move uriLabelService to be a core service. Configuraion service depends on it, not the other way around

This commit is contained in:
isidor 2018-08-22 17:40:25 +02:00
parent 07c6df15a4
commit 9acd33950e
12 changed files with 76 additions and 36 deletions

View file

@ -58,7 +58,7 @@ function createServices(args: ParsedArgs, bufferLogService: BufferLogService): I
const environmentService = new EnvironmentService(args, process.execPath);
const consoleLogService = new ConsoleLogMainService(getLogLevel(environmentService));
const logService = new MultiplexLogService([consoleLogService, bufferLogService]);
const uriLabelService = new UriLabelService(environmentService, undefined);
const uriLabelService = new UriLabelService(environmentService);
process.once('exit', () => logService.dispose());

View file

@ -609,6 +609,10 @@ export class SimpleUriLabelService implements IUriLabelService {
return resource.path;
}
public getWorkspaceLabel(workspace: IWorkspaceIdentifier | URI, options?: { verbose: boolean; }): string {
throw new Error('Not implemented');
}
public registerFormater(schema: string, formater: UriLabelRules): IDisposable {
throw new Error('Not implemented');
}

View file

@ -13,10 +13,15 @@ import { isEqual, basenameOrAuthority } from 'vs/base/common/resources';
import { isLinux, isWindows } from 'vs/base/common/platform';
import { tildify, getPathLabel } from 'vs/base/common/labels';
import { ltrim } from 'vs/base/common/strings';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { localize } from 'vs/nls';
import { isParent } from 'vs/platform/files/common/files';
import { basename, dirname, join } from 'vs/base/common/paths';
export interface IUriLabelService {
_serviceBrand: any;
getLabel(resource: URI, relative?: boolean, forceNoTildify?: boolean): string;
getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier), options?: { verbose: boolean }): string;
registerFormater(schema: string, formater: UriLabelRules): IDisposable;
onDidRegisterFormater: Event<{ scheme: string, formater: UriLabelRules }>;
}
@ -41,18 +46,21 @@ export class UriLabelService implements IUriLabelService {
private readonly formaters = new Map<string, UriLabelRules>();
private readonly _onDidRegisterFormater = new Emitter<{ scheme: string, formater: UriLabelRules }>();
private contextService: IWorkspaceContextService;
constructor(
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) { }
get onDidRegisterFormater(): Event<{ scheme: string, formater: UriLabelRules }> {
return this._onDidRegisterFormater.event;
}
getLabel(resource: URI, relative: boolean, forceNoTildify?: boolean): string {
acquireContextService(contextService: IWorkspaceContextService): void {
this.contextService = contextService;
}
getLabel(resource: URI, relative?: boolean, forceNoTildify?: boolean): string {
if (!resource) {
return undefined;
}
@ -85,6 +93,28 @@ export class UriLabelService implements IUriLabelService {
return this.formatUri(resource, formater, forceNoTildify);
}
getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier), options?: { verbose: boolean }): string {
// Workspace: Single Folder
if (isSingleFolderWorkspaceIdentifier(workspace)) {
// Folder on disk
return options && options.verbose ? this.getLabel(workspace) : basenameOrAuthority(workspace);
}
// Workspace: Untitled
if (isParent(workspace.configPath, this.environmentService.workspacesHome, !isLinux /* ignore case */)) {
return localize('untitledWorkspace', "Untitled (Workspace)");
}
// Workspace: Saved
const filename = basename(workspace.configPath);
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
if (options && options.verbose) {
return localize('workspaceNameVerbose', "{0} (Workspace)", this.getLabel(URI.file(join(dirname(workspace.configPath), workspaceName))));
}
return localize('workspaceName', "{0} (Workspace)", workspaceName);
}
registerFormater(scheme: string, formater: UriLabelRules): IDisposable {
this.formaters.set(scheme, formater);
this._onDidRegisterFormater.fire({ scheme, formater });

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { IUriLabelService, UriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
import { UriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
import { TestEnvironmentService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { Schemas } from 'vs/base/common/network';
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
@ -14,10 +14,11 @@ import { isWindows } from 'vs/base/common/platform';
suite('URI Label', () => {
let uriLabelService: IUriLabelService;
let uriLabelService: UriLabelService;
setup(() => {
uriLabelService = new UriLabelService(TestEnvironmentService, new TestContextService());
uriLabelService = new UriLabelService(TestEnvironmentService);
uriLabelService.acquireContextService(new TestContextService());
});
test('file scheme', function () {

View file

@ -48,6 +48,7 @@ import { RelayURLService } from 'vs/platform/url/common/urlService';
import { MenubarChannelClient } from 'vs/platform/menubar/node/menubarIpc';
import { IMenubarService } from 'vs/platform/menubar/common/menubar';
import { Schemas } from 'vs/base/common/network';
import { IUriLabelService, UriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
gracefulFs.gracefulify(fs); // enable gracefulFs
@ -98,13 +99,15 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
const mainServices = createMainProcessServices(mainProcessClient, configuration);
const environmentService = new EnvironmentService(configuration, configuration.execPath);
const uriLabelService = new UriLabelService(environmentService);
const logService = createLogService(mainProcessClient, configuration, environmentService);
logService.trace('openWorkbench configuration', JSON.stringify(configuration));
// Since the configuration service is one of the core services that is used in so many places, we initialize it
// right before startup of the workbench shell to have its data ready for consumers
return createAndInitializeWorkspaceService(configuration, environmentService).then(workspaceService => {
return createAndInitializeWorkspaceService(configuration, environmentService, uriLabelService).then(workspaceService => {
const storageService = createStorageService(workspaceService, environmentService);
uriLabelService.acquireContextService(workspaceService);
return domContentLoaded().then(() => {
@ -115,7 +118,8 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
configurationService: workspaceService,
environmentService,
logService,
storageService
storageService,
uriLabelService
}, mainServices, mainProcessClient, configuration);
shell.open();
@ -131,10 +135,10 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
});
}
function createAndInitializeWorkspaceService(configuration: IWindowConfiguration, environmentService: EnvironmentService): TPromise<WorkspaceService> {
function createAndInitializeWorkspaceService(configuration: IWindowConfiguration, environmentService: EnvironmentService, uriLabelService: IUriLabelService): TPromise<WorkspaceService> {
return validateFolderUri(configuration.folderUri, configuration.verbose).then(validatedFolderUri => {
const workspaceService = new WorkspaceService(environmentService);
const workspaceService = new WorkspaceService(environmentService, uriLabelService);
return workspaceService.initialize(configuration.workspace || validatedFolderUri || configuration).then(() => workspaceService, error => workspaceService);
});

View file

@ -98,6 +98,7 @@ import { ExtensionManagementServerService } from 'vs/workbench/services/extensio
import { DownloadServiceChannel } from 'vs/platform/download/node/downloadIpc';
import { DefaultURITransformer } from 'vs/base/common/uriIpc';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService';
import { IUriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
/**
* Services that we require for the Shell
@ -108,6 +109,7 @@ export interface ICoreServices {
environmentService: IEnvironmentService;
logService: ILogService;
storageService: IStorageService;
uriLabelService: IUriLabelService;
}
/**
@ -117,6 +119,7 @@ export interface ICoreServices {
export class WorkbenchShell extends Disposable {
private storageService: IStorageService;
private environmentService: IEnvironmentService;
private uriLabelService: IUriLabelService;
private logService: ILogService;
private configurationService: IConfigurationService;
private contextService: IWorkspaceContextService;
@ -145,6 +148,7 @@ export class WorkbenchShell extends Disposable {
this.contextService = coreServices.contextService;
this.configurationService = coreServices.configurationService;
this.environmentService = coreServices.environmentService;
this.uriLabelService = coreServices.uriLabelService;
this.logService = coreServices.logService;
this.storageService = coreServices.storageService;
@ -316,6 +320,7 @@ export class WorkbenchShell extends Disposable {
serviceCollection.set(IWorkspaceContextService, this.contextService);
serviceCollection.set(IConfigurationService, this.configurationService);
serviceCollection.set(IEnvironmentService, this.environmentService);
serviceCollection.set(IUriLabelService, this.uriLabelService);
serviceCollection.set(ILogService, this._register(this.logService));
serviceCollection.set(IStorageService, this.storageService);

View file

@ -116,7 +116,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
import { WorkbenchThemeService } from 'vs/workbench/services/themes/electron-browser/workbenchThemeService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IUriLabelService, UriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
interface WorkbenchParams {
configuration: IWindowConfiguration;
@ -336,11 +335,6 @@ export class Workbench extends Disposable implements IPartService {
// Clipboard
serviceCollection.set(IClipboardService, new ClipboardService());
// Uri Display
const uriLabelService = new UriLabelService(this.environmentService, this.contextService);
serviceCollection.set(IUriLabelService, uriLabelService);
this.configurationService.acquireUriLabelService(uriLabelService);
// Status bar
this.statusbarPart = this.instantiationService.createInstance(StatusbarPart, Identifiers.STATUSBAR_PART);
this._register(toDisposable(() => this.statusbarPart.shutdown()));

View file

@ -26,7 +26,7 @@ import { IWorkspaceConfigurationService, FOLDER_CONFIG_FOLDER_NAME, defaultSetti
import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationNode, IConfigurationRegistry, Extensions, IConfigurationPropertySchema, allSettings, windowSettings, resourceSettings, applicationSettings } from 'vs/platform/configuration/common/configurationRegistry';
import { createHash } from 'crypto';
import { getWorkspaceLabel, IWorkspaceIdentifier, isWorkspaceIdentifier, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspaceIdentifier, isWorkspaceIdentifier, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { ICommandService } from 'vs/platform/commands/common/commands';
@ -69,11 +69,10 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
public readonly onDidChangeWorkbenchState: Event<WorkbenchState> = this._onDidChangeWorkbenchState.event;
private fileService: IFileService;
private uriLabelService: IUriLabelService;
private configurationEditingService: ConfigurationEditingService;
private jsonEditingService: JSONEditingService;
constructor(private environmentService: IEnvironmentService, private workspaceSettingsRootFolder: string = FOLDER_CONFIG_FOLDER_NAME) {
constructor(private environmentService: IEnvironmentService, private uriLabelService: IUriLabelService, private workspaceSettingsRootFolder: string = FOLDER_CONFIG_FOLDER_NAME) {
super();
this.defaultConfiguration = new DefaultConfigurationModel();
@ -319,10 +318,6 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
});
}
acquireUriLabelService(uriLabelService: IUriLabelService): void {
this.uriLabelService = uriLabelService;
}
acquireInstantiationService(instantiationService: IInstantiationService): void {
this.configurationEditingService = instantiationService.createInstance(ConfigurationEditingService);
this.jsonEditingService = instantiationService.createInstance(JSONEditingService);
@ -346,7 +341,7 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
.then(() => {
const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), URI.file(dirname(workspaceConfigPath.fsPath)));
const workspaceId = workspaceIdentifier.id;
const workspaceName = getWorkspaceLabel({ id: workspaceId, configPath: workspaceConfigPath.fsPath }, this.environmentService, this.uriLabelService);
const workspaceName = this.uriLabelService.getWorkspaceLabel({ id: workspaceId, configPath: workspaceConfigPath.fsPath });
return new Workspace(workspaceId, workspaceName, workspaceFolders, workspaceConfigPath);
});
}
@ -369,11 +364,11 @@ export class WorkspaceService extends Disposable implements IWorkspaceConfigurat
}
const id = createHash('md5').update(folder.fsPath).update(ctime ? String(ctime) : '').digest('hex');
return new Workspace(id, getWorkspaceLabel(folder, this.environmentService, this.uriLabelService), toWorkspaceFolders([{ path: folder.fsPath }]), null, ctime);
return new Workspace(id, this.uriLabelService.getWorkspaceLabel(folder), toWorkspaceFolders([{ path: folder.fsPath }]), null, ctime);
});
} else {
const id = createHash('md5').update(folder.toString()).digest('hex');
return TPromise.as(new Workspace(id, getWorkspaceLabel(folder, this.environmentService, this.uriLabelService), toWorkspaceFolders([{ uri: folder.toString() }]), null));
return TPromise.as(new Workspace(id, this.uriLabelService.getWorkspaceLabel(folder), toWorkspaceFolders([{ uri: folder.toString() }]), null));
}
}

View file

@ -39,6 +39,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
import { ICommandService } from 'vs/platform/commands/common/commands';
import { CommandService } from 'vs/workbench/services/commands/common/commandService';
import URI from 'vs/base/common/uri';
import { UriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
class SettingsTestEnvironmentService extends EnvironmentService {
@ -102,7 +103,7 @@ suite('ConfigurationEditingService', () => {
instantiationService = <TestInstantiationService>workbenchInstantiationService();
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
instantiationService.stub(IEnvironmentService, environmentService);
const workspaceService = new WorkspaceService(environmentService);
const workspaceService = new WorkspaceService(environmentService, new UriLabelService(environmentService));
instantiationService.stub(IWorkspaceContextService, workspaceService);
return workspaceService.initialize(noWorkspace ? {} as IWindowConfiguration : URI.file(workspaceDir)).then(() => {
instantiationService.stub(IConfigurationService, workspaceService);

View file

@ -35,6 +35,7 @@ import { IJSONEditingService } from 'vs/workbench/services/configuration/common/
import { JSONEditingService } from 'vs/workbench/services/configuration/node/jsonEditingService';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { UriLabelService } from 'vs/platform/uriLabel/common/uriLabel';
class SettingsTestEnvironmentService extends EnvironmentService {
@ -86,7 +87,8 @@ suite('WorkspaceContextService - Folder', () => {
workspaceResource = folderDir;
const globalSettingsFile = path.join(parentDir, 'settings.json');
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
workspaceContextService = new WorkspaceService(environmentService);
const uriLabelService = new UriLabelService(environmentService);
workspaceContextService = new WorkspaceService(environmentService, uriLabelService);
return (<WorkspaceService>workspaceContextService).initialize(URI.file(folderDir));
});
});
@ -143,7 +145,8 @@ suite('WorkspaceContextService - Workspace', () => {
parentResource = parentDir;
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, path.join(parentDir, 'settings.json'));
const workspaceService = new WorkspaceService(environmentService);
const uriLabelService = new UriLabelService(environmentService);
const workspaceService = new WorkspaceService(environmentService, uriLabelService);
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
instantiationService.stub(IWorkspaceContextService, workspaceService);
@ -406,7 +409,8 @@ suite('WorkspaceService - Initialization', () => {
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const workspaceService = new WorkspaceService(environmentService);
const uriLabelService = new UriLabelService(environmentService);
const workspaceService = new WorkspaceService(environmentService, uriLabelService);
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
instantiationService.stub(IEnvironmentService, environmentService);
@ -661,7 +665,8 @@ suite('WorkspaceConfigurationService - Folder', () => {
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const workspaceService = new WorkspaceService(environmentService);
const uriLabelService = new UriLabelService(environmentService);
const workspaceService = new WorkspaceService(environmentService, uriLabelService);
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
instantiationService.stub(IEnvironmentService, environmentService);
@ -936,7 +941,8 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
parentResource = parentDir;
environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, path.join(parentDir, 'settings.json'));
const workspaceService = new WorkspaceService(environmentService);
const uriLabelService = new UriLabelService(environmentService);
const workspaceService = new WorkspaceService(environmentService, uriLabelService);
const instantiationService = <TestInstantiationService>workbenchInstantiationService();
instantiationService.stub(IWorkspaceContextService, workspaceService);

View file

@ -21,7 +21,7 @@ import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService, TestContextService } from 'vs/workbench/test/workbenchTestServices';
import { TestFileService, TestEditorService, TestEditorGroupsService, TestEnvironmentService } from 'vs/workbench/test/workbenchTestServices';
import { TPromise } from 'vs/base/common/winjs.base';
import { ResourceTextEdit } from 'vs/editor/common/modes';
import { BulkEditService } from 'vs/workbench/services/bulkEdit/electron-browser/bulkEditService';
@ -84,7 +84,7 @@ suite('MainThreadEditors', () => {
}
};
const bulkEditService = new BulkEditService(new NullLogService(), modelService, new TestEditorService(), textModelService, new TestFileService(), textFileService, new UriLabelService(TestEnvironmentService, new TestContextService()));
const bulkEditService = new BulkEditService(new NullLogService(), modelService, new TestEditorService(), textModelService, new TestFileService(), textFileService, new UriLabelService(TestEnvironmentService));
const rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {

View file

@ -271,7 +271,7 @@ export function workbenchInstantiationService(): IInstantiationService {
instantiationService.stub(IHashService, new TestHashService());
instantiationService.stub(ILogService, new TestLogService());
instantiationService.stub(IEditorGroupsService, new TestEditorGroupsService([new TestEditorGroup(0)]));
instantiationService.stub(IUriLabelService, new UriLabelService(TestEnvironmentService, workspaceContextService));
instantiationService.stub(IUriLabelService, new UriLabelService(TestEnvironmentService));
const editorService = new TestEditorService();
instantiationService.stub(IEditorService, editorService);
instantiationService.stub(ICodeEditorService, new TestCodeEditorService());