mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 22:02:55 +01:00
Optimize how external libs are handled and allow for custom languages:
* Adding/removing extra libs does not trigger a full worker refresh * Manual control over when the extra libs are sent to the worker * Adding a new lib with the same name replaces it inplace Also included, the capability to define custom languages
This commit is contained in:
parent
505232c7c8
commit
e39fa719bc
7 changed files with 167 additions and 59 deletions
|
|
@ -24,7 +24,7 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
|||
// --- model sync -----------------------
|
||||
|
||||
private _ctx: IWorkerContext;
|
||||
private _extraLibs: { [fileName: string]: string } = Object.create(null);
|
||||
private _extraLibs: { [path: string]: { content: string, version: number } } = Object.create(null);
|
||||
private _languageService = ts.createLanguageService(this);
|
||||
private _compilerOptions: ts.CompilerOptions;
|
||||
|
||||
|
|
@ -59,9 +59,11 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
|||
let model = this._getModel(fileName);
|
||||
if (model) {
|
||||
return model.version.toString();
|
||||
} else if (this.isDefaultLibFileName(fileName) || fileName in this._extraLibs) {
|
||||
// extra lib and default lib are static
|
||||
} else if (this.isDefaultLibFileName(fileName)) {
|
||||
// default lib is static
|
||||
return '1';
|
||||
} else if(fileName in this._extraLibs) {
|
||||
return this._extraLibs[fileName].version.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +76,7 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
|||
|
||||
} else if (fileName in this._extraLibs) {
|
||||
// static extra lib
|
||||
text = this._extraLibs[fileName];
|
||||
text = this._extraLibs[fileName].content;
|
||||
|
||||
} else if (fileName === DEFAULT_LIB.NAME) {
|
||||
text = DEFAULT_LIB.CONTENTS;
|
||||
|
|
@ -196,11 +198,15 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
|||
getEmitOutput(fileName: string): Promise<ts.EmitOutput> {
|
||||
return Promise.resolve(this._languageService.getEmitOutput(fileName));
|
||||
}
|
||||
|
||||
syncExtraLibs(extraLibs: { [path: string]: { content: string, version: number } }) {
|
||||
this._extraLibs = extraLibs;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICreateData {
|
||||
compilerOptions: ts.CompilerOptions;
|
||||
extraLibs: { [path: string]: string };
|
||||
extraLibs: { [path: string]: { content: string, version: number } };
|
||||
}
|
||||
|
||||
export function create(ctx: IWorkerContext, createData: ICreateData): TypeScriptWorker {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue