mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Expose setMaximunWorkerIdleTime
This commit is contained in:
parent
b9333be154
commit
867476531d
4 changed files with 51 additions and 12 deletions
|
|
@ -95,11 +95,12 @@ export class DiagnostcsAdapter extends Adapter {
|
||||||
|
|
||||||
private _doValidate(resource: Uri): void {
|
private _doValidate(resource: Uri): void {
|
||||||
this._worker(resource).then(worker => {
|
this._worker(resource).then(worker => {
|
||||||
let promises: Promise<ts.Diagnostic[]>[] = [];
|
const promises: Promise<ts.Diagnostic[]>[] = [];
|
||||||
if (!this._defaults.diagnosticsOptions.noSyntaxValidation) {
|
const {noSyntaxValidation, noSemanticValidation} = this._defaults.getDiagnosticsOptions();
|
||||||
|
if (!noSyntaxValidation) {
|
||||||
promises.push(worker.getSyntacticDiagnostics(resource.toString()));
|
promises.push(worker.getSyntacticDiagnostics(resource.toString()));
|
||||||
}
|
}
|
||||||
if (!this._defaults.diagnosticsOptions.noSemanticValidation) {
|
if (!noSemanticValidation) {
|
||||||
promises.push(worker.getSemanticDiagnostics(resource.toString()));
|
promises.push(worker.getSemanticDiagnostics(resource.toString()));
|
||||||
}
|
}
|
||||||
return Promise.join(promises);
|
return Promise.join(promises);
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
||||||
|
|
||||||
private _onDidChange = new Emitter<monaco.languages.typescript.LanguageServiceDefaults>();
|
private _onDidChange = new Emitter<monaco.languages.typescript.LanguageServiceDefaults>();
|
||||||
private _extraLibs: { [path: string]: string };
|
private _extraLibs: { [path: string]: string };
|
||||||
|
private _workerMaxIdleTime: number;
|
||||||
private _compilerOptions: monaco.languages.typescript.CompilerOptions;
|
private _compilerOptions: monaco.languages.typescript.CompilerOptions;
|
||||||
private _diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions;
|
private _diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions;
|
||||||
|
|
||||||
constructor(compilerOptions: monaco.languages.typescript.CompilerOptions, diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions) {
|
constructor(compilerOptions: monaco.languages.typescript.CompilerOptions, diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions) {
|
||||||
this._extraLibs = Object.create(null);
|
this._extraLibs = Object.create(null);
|
||||||
|
this._workerMaxIdleTime = 2 * 60 * 1000;
|
||||||
this.setCompilerOptions(compilerOptions);
|
this.setCompilerOptions(compilerOptions);
|
||||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +33,7 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
||||||
return this._onDidChange.event;
|
return this._onDidChange.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
get extraLibs(): { [path: string]: string; } {
|
getExtraLibs(): { [path: string]: string; } {
|
||||||
const result = Object.create(null);
|
const result = Object.create(null);
|
||||||
for (var key in this._extraLibs) {
|
for (var key in this._extraLibs) {
|
||||||
result[key] = this._extraLibs[key];
|
result[key] = this._extraLibs[key];
|
||||||
|
|
@ -60,7 +62,7 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get compilerOptions(): monaco.languages.typescript.CompilerOptions {
|
getCompilerOptions(): monaco.languages.typescript.CompilerOptions {
|
||||||
return this._compilerOptions;
|
return this._compilerOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +71,7 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
||||||
this._onDidChange.fire(this);
|
this._onDidChange.fire(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
get diagnosticsOptions(): monaco.languages.typescript.DiagnosticsOptions {
|
getDiagnosticsOptions(): monaco.languages.typescript.DiagnosticsOptions {
|
||||||
return this._diagnosticsOptions;
|
return this._diagnosticsOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +79,16 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
||||||
this._diagnosticsOptions = options || Object.create(null);
|
this._diagnosticsOptions = options || Object.create(null);
|
||||||
this._onDidChange.fire(this);
|
this._onDidChange.fire(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setMaximunWorkerIdleTime(value: number): void {
|
||||||
|
// doesn't fire an event since no
|
||||||
|
// worker restart is required here
|
||||||
|
this._workerMaxIdleTime = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
getWorkerMaxIdleTime() {
|
||||||
|
return this._workerMaxIdleTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- BEGIN enums copied from typescript to prevent loading the entire typescriptServices ---
|
// --- BEGIN enums copied from typescript to prevent loading the entire typescriptServices ---
|
||||||
|
|
|
||||||
27
src/monaco.d.ts
vendored
27
src/monaco.d.ts
vendored
|
|
@ -95,9 +95,36 @@ declare module monaco.languages.typescript {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LanguageServiceDefaults {
|
export interface LanguageServiceDefaults {
|
||||||
|
/**
|
||||||
|
* Add an additional source file to the language service. Use this
|
||||||
|
* for typescript (definition) files that won't be loaded as editor
|
||||||
|
* document, like `jquery.d.ts`.
|
||||||
|
*
|
||||||
|
* @param content The file content
|
||||||
|
* @param filePath An optional file path
|
||||||
|
* @returns A disposabled which will remove the file from the
|
||||||
|
* language service upon disposal.
|
||||||
|
*/
|
||||||
addExtraLib(content: string, filePath?: string): IDisposable;
|
addExtraLib(content: string, filePath?: string): IDisposable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set TypeScript compiler options.
|
||||||
|
*/
|
||||||
setCompilerOptions(options: CompilerOptions): void;
|
setCompilerOptions(options: CompilerOptions): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure whether syntactic and/or semantic validation should
|
||||||
|
* be performed
|
||||||
|
*/
|
||||||
setDiagnosticsOptions(options: DiagnosticsOptions): void;
|
setDiagnosticsOptions(options: DiagnosticsOptions): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure when the worker shuts down. By default that is 2mins.
|
||||||
|
*
|
||||||
|
* @param value The maximun idle time in milliseconds. Values less than one
|
||||||
|
* mean never shut down.
|
||||||
|
*/
|
||||||
|
setMaximunWorkerIdleTime(value: number): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export var typescriptDefaults: LanguageServiceDefaults;
|
export var typescriptDefaults: LanguageServiceDefaults;
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ import Promise = monaco.Promise;
|
||||||
import IDisposable = monaco.IDisposable;
|
import IDisposable = monaco.IDisposable;
|
||||||
import Uri = monaco.Uri;
|
import Uri = monaco.Uri;
|
||||||
|
|
||||||
const STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
|
|
||||||
|
|
||||||
export class WorkerManager {
|
export class WorkerManager {
|
||||||
|
|
||||||
private _defaults: LanguageServiceDefaultsImpl;
|
private _defaults: LanguageServiceDefaultsImpl;
|
||||||
|
|
@ -49,8 +47,9 @@ export class WorkerManager {
|
||||||
if (!this._worker) {
|
if (!this._worker) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
const maxIdleTime = this._defaults.getWorkerMaxIdleTime();
|
||||||
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
|
const timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
||||||
|
if (maxIdleTime > 0 && timePassedSinceLastUsed > maxIdleTime) {
|
||||||
this._stopWorker();
|
this._stopWorker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -66,8 +65,8 @@ export class WorkerManager {
|
||||||
|
|
||||||
// passed in to the create() method
|
// passed in to the create() method
|
||||||
createData: {
|
createData: {
|
||||||
compilerOptions: this._defaults.compilerOptions,
|
compilerOptions: this._defaults.getCompilerOptions(),
|
||||||
extraLibs: this._defaults.extraLibs
|
extraLibs: this._defaults.getExtraLibs()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue