mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 07:00:11 +01:00
Adopt createData option when creatin a web worker
This commit is contained in:
parent
ab14589e93
commit
7ba10ddbfb
2 changed files with 26 additions and 25 deletions
|
|
@ -24,17 +24,13 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
||||||
|
|
||||||
// --- model sync -----------------------
|
// --- model sync -----------------------
|
||||||
|
|
||||||
// private _models: { [uri: string]: MirrorModel2 } = Object.create(null);
|
|
||||||
private _extraLibs: { [fileName: string]: string } = Object.create(null);
|
private _extraLibs: { [fileName: string]: string } = Object.create(null);
|
||||||
private _languageService = ts.createLanguageService(this);
|
private _languageService = ts.createLanguageService(this);
|
||||||
private _compilerOptions: ts.CompilerOptions;
|
private _compilerOptions: ts.CompilerOptions;
|
||||||
|
|
||||||
// --- default ---------
|
constructor(createData:ICreateData) {
|
||||||
|
this._compilerOptions = createData.compilerOptions;
|
||||||
acceptDefaults(options:ts.CompilerOptions, extraLibs:{ [path: string]: string }): Promise<void> {
|
this._extraLibs = createData.extraLibs;
|
||||||
this._compilerOptions = options;
|
|
||||||
this._extraLibs = extraLibs;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- language service host ---------------
|
// --- language service host ---------------
|
||||||
|
|
@ -176,6 +172,11 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(): TypeScriptWorker {
|
export interface ICreateData {
|
||||||
return new TypeScriptWorker();
|
compilerOptions:ts.CompilerOptions;
|
||||||
|
extraLibs:{ [path: string]: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function create(createData:ICreateData): TypeScriptWorker {
|
||||||
|
return new TypeScriptWorker(createData);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,20 +60,18 @@ export class WorkerManager {
|
||||||
|
|
||||||
if (!this._client) {
|
if (!this._client) {
|
||||||
this._worker = monaco.editor.createWebWorker<TypeScriptWorker>({
|
this._worker = monaco.editor.createWebWorker<TypeScriptWorker>({
|
||||||
|
|
||||||
|
// module that exports the create() method and returns a `TypeScriptWorker` instance
|
||||||
moduleId: 'vs/language/typescript/src/worker',
|
moduleId: 'vs/language/typescript/src/worker',
|
||||||
|
|
||||||
|
// passed in to the create() method
|
||||||
|
createData: {
|
||||||
|
compilerOptions: this._defaults.compilerOptions,
|
||||||
|
extraLibs: this._defaults.extraLibs
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let _client:TypeScriptWorker = null;
|
this._client = this._worker.getProxy();
|
||||||
|
|
||||||
// avoid cancellation
|
|
||||||
this._client = toShallowCancelPromise(
|
|
||||||
this._worker.getProxy().then((client) => {
|
|
||||||
_client = client;
|
|
||||||
}).then(_ => {
|
|
||||||
const {compilerOptions, extraLibs} = this._defaults;
|
|
||||||
return _client.acceptDefaults(compilerOptions, extraLibs);
|
|
||||||
}).then(_ => _client)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._client;
|
return this._client;
|
||||||
|
|
@ -81,11 +79,13 @@ export class WorkerManager {
|
||||||
|
|
||||||
getLanguageServiceWorker(...resources: Uri[]): Promise<TypeScriptWorker> {
|
getLanguageServiceWorker(...resources: Uri[]): Promise<TypeScriptWorker> {
|
||||||
let _client:TypeScriptWorker;
|
let _client:TypeScriptWorker;
|
||||||
return this._getClient().then((client) => {
|
return toShallowCancelPromise(
|
||||||
_client = client
|
this._getClient().then((client) => {
|
||||||
}).then(_ => {
|
_client = client
|
||||||
return this._worker.withSyncedResources(resources)
|
}).then(_ => {
|
||||||
}).then(_ => _client);
|
return this._worker.withSyncedResources(resources)
|
||||||
|
}).then(_ => _client)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue