From eaa2d3bb23ce6dc79eadb497ea697e4c192ece6a Mon Sep 17 00:00:00 2001 From: isidor Date: Mon, 1 Jul 2019 15:20:56 +0200 Subject: [PATCH] introduce extHostLabelService and mainThreadLabelService fixes #75881 --- .../api/browser/extensionHost.contribution.ts | 1 + .../api/browser/mainThreadFileSystem.ts | 15 -------- .../api/browser/mainThreadLabelService.ts | 36 +++++++++++++++++++ .../workbench/api/common/extHost.protocol.ts | 13 +++++-- .../workbench/api/common/extHostFileSystem.ts | 10 ------ .../api/common/extHostLabelService.ts | 27 ++++++++++++++ src/vs/workbench/api/node/extHost.api.impl.ts | 4 ++- 7 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 src/vs/workbench/api/browser/mainThreadLabelService.ts create mode 100644 src/vs/workbench/api/common/extHostLabelService.ts diff --git a/src/vs/workbench/api/browser/extensionHost.contribution.ts b/src/vs/workbench/api/browser/extensionHost.contribution.ts index 2f07210ca5b..dca4efc3835 100644 --- a/src/vs/workbench/api/browser/extensionHost.contribution.ts +++ b/src/vs/workbench/api/browser/extensionHost.contribution.ts @@ -54,6 +54,7 @@ import './mainThreadWebview'; import './mainThreadWorkspace'; import './mainThreadComments'; import './mainThreadTask'; +import './mainThreadLabelService'; import 'vs/workbench/api/common/apiCommands'; export class ExtensionPoints implements IWorkbenchContribution { diff --git a/src/vs/workbench/api/browser/mainThreadFileSystem.ts b/src/vs/workbench/api/browser/mainThreadFileSystem.ts index cb84e3c1323..331ba328297 100644 --- a/src/vs/workbench/api/browser/mainThreadFileSystem.ts +++ b/src/vs/workbench/api/browser/mainThreadFileSystem.ts @@ -9,7 +9,6 @@ import { URI, UriComponents } from 'vs/base/common/uri'; import { FileWriteOptions, FileSystemProviderCapabilities, IFileChange, IFileService, IFileSystemProvider, IStat, IWatchOptions, FileType, FileOverwriteOptions, FileDeleteOptions, FileOpenOptions, IFileStat } from 'vs/platform/files/common/files'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; import { ExtHostContext, ExtHostFileSystemShape, IExtHostContext, IFileChangeDto, MainContext, MainThreadFileSystemShape } from '../common/extHost.protocol'; -import { ResourceLabelFormatter, ILabelService } from 'vs/platform/label/common/label'; import { VSBuffer } from 'vs/base/common/buffer'; @extHostNamedCustomer(MainContext.MainThreadFileSystem) @@ -17,12 +16,10 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape { private readonly _proxy: ExtHostFileSystemShape; private readonly _fileProvider = new Map(); - private readonly _resourceLabelFormatters = new Map(); constructor( extHostContext: IExtHostContext, @IFileService private readonly _fileService: IFileService, - @ILabelService private readonly _labelService: ILabelService ) { this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostFileSystem); } @@ -41,18 +38,6 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape { this._fileProvider.delete(handle); } - $registerResourceLabelFormatter(handle: number, formatter: ResourceLabelFormatter): void { - // Dynamicily registered formatters should have priority over those contributed via package.json - formatter.priority = true; - const disposable = this._labelService.registerFormatter(formatter); - this._resourceLabelFormatters.set(handle, disposable); - } - - $unregisterResourceLabelFormatter(handle: number): void { - dispose(this._resourceLabelFormatters.get(handle)); - this._resourceLabelFormatters.delete(handle); - } - $onFileSystemChange(handle: number, changes: IFileChangeDto[]): void { const fileProvider = this._fileProvider.get(handle); if (!fileProvider) { diff --git a/src/vs/workbench/api/browser/mainThreadLabelService.ts b/src/vs/workbench/api/browser/mainThreadLabelService.ts new file mode 100644 index 00000000000..a0b85358bda --- /dev/null +++ b/src/vs/workbench/api/browser/mainThreadLabelService.ts @@ -0,0 +1,36 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { MainContext, MainThreadLabelServiceShape, IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; +import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; +import { ResourceLabelFormatter, ILabelService } from 'vs/platform/label/common/label'; +import { IDisposable, dispose } from 'vs/base/common/lifecycle'; + +@extHostNamedCustomer(MainContext.MainThreadLabelService) +export class MainThreadLabelService implements MainThreadLabelServiceShape { + + private readonly _resourceLabelFormatters = new Map(); + + constructor( + _: IExtHostContext, + @ILabelService private readonly _labelService: ILabelService + ) { } + + $registerResourceLabelFormatter(handle: number, formatter: ResourceLabelFormatter): void { + // Dynamicily registered formatters should have priority over those contributed via package.json + formatter.priority = true; + const disposable = this._labelService.registerFormatter(formatter); + this._resourceLabelFormatters.set(handle, disposable); + } + + $unregisterResourceLabelFormatter(handle: number): void { + dispose(this._resourceLabelFormatters.get(handle)); + this._resourceLabelFormatters.delete(handle); + } + + dispose(): void { + // noop + } +} \ No newline at end of file diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index f9f60f7dde7..6b747ffac41 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -592,8 +592,6 @@ export interface IFileChangeDto { export interface MainThreadFileSystemShape extends IDisposable { $registerFileSystemProvider(handle: number, scheme: string, capabilities: files.FileSystemProviderCapabilities): void; $unregisterProvider(handle: number): void; - $registerResourceLabelFormatter(handle: number, formatter: ResourceLabelFormatter): void; - $unregisterResourceLabelFormatter(handle: number): void; $onFileSystemChange(handle: number, resource: IFileChangeDto[]): void; $stat(uri: UriComponents): Promise; @@ -606,6 +604,11 @@ export interface MainThreadFileSystemShape extends IDisposable { $delete(resource: UriComponents, opts: files.FileDeleteOptions): Promise; } +export interface MainThreadLabelServiceShape extends IDisposable { + $registerResourceLabelFormatter(handle: number, formatter: ResourceLabelFormatter): void; + $unregisterResourceLabelFormatter(handle: number): void; +} + export interface MainThreadSearchShape extends IDisposable { $registerFileSearchProvider(handle: number, scheme: string): void; $registerTextSearchProvider(handle: number, scheme: string): void; @@ -832,6 +835,10 @@ export interface ExtHostFileSystemShape { $write(handle: number, fd: number, pos: number, data: VSBuffer): Promise; } +export interface ExtHostLabelServiceShape { + $registerResourceLabelFormatter(formatter: ResourceLabelFormatter): IDisposable; +} + export interface ExtHostSearchShape { $provideFileSearchResults(handle: number, session: number, query: search.IRawQuery, token: CancellationToken): Promise; $provideTextSearchResults(handle: number, session: number, query: search.IRawTextQuery, token: CancellationToken): Promise; @@ -1331,6 +1338,7 @@ export const MainContext = { MainThreadSearch: createMainId('MainThreadSearch'), MainThreadTask: createMainId('MainThreadTask'), MainThreadWindow: createMainId('MainThreadWindow'), + MainThreadLabelService: createMainId('MainThreadLabelService') }; export const ExtHostContext = { @@ -1364,4 +1372,5 @@ export const ExtHostContext = { ExtHostStorage: createMainId('ExtHostStorage'), ExtHostUrls: createExtId('ExtHostUrls'), ExtHostOutputService: createMainId('ExtHostOutputService'), + ExtHosLabelService: createMainId('ExtHostLabelService') }; diff --git a/src/vs/workbench/api/common/extHostFileSystem.ts b/src/vs/workbench/api/common/extHostFileSystem.ts index 778a5cb67ad..fe97cae97ee 100644 --- a/src/vs/workbench/api/common/extHostFileSystem.ts +++ b/src/vs/workbench/api/common/extHostFileSystem.ts @@ -12,7 +12,6 @@ import { FileChangeType } from 'vs/workbench/api/common/extHostTypes'; import * as typeConverter from 'vs/workbench/api/common/extHostTypeConverters'; import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguageFeatures'; import { Schemas } from 'vs/base/common/network'; -import { ResourceLabelFormatter } from 'vs/platform/label/common/label'; import { State, StateMachine, LinkComputer, Edge } from 'vs/editor/common/modes/linkComputer'; import { commonPrefixLength } from 'vs/base/common/strings'; import { CharCode } from 'vs/base/common/charCode'; @@ -241,15 +240,6 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape { }); } - registerResourceLabelFormatter(formatter: ResourceLabelFormatter): IDisposable { - const handle = this._handlePool++; - this._proxy.$registerResourceLabelFormatter(handle, formatter); - - return toDisposable(() => { - this._proxy.$unregisterResourceLabelFormatter(handle); - }); - } - private static _asIStat(stat: vscode.FileStat): files.IStat { const { type, ctime, mtime, size } = stat; return { type, ctime, mtime, size }; diff --git a/src/vs/workbench/api/common/extHostLabelService.ts b/src/vs/workbench/api/common/extHostLabelService.ts new file mode 100644 index 00000000000..3a7eec9b5a1 --- /dev/null +++ b/src/vs/workbench/api/common/extHostLabelService.ts @@ -0,0 +1,27 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { ResourceLabelFormatter } from 'vs/platform/label/common/label'; +import { IDisposable, toDisposable } from 'vs/base/common/lifecycle'; +import { MainThreadLabelServiceShape, ExtHostLabelServiceShape, MainContext, IMainContext } from 'vs/workbench/api/common/extHost.protocol'; + +export class ExtHostLabelService implements ExtHostLabelServiceShape { + + private readonly _proxy: MainThreadLabelServiceShape; + private _handlePool: number = 0; + + constructor(mainContext: IMainContext) { + this._proxy = mainContext.getProxy(MainContext.MainThreadLabelService); + } + + $registerResourceLabelFormatter(formatter: ResourceLabelFormatter): IDisposable { + const handle = this._handlePool++; + this._proxy.$registerResourceLabelFormatter(handle, formatter); + + return toDisposable(() => { + this._proxy.$unregisterResourceLabelFormatter(handle); + }); + } +} \ No newline at end of file diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 3ad15b30f7d..4c3395f98a6 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -67,6 +67,7 @@ import { values } from 'vs/base/common/collections'; import { Schemas } from 'vs/base/common/network'; import { IURITransformer } from 'vs/base/common/uriIpc'; import { ExtHostEditorInsets } from 'vs/workbench/api/common/extHostCodeInsets'; +import { ExtHostLabelService } from 'vs/workbench/api/common/extHostLabelService'; export interface IExtensionApiFactory { (extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode; @@ -125,6 +126,7 @@ export function createApiFactory( const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress))); const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, new ExtHostOutputService(LogOutputChannelFactory, initData.logsLocation, rpcProtocol)); rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage); + const extHostLabelService = rpcProtocol.set(ExtHostContext.ExtHosLabelService, new ExtHostLabelService(rpcProtocol)); if (initData.remote.isRemote && initData.remote.authority) { extHostTask.registerTaskSystem(Schemas.vscodeRemote, { @@ -694,7 +696,7 @@ export function createApiFactory( return extensionService.registerRemoteAuthorityResolver(authorityPrefix, resolver); }), registerResourceLabelFormatter: proposedApiFunction(extension, (formatter: vscode.ResourceLabelFormatter) => { - return extHostFileSystem.registerResourceLabelFormatter(formatter); + return extHostLabelService.$registerResourceLabelFormatter(formatter); }), onDidRenameFile: proposedApiFunction(extension, (listener: (e: vscode.FileRenameEvent) => any, thisArg?: any, disposables?: vscode.Disposable[]) => { return extHostFileSystemEvent.onDidRenameFile(listener, thisArg, disposables); -- GitLab