mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 23:13:02 +01:00
Keep idle models, do not terminate worker on idle (fixes microsoft/monaco-editor#1310)
This commit is contained in:
parent
e4ab9e4360
commit
14fbd7c2e0
2 changed files with 2 additions and 27 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue