UNPKG

@codingame/monaco-vscode-extensions-service-override

Version:

VSCode public API plugged on the monaco editor - extensions service-override

45 lines (41 loc) 2.37 kB
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6'; import { shouldSynchronizeModel } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/model'; import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls'; import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation'; import { extHostCustomer } from '../../services/extensions/common/extHostCustomers.js'; import { ITextFileService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/textfile/common/textfiles.service'; import { ExtHostContext } from '@codingame/monaco-vscode-api/vscode/vs/workbench/api/common/extHost.protocol'; import { raceCancellationError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async'; class ExtHostSaveParticipant { constructor(extHostContext) { this._proxy = ( extHostContext.getProxy(ExtHostContext.ExtHostDocumentSaveParticipant)); } async participate(editorModel, context, _progress, token) { if (!editorModel.textEditorModel || !shouldSynchronizeModel(editorModel.textEditorModel)) { return undefined; } const p = ( new Promise((resolve, reject) => { setTimeout(() => reject(( new Error(( localize(2642, "Aborted onWillSaveTextDocument-event after 1750ms"))))), 1750); this._proxy.$participateInSave(editorModel.resource, context.reason).then(values => { if (!values.every(success => success)) { return Promise.reject(( new Error("listener failed"))); } return undefined; }).then(resolve, reject); })); return raceCancellationError(p, token); } } let SaveParticipant = class SaveParticipant { constructor(extHostContext, instantiationService, _textFileService) { this._textFileService = _textFileService; this._saveParticipantDisposable = this._textFileService.files.addSaveParticipant( instantiationService.createInstance(ExtHostSaveParticipant, extHostContext) ); } dispose() { this._saveParticipantDisposable.dispose(); } }; SaveParticipant = __decorate([extHostCustomer, ( __param(1, IInstantiationService)), ( __param(2, ITextFileService))], SaveParticipant); export { SaveParticipant };