mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Do not load typescriptServices.js on the UI thread anymore
This commit is contained in:
parent
95c8a531a2
commit
d1e907a30c
4 changed files with 89 additions and 40 deletions
|
|
@ -26,9 +26,8 @@ const BUNDLED_FILE_HEADER = [
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
bundleOne('monaco.contribution');
|
bundleOne('monaco.contribution');
|
||||||
bundleOne('lib/typescriptServices');
|
bundleOne('tsMode');
|
||||||
bundleOne('tsMode', ['vs/language/typescript/lib/typescriptServices']);
|
bundleOne('tsWorker');
|
||||||
bundleOne('tsWorker', ['vs/language/typescript/lib/typescriptServices']);
|
|
||||||
|
|
||||||
function bundleOne(moduleId, exclude) {
|
function bundleOne(moduleId, exclude) {
|
||||||
requirejs.optimize({
|
requirejs.optimize({
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,45 @@ import Promise = monaco.Promise;
|
||||||
import CancellationToken = monaco.CancellationToken;
|
import CancellationToken = monaco.CancellationToken;
|
||||||
import IDisposable = monaco.IDisposable;
|
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 {
|
export abstract class Adapter {
|
||||||
|
|
||||||
constructor(protected _worker: (first: Uri, ...more: Uri[]) => Promise<TypeScriptWorker>) {
|
constructor(protected _worker: (first: Uri, ...more: Uri[]) => Promise<TypeScriptWorker>) {
|
||||||
|
|
@ -153,7 +192,7 @@ export class DiagnostcsAdapter extends Adapter {
|
||||||
startColumn,
|
startColumn,
|
||||||
endLineNumber,
|
endLineNumber,
|
||||||
endColumn,
|
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,
|
position: position,
|
||||||
label: details.name,
|
label: details.name,
|
||||||
kind: SuggestAdapter.convertKind(details.kind),
|
kind: SuggestAdapter.convertKind(details.kind),
|
||||||
detail: ts.displayPartsToString(details.displayParts),
|
detail: displayPartsToString(details.displayParts),
|
||||||
documentation: ts.displayPartsToString(details.documentation)
|
documentation: displayPartsToString(details.documentation)
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -281,20 +320,20 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si
|
||||||
parameters: []
|
parameters: []
|
||||||
};
|
};
|
||||||
|
|
||||||
signature.label += ts.displayPartsToString(item.prefixDisplayParts);
|
signature.label += displayPartsToString(item.prefixDisplayParts);
|
||||||
item.parameters.forEach((p, i, a) => {
|
item.parameters.forEach((p, i, a) => {
|
||||||
let label = ts.displayPartsToString(p.displayParts);
|
let label = displayPartsToString(p.displayParts);
|
||||||
let parameter: monaco.languages.ParameterInformation = {
|
let parameter: monaco.languages.ParameterInformation = {
|
||||||
label: label,
|
label: label,
|
||||||
documentation: ts.displayPartsToString(p.documentation)
|
documentation: displayPartsToString(p.documentation)
|
||||||
};
|
};
|
||||||
signature.label += label;
|
signature.label += label;
|
||||||
signature.parameters.push(parameter);
|
signature.parameters.push(parameter);
|
||||||
if (i < a.length - 1) {
|
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);
|
ret.signatures.push(signature);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -317,7 +356,7 @@ export class QuickInfoAdapter extends Adapter implements monaco.languages.HoverP
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let documentation = ts.displayPartsToString(info.documentation);
|
let documentation = displayPartsToString(info.documentation);
|
||||||
let tags = info.tags ? info.tags.map(tag => {
|
let tags = info.tags ? info.tags.map(tag => {
|
||||||
const label = `*@${tag.name}*`;
|
const label = `*@${tag.name}*`;
|
||||||
if (!tag.text) {
|
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}`);
|
return label + (tag.text.match(/\r\n|\n/g) ? ' \n' + tag.text : ` - ${tag.text}`);
|
||||||
})
|
})
|
||||||
.join(' \n\n') : '';
|
.join(' \n\n') : '';
|
||||||
let contents = ts.displayPartsToString(info.displayParts);
|
let contents = displayPartsToString(info.displayParts);
|
||||||
return {
|
return {
|
||||||
range: this._textSpanToRange(resource, info.textSpan),
|
range: this._textSpanToRange(resource, info.textSpan),
|
||||||
contents: [{
|
contents: [{
|
||||||
|
|
@ -512,7 +551,7 @@ export abstract class FormatHelper extends Adapter {
|
||||||
ConvertTabsToSpaces: options.insertSpaces,
|
ConvertTabsToSpaces: options.insertSpaces,
|
||||||
TabSize: options.tabSize,
|
TabSize: options.tabSize,
|
||||||
IndentSize: options.tabSize,
|
IndentSize: options.tabSize,
|
||||||
IndentStyle: ts.IndentStyle.Smart,
|
IndentStyle: IndentStyle.Smart,
|
||||||
NewLineCharacter: '\n',
|
NewLineCharacter: '\n',
|
||||||
InsertSpaceAfterCommaDelimiter: true,
|
InsertSpaceAfterCommaDelimiter: true,
|
||||||
InsertSpaceAfterSemicolonInForStatements: true,
|
InsertSpaceAfterSemicolonInForStatements: true,
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
enum ModuleKind {
|
||||||
None = 0,
|
None = 0,
|
||||||
|
|
@ -109,26 +109,17 @@ enum ModuleKind {
|
||||||
UMD = 3,
|
UMD = 3,
|
||||||
System = 4,
|
System = 4,
|
||||||
ES2015 = 5,
|
ES2015 = 5,
|
||||||
|
ESNext = 6
|
||||||
}
|
}
|
||||||
enum JsxEmit {
|
enum JsxEmit {
|
||||||
None = 0,
|
None = 0,
|
||||||
Preserve = 1,
|
Preserve = 1,
|
||||||
React = 2,
|
React = 2,
|
||||||
|
ReactNative = 3
|
||||||
}
|
}
|
||||||
enum NewLineKind {
|
enum NewLineKind {
|
||||||
CarriageReturnLineFeed = 0,
|
CarriageReturnLineFeed = 0,
|
||||||
LineFeed = 1,
|
LineFeed = 1
|
||||||
}
|
|
||||||
interface LineAndCharacter {
|
|
||||||
line: number;
|
|
||||||
character: number;
|
|
||||||
}
|
|
||||||
enum ScriptKind {
|
|
||||||
Unknown = 0,
|
|
||||||
JS = 1,
|
|
||||||
JSX = 2,
|
|
||||||
TS = 3,
|
|
||||||
TSX = 4,
|
|
||||||
}
|
}
|
||||||
enum ScriptTarget {
|
enum ScriptTarget {
|
||||||
ES3 = 0,
|
ES3 = 0,
|
||||||
|
|
@ -136,18 +127,16 @@ enum ScriptTarget {
|
||||||
ES2015 = 2,
|
ES2015 = 2,
|
||||||
ES2016 = 3,
|
ES2016 = 3,
|
||||||
ES2017 = 4,
|
ES2017 = 4,
|
||||||
ESNext = 5,
|
ES2018 = 5,
|
||||||
Latest = 5,
|
ESNext = 6,
|
||||||
}
|
JSON = 100,
|
||||||
enum LanguageVariant {
|
Latest = 6
|
||||||
Standard = 0,
|
|
||||||
JSX = 1,
|
|
||||||
}
|
}
|
||||||
enum ModuleResolutionKind {
|
enum ModuleResolutionKind {
|
||||||
Classic = 1,
|
Classic = 1,
|
||||||
NodeJs = 2,
|
NodeJs = 2
|
||||||
}
|
}
|
||||||
// --- END enums copied from typescript to prevent loading the entire typescriptServices ---
|
//#endregion
|
||||||
|
|
||||||
const typescriptDefaults = new LanguageServiceDefaultsImpl(
|
const typescriptDefaults = new LanguageServiceDefaultsImpl(
|
||||||
{ allowNonTsExtensions: true, target: ScriptTarget.Latest },
|
{ allowNonTsExtensions: true, target: ScriptTarget.Latest },
|
||||||
|
|
|
||||||
32
src/monaco.d.ts
vendored
32
src/monaco.d.ts
vendored
|
|
@ -8,15 +8,17 @@ declare module monaco.languages.typescript {
|
||||||
UMD = 3,
|
UMD = 3,
|
||||||
System = 4,
|
System = 4,
|
||||||
ES2015 = 5,
|
ES2015 = 5,
|
||||||
|
ESNext = 6
|
||||||
}
|
}
|
||||||
enum JsxEmit {
|
enum JsxEmit {
|
||||||
None = 0,
|
None = 0,
|
||||||
Preserve = 1,
|
Preserve = 1,
|
||||||
React = 2,
|
React = 2,
|
||||||
|
ReactNative = 3
|
||||||
}
|
}
|
||||||
enum NewLineKind {
|
enum NewLineKind {
|
||||||
CarriageReturnLineFeed = 0,
|
CarriageReturnLineFeed = 0,
|
||||||
LineFeed = 1,
|
LineFeed = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ScriptTarget {
|
enum ScriptTarget {
|
||||||
|
|
@ -25,16 +27,22 @@ declare module monaco.languages.typescript {
|
||||||
ES2015 = 2,
|
ES2015 = 2,
|
||||||
ES2016 = 3,
|
ES2016 = 3,
|
||||||
ES2017 = 4,
|
ES2017 = 4,
|
||||||
ESNext = 5,
|
ES2018 = 5,
|
||||||
Latest = 5,
|
ESNext = 6,
|
||||||
|
JSON = 100,
|
||||||
|
Latest = 6
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ModuleResolutionKind {
|
export enum ModuleResolutionKind {
|
||||||
Classic = 1,
|
Classic = 1,
|
||||||
NodeJs = 2,
|
NodeJs = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[];
|
interface MapLike<T> {
|
||||||
|
[index: string]: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike<string[]> | null | undefined;
|
||||||
interface CompilerOptions {
|
interface CompilerOptions {
|
||||||
allowJs?: boolean;
|
allowJs?: boolean;
|
||||||
allowSyntheticDefaultImports?: boolean;
|
allowSyntheticDefaultImports?: boolean;
|
||||||
|
|
@ -43,9 +51,13 @@ declare module monaco.languages.typescript {
|
||||||
alwaysStrict?: boolean;
|
alwaysStrict?: boolean;
|
||||||
baseUrl?: string;
|
baseUrl?: string;
|
||||||
charset?: string;
|
charset?: string;
|
||||||
|
checkJs?: boolean;
|
||||||
declaration?: boolean;
|
declaration?: boolean;
|
||||||
|
declarationMap?: boolean;
|
||||||
|
emitDeclarationOnly?: boolean;
|
||||||
declarationDir?: string;
|
declarationDir?: string;
|
||||||
disableSizeLimit?: boolean;
|
disableSizeLimit?: boolean;
|
||||||
|
downlevelIteration?: boolean;
|
||||||
emitBOM?: boolean;
|
emitBOM?: boolean;
|
||||||
emitDecoratorMetadata?: boolean;
|
emitDecoratorMetadata?: boolean;
|
||||||
experimentalDecorators?: boolean;
|
experimentalDecorators?: boolean;
|
||||||
|
|
@ -55,6 +67,7 @@ declare module monaco.languages.typescript {
|
||||||
inlineSources?: boolean;
|
inlineSources?: boolean;
|
||||||
isolatedModules?: boolean;
|
isolatedModules?: boolean;
|
||||||
jsx?: JsxEmit;
|
jsx?: JsxEmit;
|
||||||
|
keyofStringsOnly?: boolean;
|
||||||
lib?: string[];
|
lib?: string[];
|
||||||
locale?: string;
|
locale?: string;
|
||||||
mapRoot?: string;
|
mapRoot?: string;
|
||||||
|
|
@ -70,6 +83,7 @@ declare module monaco.languages.typescript {
|
||||||
noImplicitAny?: boolean;
|
noImplicitAny?: boolean;
|
||||||
noImplicitReturns?: boolean;
|
noImplicitReturns?: boolean;
|
||||||
noImplicitThis?: boolean;
|
noImplicitThis?: boolean;
|
||||||
|
noStrictGenericChecks?: boolean;
|
||||||
noUnusedLocals?: boolean;
|
noUnusedLocals?: boolean;
|
||||||
noUnusedParameters?: boolean;
|
noUnusedParameters?: boolean;
|
||||||
noImplicitUseStrict?: boolean;
|
noImplicitUseStrict?: boolean;
|
||||||
|
|
@ -78,10 +92,13 @@ declare module monaco.languages.typescript {
|
||||||
out?: string;
|
out?: string;
|
||||||
outDir?: string;
|
outDir?: string;
|
||||||
outFile?: string;
|
outFile?: string;
|
||||||
|
paths?: MapLike<string[]>;
|
||||||
preserveConstEnums?: boolean;
|
preserveConstEnums?: boolean;
|
||||||
|
preserveSymlinks?: boolean;
|
||||||
project?: string;
|
project?: string;
|
||||||
reactNamespace?: string;
|
reactNamespace?: string;
|
||||||
jsxFactory?: string;
|
jsxFactory?: string;
|
||||||
|
composite?: boolean;
|
||||||
removeComments?: boolean;
|
removeComments?: boolean;
|
||||||
rootDir?: string;
|
rootDir?: string;
|
||||||
rootDirs?: string[];
|
rootDirs?: string[];
|
||||||
|
|
@ -89,14 +106,19 @@ declare module monaco.languages.typescript {
|
||||||
skipDefaultLibCheck?: boolean;
|
skipDefaultLibCheck?: boolean;
|
||||||
sourceMap?: boolean;
|
sourceMap?: boolean;
|
||||||
sourceRoot?: string;
|
sourceRoot?: string;
|
||||||
|
strict?: boolean;
|
||||||
|
strictFunctionTypes?: boolean;
|
||||||
strictNullChecks?: boolean;
|
strictNullChecks?: boolean;
|
||||||
|
strictPropertyInitialization?: boolean;
|
||||||
suppressExcessPropertyErrors?: boolean;
|
suppressExcessPropertyErrors?: boolean;
|
||||||
suppressImplicitAnyIndexErrors?: boolean;
|
suppressImplicitAnyIndexErrors?: boolean;
|
||||||
target?: ScriptTarget;
|
target?: ScriptTarget;
|
||||||
traceResolution?: boolean;
|
traceResolution?: boolean;
|
||||||
|
resolveJsonModule?: boolean;
|
||||||
types?: string[];
|
types?: string[];
|
||||||
/** Paths used to compute primary types search locations */
|
/** Paths used to compute primary types search locations */
|
||||||
typeRoots?: string[];
|
typeRoots?: string[];
|
||||||
|
esModuleInterop?: boolean;
|
||||||
[option: string]: CompilerOptionsValue | undefined;
|
[option: string]: CompilerOptionsValue | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue