mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 11:35:40 +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 {
|
||||
this._worker(resource).then(worker => {
|
||||
let promises: Promise<ts.Diagnostic[]>[] = [];
|
||||
if (!this._defaults.diagnosticsOptions.noSyntaxValidation) {
|
||||
const promises: Promise<ts.Diagnostic[]>[] = [];
|
||||
const {noSyntaxValidation, noSemanticValidation} = this._defaults.getDiagnosticsOptions();
|
||||
if (!noSyntaxValidation) {
|
||||
promises.push(worker.getSyntacticDiagnostics(resource.toString()));
|
||||
}
|
||||
if (!this._defaults.diagnosticsOptions.noSemanticValidation) {
|
||||
if (!noSemanticValidation) {
|
||||
promises.push(worker.getSemanticDiagnostics(resource.toString()));
|
||||
}
|
||||
return Promise.join(promises);
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
|||
|
||||
private _onDidChange = new Emitter<monaco.languages.typescript.LanguageServiceDefaults>();
|
||||
private _extraLibs: { [path: string]: string };
|
||||
private _workerMaxIdleTime: number;
|
||||
private _compilerOptions: monaco.languages.typescript.CompilerOptions;
|
||||
private _diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions;
|
||||
|
||||
constructor(compilerOptions: monaco.languages.typescript.CompilerOptions, diagnosticsOptions: monaco.languages.typescript.DiagnosticsOptions) {
|
||||
this._extraLibs = Object.create(null);
|
||||
this._workerMaxIdleTime = 2 * 60 * 1000;
|
||||
this.setCompilerOptions(compilerOptions);
|
||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||
}
|
||||
|
|
@ -31,7 +33,7 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
|||
return this._onDidChange.event;
|
||||
}
|
||||
|
||||
get extraLibs(): { [path: string]: string; } {
|
||||
getExtraLibs(): { [path: string]: string; } {
|
||||
const result = Object.create(null);
|
||||
for (var key in this._extraLibs) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +71,7 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
|||
this._onDidChange.fire(this);
|
||||
}
|
||||
|
||||
get diagnosticsOptions(): monaco.languages.typescript.DiagnosticsOptions {
|
||||
getDiagnosticsOptions(): monaco.languages.typescript.DiagnosticsOptions {
|
||||
return this._diagnosticsOptions;
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +79,16 @@ export class LanguageServiceDefaultsImpl implements monaco.languages.typescript.
|
|||
this._diagnosticsOptions = options || Object.create(null);
|
||||
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 ---
|
||||
|
|
|
|||
27
src/monaco.d.ts
vendored
27
src/monaco.d.ts
vendored
|
|
@ -95,9 +95,36 @@ declare module monaco.languages.typescript {
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Set TypeScript compiler options.
|
||||
*/
|
||||
setCompilerOptions(options: CompilerOptions): void;
|
||||
|
||||
/**
|
||||
* Configure whether syntactic and/or semantic validation should
|
||||
* be performed
|
||||
*/
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ import Promise = monaco.Promise;
|
|||
import IDisposable = monaco.IDisposable;
|
||||
import Uri = monaco.Uri;
|
||||
|
||||
const STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
|
||||
|
||||
export class WorkerManager {
|
||||
|
||||
private _defaults: LanguageServiceDefaultsImpl;
|
||||
|
|
@ -49,8 +47,9 @@ export class WorkerManager {
|
|||
if (!this._worker) {
|
||||
return;
|
||||
}
|
||||
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
||||
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
|
||||
const maxIdleTime = this._defaults.getWorkerMaxIdleTime();
|
||||
const timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
||||
if (maxIdleTime > 0 && timePassedSinceLastUsed > maxIdleTime) {
|
||||
this._stopWorker();
|
||||
}
|
||||
}
|
||||
|
|
@ -66,8 +65,8 @@ export class WorkerManager {
|
|||
|
||||
// passed in to the create() method
|
||||
createData: {
|
||||
compilerOptions: this._defaults.compilerOptions,
|
||||
extraLibs: this._defaults.extraLibs
|
||||
compilerOptions: this._defaults.getCompilerOptions(),
|
||||
extraLibs: this._defaults.getExtraLibs()
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue