diff --git a/scripts/bundle.js b/scripts/bundle.js index c18942fd..e195e33d 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -26,9 +26,8 @@ const BUNDLED_FILE_HEADER = [ ].join('\n'); bundleOne('monaco.contribution'); -bundleOne('lib/typescriptServices'); -bundleOne('tsMode', ['vs/language/typescript/lib/typescriptServices']); -bundleOne('tsWorker', ['vs/language/typescript/lib/typescriptServices']); +bundleOne('tsMode'); +bundleOne('tsWorker'); function bundleOne(moduleId, exclude) { requirejs.optimize({ diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index 35546fc3..bb826a94 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -16,6 +16,45 @@ import Promise = monaco.Promise; import CancellationToken = monaco.CancellationToken; import IDisposable = monaco.IDisposable; +//#region utils copied from typescript to prevent loading the entire typescriptServices --- + +enum IndentStyle { + None = 0, + Block = 1, + Smart = 2 +} + +function flattenDiagnosticMessageText(messageText: string | ts.DiagnosticMessageChain, newLine: '\n'): string { + if (typeof messageText === "string") { + return messageText; + } else { + let diagnosticChain = messageText; + let result = ""; + let indent = 0; + while (diagnosticChain) { + if (indent) { + result += newLine; + for (let i = 0; i < indent; i++) { + result += " "; + } + } + result += diagnosticChain.messageText; + indent++; + diagnosticChain = diagnosticChain.next; + } + return result; + } +} + +function displayPartsToString(displayParts: ts.SymbolDisplayPart[]): string { + if (displayParts) { + return displayParts.map((displayPart) => displayPart.text).join(""); + } + return ""; +} + +//#endregion + export abstract class Adapter { constructor(protected _worker: (first: Uri, ...more: Uri[]) => Promise) { @@ -153,7 +192,7 @@ export class DiagnostcsAdapter extends Adapter { startColumn, endLineNumber, endColumn, - message: ts.flattenDiagnosticMessageText(diag.messageText, '\n') + message: flattenDiagnosticMessageText(diag.messageText, '\n') }; } } @@ -215,8 +254,8 @@ export class SuggestAdapter extends Adapter implements monaco.languages.Completi position: position, label: details.name, kind: SuggestAdapter.convertKind(details.kind), - detail: ts.displayPartsToString(details.displayParts), - documentation: ts.displayPartsToString(details.documentation) + detail: displayPartsToString(details.displayParts), + documentation: displayPartsToString(details.documentation) }; })); } @@ -281,20 +320,20 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si parameters: [] }; - signature.label += ts.displayPartsToString(item.prefixDisplayParts); + signature.label += displayPartsToString(item.prefixDisplayParts); item.parameters.forEach((p, i, a) => { - let label = ts.displayPartsToString(p.displayParts); + let label = displayPartsToString(p.displayParts); let parameter: monaco.languages.ParameterInformation = { label: label, - documentation: ts.displayPartsToString(p.documentation) + documentation: displayPartsToString(p.documentation) }; signature.label += label; signature.parameters.push(parameter); if (i < a.length - 1) { - signature.label += ts.displayPartsToString(item.separatorDisplayParts); + signature.label += displayPartsToString(item.separatorDisplayParts); } }); - signature.label += ts.displayPartsToString(item.suffixDisplayParts); + signature.label += displayPartsToString(item.suffixDisplayParts); ret.signatures.push(signature); }); @@ -317,7 +356,7 @@ export class QuickInfoAdapter extends Adapter implements monaco.languages.HoverP if (!info) { return; } - let documentation = ts.displayPartsToString(info.documentation); + let documentation = displayPartsToString(info.documentation); let tags = info.tags ? info.tags.map(tag => { const label = `*@${tag.name}*`; if (!tag.text) { @@ -326,7 +365,7 @@ export class QuickInfoAdapter extends Adapter implements monaco.languages.HoverP return label + (tag.text.match(/\r\n|\n/g) ? ' \n' + tag.text : ` - ${tag.text}`); }) .join(' \n\n') : ''; - let contents = ts.displayPartsToString(info.displayParts); + let contents = displayPartsToString(info.displayParts); return { range: this._textSpanToRange(resource, info.textSpan), contents: [{ @@ -512,7 +551,7 @@ export abstract class FormatHelper extends Adapter { ConvertTabsToSpaces: options.insertSpaces, TabSize: options.tabSize, IndentSize: options.tabSize, - IndentStyle: ts.IndentStyle.Smart, + IndentStyle: IndentStyle.Smart, NewLineCharacter: '\n', InsertSpaceAfterCommaDelimiter: true, InsertSpaceAfterSemicolonInForStatements: true, diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index b72cd007..edde6228 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -100,7 +100,7 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript. } } -// --- BEGIN enums copied from typescript to prevent loading the entire typescriptServices --- +//#region enums copied from typescript to prevent loading the entire typescriptServices --- enum ModuleKind { None = 0, @@ -109,26 +109,17 @@ enum ModuleKind { UMD = 3, System = 4, ES2015 = 5, + ESNext = 6 } enum JsxEmit { None = 0, Preserve = 1, React = 2, + ReactNative = 3 } enum NewLineKind { CarriageReturnLineFeed = 0, - LineFeed = 1, -} -interface LineAndCharacter { - line: number; - character: number; -} -enum ScriptKind { - Unknown = 0, - JS = 1, - JSX = 2, - TS = 3, - TSX = 4, + LineFeed = 1 } enum ScriptTarget { ES3 = 0, @@ -136,18 +127,16 @@ enum ScriptTarget { ES2015 = 2, ES2016 = 3, ES2017 = 4, - ESNext = 5, - Latest = 5, -} -enum LanguageVariant { - Standard = 0, - JSX = 1, + ES2018 = 5, + ESNext = 6, + JSON = 100, + Latest = 6 } enum ModuleResolutionKind { Classic = 1, - NodeJs = 2, + NodeJs = 2 } -// --- END enums copied from typescript to prevent loading the entire typescriptServices --- +//#endregion const typescriptDefaults = new LanguageServiceDefaultsImpl( { allowNonTsExtensions: true, target: ScriptTarget.Latest }, diff --git a/src/monaco.d.ts b/src/monaco.d.ts index f1a849f4..35806f17 100644 --- a/src/monaco.d.ts +++ b/src/monaco.d.ts @@ -8,15 +8,17 @@ declare module monaco.languages.typescript { UMD = 3, System = 4, ES2015 = 5, + ESNext = 6 } enum JsxEmit { None = 0, Preserve = 1, React = 2, + ReactNative = 3 } enum NewLineKind { CarriageReturnLineFeed = 0, - LineFeed = 1, + LineFeed = 1 } enum ScriptTarget { @@ -25,16 +27,22 @@ declare module monaco.languages.typescript { ES2015 = 2, ES2016 = 3, ES2017 = 4, - ESNext = 5, - Latest = 5, + ES2018 = 5, + ESNext = 6, + JSON = 100, + Latest = 6 } export enum ModuleResolutionKind { Classic = 1, - NodeJs = 2, + NodeJs = 2 } - type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[]; + interface MapLike { + [index: string]: T; + } + + type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike | null | undefined; interface CompilerOptions { allowJs?: boolean; allowSyntheticDefaultImports?: boolean; @@ -43,9 +51,13 @@ declare module monaco.languages.typescript { alwaysStrict?: boolean; baseUrl?: string; charset?: string; + checkJs?: boolean; declaration?: boolean; + declarationMap?: boolean; + emitDeclarationOnly?: boolean; declarationDir?: string; disableSizeLimit?: boolean; + downlevelIteration?: boolean; emitBOM?: boolean; emitDecoratorMetadata?: boolean; experimentalDecorators?: boolean; @@ -55,6 +67,7 @@ declare module monaco.languages.typescript { inlineSources?: boolean; isolatedModules?: boolean; jsx?: JsxEmit; + keyofStringsOnly?: boolean; lib?: string[]; locale?: string; mapRoot?: string; @@ -70,6 +83,7 @@ declare module monaco.languages.typescript { noImplicitAny?: boolean; noImplicitReturns?: boolean; noImplicitThis?: boolean; + noStrictGenericChecks?: boolean; noUnusedLocals?: boolean; noUnusedParameters?: boolean; noImplicitUseStrict?: boolean; @@ -78,10 +92,13 @@ declare module monaco.languages.typescript { out?: string; outDir?: string; outFile?: string; + paths?: MapLike; preserveConstEnums?: boolean; + preserveSymlinks?: boolean; project?: string; reactNamespace?: string; jsxFactory?: string; + composite?: boolean; removeComments?: boolean; rootDir?: string; rootDirs?: string[]; @@ -89,14 +106,19 @@ declare module monaco.languages.typescript { skipDefaultLibCheck?: boolean; sourceMap?: boolean; sourceRoot?: string; + strict?: boolean; + strictFunctionTypes?: boolean; strictNullChecks?: boolean; + strictPropertyInitialization?: boolean; suppressExcessPropertyErrors?: boolean; suppressImplicitAnyIndexErrors?: boolean; target?: ScriptTarget; traceResolution?: boolean; + resolveJsonModule?: boolean; types?: string[]; /** Paths used to compute primary types search locations */ typeRoots?: string[]; + esModuleInterop?: boolean; [option: string]: CompilerOptionsValue | undefined; }