use IdleValue to prevent overly eager service creation

This commit is contained in:
Johannes Rieken
2018-09-28 14:58:43 +02:00
parent 5867865b25
commit 9435f9cbc7

View File

@@ -5,7 +5,7 @@
'use strict';
import { sequence } from 'vs/base/common/async';
import { sequence, IdleValue } from 'vs/base/common/async';
import * as strings from 'vs/base/common/strings';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { ISaveParticipant, ITextFileEditorModel, SaveReason } from 'vs/workbench/services/textfile/common/textfiles';
@@ -376,7 +376,7 @@ class ExtHostSaveParticipant implements ISaveParticipantParticipant {
@extHostCustomer
export class SaveParticipant implements ISaveParticipant {
private _saveParticipants: ISaveParticipantParticipant[];
private readonly _saveParticipants: IdleValue<ISaveParticipantParticipant[]>;
constructor(
extHostContext: IExtHostContext,
@@ -384,26 +384,27 @@ export class SaveParticipant implements ISaveParticipant {
@IProgressService2 private readonly _progressService: IProgressService2,
@ILogService private readonly _logService: ILogService
) {
this._saveParticipants = [
this._saveParticipants = new IdleValue(() => [
instantiationService.createInstance(TrimWhitespaceParticipant),
instantiationService.createInstance(CodeActionOnParticipant),
instantiationService.createInstance(FormatOnSaveParticipant),
instantiationService.createInstance(FinalNewLineParticipant),
instantiationService.createInstance(TrimFinalNewLinesParticipant),
instantiationService.createInstance(ExtHostSaveParticipant, extHostContext),
];
]);
// Hook into model
TextFileEditorModel.setSaveParticipant(this);
}
dispose(): void {
TextFileEditorModel.setSaveParticipant(undefined);
this._saveParticipants.dispose();
}
participate(model: ITextFileEditorModel, env: { reason: SaveReason }): Thenable<void> {
return this._progressService.withProgress({ location: ProgressLocation.Window }, progress => {
progress.report({ message: localize('saveParticipants', "Running Save Participants...") });
const promiseFactory = this._saveParticipants.map(p => () => {
const promiseFactory = this._saveParticipants.getValue().map(p => () => {
return Promise.resolve(p.participate(model, env));
});
return sequence(promiseFactory).then(() => { }, err => this._logService.warn(err));