From f041bc0c5f05e3b53468b0de0765cbd9a1407c31 Mon Sep 17 00:00:00 2001 From: isidor Date: Mon, 10 Dec 2018 16:24:24 +0100 Subject: [PATCH] remove labelService from main side fixes #57788 --- src/tsconfig.strictNullChecks.json | 3 +-- src/vs/code/electron-main/app.ts | 6 ----- src/vs/code/electron-main/main.ts | 2 -- .../electron-main/historyMainService.ts | 12 ++++----- src/vs/platform/label/common/label.ts | 14 ++++++++++ .../electron-browser/label.contribution.ts | 27 ------------------- src/vs/workbench/workbench.main.ts | 1 - 7 files changed, 21 insertions(+), 44 deletions(-) delete mode 100644 src/vs/platform/label/electron-browser/label.contribution.ts diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 8b0bd6caae6..b612ba5daed 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -460,7 +460,6 @@ "./vs/platform/keybinding/common/usLayoutResolvedKeybinding.ts", "./vs/platform/keybinding/test/common/mockKeybindingService.ts", "./vs/platform/label/common/label.ts", - "./vs/platform/label/electron-browser/label.contribution.ts", "./vs/platform/launch/electron-main/launchService.ts", "./vs/platform/lifecycle/common/lifecycle.ts", "./vs/platform/lifecycle/electron-browser/lifecycleService.ts", @@ -747,4 +746,4 @@ "exclude": [ "./typings/require-monaco.d.ts" ] -} \ No newline at end of file +} diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 818a6b77cdb..dcfbe3a9315 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -61,7 +61,6 @@ import { connectRemoteAgentManagement, RemoteAgentConnectionContext } from 'vs/p import { IMenubarService } from 'vs/platform/menubar/common/menubar'; import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService'; import { MenubarChannel } from 'vs/platform/menubar/node/menubarIpc'; -import { ILabelService, RegisterFormatterEvent } from 'vs/platform/label/common/label'; import { hasArgs } from 'vs/platform/environment/node/argv'; import { RunOnceScheduler } from 'vs/base/common/async'; import { registerContextMenuListener } from 'vs/base/parts/contextmenu/electron-main/contextmenu'; @@ -98,7 +97,6 @@ export class CodeApplication extends Disposable { @IConfigurationService private configurationService: ConfigurationService, @IStateService private stateService: IStateService, @IHistoryMainService private historyMainService: IHistoryMainService, - @ILabelService private labelService: ILabelService ) { super(); @@ -318,10 +316,6 @@ export class CodeApplication extends Disposable { } }); - ipc.on('vscode:labelRegisterFormatter', (event: any, data: RegisterFormatterEvent) => { - this.labelService.registerFormatter(data.selector, data.formatter); - }); - ipc.on('vscode:toggleDevTools', (event: Event) => { event.sender.toggleDevTools(); }); diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 0708ad34354..62183f13f3e 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -47,7 +47,6 @@ import { uploadLogs } from 'vs/code/electron-main/logUploader'; import { setUnexpectedErrorHandler } from 'vs/base/common/errors'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { CommandLineDialogService } from 'vs/platform/dialogs/node/dialogService'; -import { ILabelService, LabelService } from 'vs/platform/label/common/label'; import { createWaitMarkerFile } from 'vs/code/node/wait'; function createServices(args: ParsedArgs, bufferLogService: BufferLogService): IInstantiationService { @@ -60,7 +59,6 @@ function createServices(args: ParsedArgs, bufferLogService: BufferLogService): I setTimeout(() => cleanupOlderLogs(environmentService).then(null, err => console.error(err)), 10000); services.set(IEnvironmentService, environmentService); - services.set(ILabelService, new LabelService(environmentService, void 0, void 0)); services.set(ILogService, logService); services.set(IWorkspacesMainService, new SyncDescriptor(WorkspacesMainService)); services.set(IHistoryMainService, new SyncDescriptor(HistoryMainService)); diff --git a/src/vs/platform/history/electron-main/historyMainService.ts b/src/vs/platform/history/electron-main/historyMainService.ts index bc023db8dfd..14481c50629 100644 --- a/src/vs/platform/history/electron-main/historyMainService.ts +++ b/src/vs/platform/history/electron-main/historyMainService.ts @@ -8,7 +8,7 @@ import * as arrays from 'vs/base/common/arrays'; import { IStateService } from 'vs/platform/state/common/state'; import { app } from 'electron'; import { ILogService } from 'vs/platform/log/common/log'; -import { getBaseLabel } from 'vs/base/common/labels'; +import { getBaseLabel, getPathLabel } from 'vs/base/common/labels'; import { IPath } from 'vs/platform/windows/common/windows'; import { Event as CommonEvent, Emitter } from 'vs/base/common/event'; import { isWindows, isMacintosh, isLinux } from 'vs/base/common/platform'; @@ -19,7 +19,8 @@ import { RunOnceScheduler } from 'vs/base/common/async'; import { getComparisonKey, isEqual as areResourcesEqual, dirname } from 'vs/base/common/resources'; import { URI, UriComponents } from 'vs/base/common/uri'; import { Schemas } from 'vs/base/common/network'; -import { ILabelService } from 'vs/platform/label/common/label'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { getSimpleWorkspaceLabel } from 'vs/platform/label/common/label'; interface ISerializedRecentlyOpened { workspaces2: (IWorkspaceIdentifier | string)[]; // IWorkspaceIdentifier or URI.toString() @@ -49,7 +50,7 @@ export class HistoryMainService implements IHistoryMainService { @IStateService private stateService: IStateService, @ILogService private logService: ILogService, @IWorkspacesMainService private workspacesMainService: IWorkspacesMainService, - @ILabelService private labelService: ILabelService + @IEnvironmentService private environmentService: IEnvironmentService ) { this.macOSRecentDocumentsUpdater = new RunOnceScheduler(() => this.updateMacOSRecentDocuments(), 800); @@ -58,7 +59,6 @@ export class HistoryMainService implements IHistoryMainService { private registerListeners(): void { this.workspacesMainService.onWorkspaceSaved(e => this.onWorkspaceSaved(e)); - this.labelService.onDidRegisterFormatter(() => this._onRecentlyOpenedChange.fire()); } private onWorkspaceSaved(e: IWorkspaceSavedEvent): void { @@ -370,12 +370,12 @@ export class HistoryMainService implements IHistoryMainService { type: 'custom', name: nls.localize('recentFolders', "Recent Workspaces"), items: arrays.coalesce(this.getRecentlyOpened().workspaces.slice(0, 7 /* limit number of entries here */).map(workspace => { - const title = this.labelService.getWorkspaceLabel(workspace); + const title = getSimpleWorkspaceLabel(workspace, this.environmentService.workspacesHome); let description; let args; if (isSingleFolderWorkspaceIdentifier(workspace)) { const parentFolder = dirname(workspace); - description = parentFolder ? nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), this.labelService.getUriLabel(parentFolder)) : getBaseLabel(workspace); + description = parentFolder ? nls.localize('folderDesc', "{0} {1}", getBaseLabel(workspace), getPathLabel(parentFolder, this.environmentService)) : getBaseLabel(workspace); args = `--folder-uri "${workspace.toString()}"`; } else { description = nls.localize('codeWorkspace', "Code Workspace"); diff --git a/src/vs/platform/label/common/label.ts b/src/vs/platform/label/common/label.ts index abe748d84f5..0e8cdb2fcaa 100644 --- a/src/vs/platform/label/common/label.ts +++ b/src/vs/platform/label/common/label.ts @@ -61,6 +61,20 @@ function hasDriveLetter(path: string): boolean { return !!(isWindows && path && path[2] === ':'); } +export function getSimpleWorkspaceLabel(workspace: IWorkspaceIdentifier | URI, workspaceHome: string): string { + if (isSingleFolderWorkspaceIdentifier(workspace)) { + return basenameOrAuthority(workspace); + } + // Workspace: Untitled + if (isParent(workspace.configPath, workspaceHome, !isLinux /* ignore case */)) { + return localize('untitledWorkspace', "Untitled (Workspace)"); + } + + const filename = basename(workspace.configPath); + const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1); + return localize('workspaceName', "{0} (Workspace)", workspaceName); +} + export class LabelService implements ILabelService { _serviceBrand: any; diff --git a/src/vs/platform/label/electron-browser/label.contribution.ts b/src/vs/platform/label/electron-browser/label.contribution.ts deleted file mode 100644 index 68bd62b54a7..00000000000 --- a/src/vs/platform/label/electron-browser/label.contribution.ts +++ /dev/null @@ -1,27 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -// TODO@Isidor bad layering -// tslint:disable-next-line:import-patterns -import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; -import { ILabelService } from 'vs/platform/label/common/label'; -import { ipcRenderer as ipc } from 'electron'; -import { Registry } from 'vs/platform/registry/common/platform'; -import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; - -/** - * Uri display registration needs to be shared from renderer to main. - * Since there will be another instance of the uri display service running on main. - */ -class LabelRegistrationContribution implements IWorkbenchContribution { - - constructor(@ILabelService labelService: ILabelService) { - labelService.onDidRegisterFormatter(data => { - ipc.send('vscode:labelRegisterFormatter', data); - }); - } -} - -Registry.as(WorkbenchExtensions.Workbench).registerWorkbenchContribution(LabelRegistrationContribution, LifecyclePhase.Starting); diff --git a/src/vs/workbench/workbench.main.ts b/src/vs/workbench/workbench.main.ts index dbaf8bcf012..dc6ef56c636 100644 --- a/src/vs/workbench/workbench.main.ts +++ b/src/vs/workbench/workbench.main.ts @@ -15,7 +15,6 @@ import 'vs/editor/editor.all'; // Platform import 'vs/platform/widget/browser/contextScopedHistoryWidget'; -import 'vs/platform/label/electron-browser/label.contribution'; // Menus/Actions import 'vs/workbench/services/actions/electron-browser/menusExtensionPoint'; -- GitLab