Keep idle models, do not terminate worker on idle (fixes microsoft/monaco-editor#1310)

pull/2748/head
Alex Dima 5 years ago
parent e4ab9e4360
commit 14fbd7c2e0
No known key found for this signature in database
GPG Key ID: 6E58D7B045760DA0

@ -28,7 +28,6 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
private _onDidExtraLibsChange = new Emitter<void>();
private _extraLibs: IExtraLibs;
private _workerMaxIdleTime: number;
private _eagerModelSync: boolean;
private _compilerOptions!: monaco.languages.typescript.CompilerOptions;
private _diagnosticsOptions!: monaco.languages.typescript.DiagnosticsOptions;
@ -36,7 +35,6 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
constructor(compilerOptions: monaco.languages.typescript.CompilerOptions, diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions) {
this._extraLibs = Object.create(null);
this._workerMaxIdleTime = 2 * 60 * 1000;
this._eagerModelSync = false;
this.setCompilerOptions(compilerOptions);
this.setDiagnosticsOptions(diagnosticsOptions);
@ -145,13 +143,6 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
}
setMaximumWorkerIdleTime(value: number): void {
// doesn't fire an event since no
// worker restart is required here
this._workerMaxIdleTime = value;
}
getWorkerMaxIdleTime() {
return this._workerMaxIdleTime;
}
setEagerModelSync(value: boolean) {

@ -14,8 +14,6 @@ export class WorkerManager {
private _modeId: string;
private _defaults: LanguageServiceDefaultsImpl;
private _idleCheckInterval: number;
private _lastUsedTime: number;
private _configChangeListener: IDisposable;
private _updateExtraLibsToken: number;
private _extraLibsChangeListener: IDisposable;
@ -28,8 +26,6 @@ export class WorkerManager {
this._defaults = defaults;
this._worker = null;
this._client = null;
this._idleCheckInterval = setInterval(() => this._checkIfIdle(), 30 * 1000);
this._lastUsedTime = 0;
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
this._updateExtraLibsToken = 0;
this._extraLibsChangeListener = this._defaults.onDidExtraLibsChange(() => this._updateExtraLibs());
@ -44,7 +40,6 @@ export class WorkerManager {
}
dispose(): void {
clearInterval(this._idleCheckInterval);
this._configChangeListener.dispose();
this._extraLibsChangeListener.dispose();
this._stopWorker();
@ -63,20 +58,7 @@ export class WorkerManager {
proxy.updateExtraLibs(this._defaults.getExtraLibs());
}
private _checkIfIdle(): void {
if (!this._worker) {
return;
}
const maxIdleTime = this._defaults.getWorkerMaxIdleTime();
const timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
if (maxIdleTime > 0 && timePassedSinceLastUsed > maxIdleTime) {
this._stopWorker();
}
}
private _getClient(): Promise<TypeScriptWorker> {
this._lastUsedTime = Date.now();
if (!this._client) {
this._worker = monaco.editor.createWebWorker<TypeScriptWorker>({
@ -85,6 +67,8 @@ export class WorkerManager {
label: this._modeId,
keepIdleModels: true,
// passed in to the create() method
createData: {
compilerOptions: this._defaults.getCompilerOptions(),

Loading…
Cancel
Save