diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditors.ts b/src/vs/workbench/contrib/customEditor/browser/customEditors.ts index d6be547318199c19b831816ad504d8df429f0c39..421b2241d22c901aea0df69b9c72004c581233d4 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditors.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditors.ts @@ -17,6 +17,7 @@ import { EditorActivation, IEditorOptions, ITextEditorOptions } from 'vs/platfor import { FileOperation, IFileService } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput'; +import { IStorageService } from 'vs/platform/storage/common/storage'; import * as colorRegistry from 'vs/platform/theme/common/colorRegistry'; import { registerThemingParticipant } from 'vs/platform/theme/common/themeService'; import { EditorServiceImpl } from 'vs/workbench/browser/parts/editor/editor'; @@ -37,7 +38,7 @@ import { CustomEditorInput } from './customEditorInput'; export class CustomEditorService extends Disposable implements ICustomEditorService, ICustomEditorViewTypesHandler { _serviceBrand: any; - private readonly _contributedEditors = this._register(new ContributedCustomEditors()); + private readonly _contributedEditors: ContributedCustomEditors; private readonly _editorCapabilities = new Map(); private readonly _models = new CustomEditorModelManager(); @@ -51,6 +52,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ constructor( @IContextKeyService contextKeyService: IContextKeyService, @IFileService fileService: IFileService, + @IStorageService storageService: IStorageService, @IConfigurationService private readonly configurationService: IConfigurationService, @IEditorService private readonly editorService: IEditorService, @IEditorGroupsService private readonly editorGroupService: IEditorGroupsService, @@ -64,11 +66,13 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ this._focusedCustomEditorIsEditable = CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE.bindTo(contextKeyService); this._webviewHasOwnEditFunctions = webviewHasOwnEditFunctionsContext.bindTo(contextKeyService); - this._register(this.editorService.registerCustomEditorViewTypesHandler('Custom Editor', this)); + + this._contributedEditors = this._register(new ContributedCustomEditors(storageService)); this._register(this._contributedEditors.onChange(() => { this.updateContexts(); this._onDidChangeViewTypes.fire(); })); + this._register(this.editorService.registerCustomEditorViewTypesHandler('Custom Editor', this)); this._register(this.editorService.onDidActiveEditorChange(() => this.updateContexts())); this._register(fileService.onDidRunOperation(e => { diff --git a/src/vs/workbench/contrib/customEditor/common/contributedCustomEditors.ts b/src/vs/workbench/contrib/customEditor/common/contributedCustomEditors.ts index b00fa6c5f63cd59d6f02da882e6bb3af1954aa04..7633e95e1748244a85051466e6d21fb34dbed188 100644 --- a/src/vs/workbench/contrib/customEditor/common/contributedCustomEditors.ts +++ b/src/vs/workbench/contrib/customEditor/common/contributedCustomEditors.ts @@ -8,9 +8,12 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { URI } from 'vs/base/common/uri'; import * as nls from 'vs/nls'; import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; -import { CustomEditorInfo, CustomEditorPriority } from 'vs/workbench/contrib/customEditor/common/customEditor'; +import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; +import { Memento } from 'vs/workbench/common/memento'; +import { CustomEditorDescriptor, CustomEditorInfo, CustomEditorPriority } from 'vs/workbench/contrib/customEditor/common/customEditor'; import { customEditorsExtensionPoint, ICustomEditorsExtensionPoint } from 'vs/workbench/contrib/customEditor/common/extensionPoint'; import { DEFAULT_EDITOR_ID } from 'vs/workbench/contrib/files/common/files'; +import { IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry'; const builtinProviderDisplayName = nls.localize('builtinProviderDisplayName', "Built-in"); @@ -26,32 +29,52 @@ export const defaultCustomEditor = new CustomEditorInfo({ export class ContributedCustomEditors extends Disposable { + private static readonly CUSTOM_EDITORS_STORAGE_ID = 'customEditors'; + private static readonly CUSTOM_EDITORS_ENTRY_ID = 'editors'; + private readonly _editors = new Map(); + private readonly _memento: Memento; - constructor() { + constructor(storageService: IStorageService) { super(); + this._memento = new Memento(ContributedCustomEditors.CUSTOM_EDITORS_STORAGE_ID, storageService); + + const mementoObject = this._memento.getMemento(StorageScope.GLOBAL); + for (const info of (mementoObject[ContributedCustomEditors.CUSTOM_EDITORS_ENTRY_ID] || []) as CustomEditorDescriptor[]) { + this.add(new CustomEditorInfo(info)); + } + customEditorsExtensionPoint.setHandler(extensions => { - this._editors.clear(); - - for (const extension of extensions) { - for (const webviewEditorContribution of extension.value) { - this.add(new CustomEditorInfo({ - id: webviewEditorContribution.viewType, - displayName: webviewEditorContribution.displayName, - providerDisplayName: extension.description.isBuiltin ? builtinProviderDisplayName : extension.description.displayName || extension.description.identifier.value, - selector: webviewEditorContribution.selector || [], - priority: getPriorityFromContribution(webviewEditorContribution, extension.description), - })); - } - } - this._onChange.fire(); + this.update(extensions); }); } private readonly _onChange = this._register(new Emitter()); public readonly onChange = this._onChange.event; + private update(extensions: readonly IExtensionPointUser[]) { + this._editors.clear(); + + for (const extension of extensions) { + for (const webviewEditorContribution of extension.value) { + this.add(new CustomEditorInfo({ + id: webviewEditorContribution.viewType, + displayName: webviewEditorContribution.displayName, + providerDisplayName: extension.description.isBuiltin ? builtinProviderDisplayName : extension.description.displayName || extension.description.identifier.value, + selector: webviewEditorContribution.selector || [], + priority: getPriorityFromContribution(webviewEditorContribution, extension.description), + })); + } + } + + const mementoObject = this._memento.getMemento(StorageScope.GLOBAL); + mementoObject[ContributedCustomEditors.CUSTOM_EDITORS_ENTRY_ID] = Array.from(this._editors.values()); + this._memento.saveMemento(); + + this._onChange.fire(); + } + public [Symbol.iterator](): Iterator { return this._editors.values(); } diff --git a/src/vs/workbench/contrib/customEditor/common/customEditor.ts b/src/vs/workbench/contrib/customEditor/common/customEditor.ts index e914afd609f4a8c16f1ad45a298da792efc779e8..cbe489306b9fb3b8b0353a9201f62477822bc8ee 100644 --- a/src/vs/workbench/contrib/customEditor/common/customEditor.ts +++ b/src/vs/workbench/contrib/customEditor/common/customEditor.ts @@ -79,7 +79,15 @@ export interface CustomEditorSelector { readonly filenamePattern?: string; } -export class CustomEditorInfo { +export interface CustomEditorDescriptor { + readonly id: string; + readonly displayName: string; + readonly providerDisplayName: string; + readonly priority: CustomEditorPriority; + readonly selector: readonly CustomEditorSelector[]; +} + +export class CustomEditorInfo implements CustomEditorDescriptor { public readonly id: string; public readonly displayName: string; @@ -87,13 +95,7 @@ export class CustomEditorInfo { public readonly priority: CustomEditorPriority; public readonly selector: readonly CustomEditorSelector[]; - constructor(descriptor: { - readonly id: string; - readonly displayName: string; - readonly providerDisplayName: string; - readonly priority: CustomEditorPriority; - readonly selector: readonly CustomEditorSelector[]; - }) { + constructor(descriptor: CustomEditorDescriptor) { this.id = descriptor.id; this.displayName = descriptor.displayName; this.providerDisplayName = descriptor.providerDisplayName;