getOptions()/updateOptions() only in workbench

This commit is contained in:
Benjamin Pasero 2016-08-18 14:39:17 +02:00
parent 5b2d612db3
commit 686646039b
12 changed files with 67 additions and 85 deletions

View file

@ -28,8 +28,7 @@ import {IMessageService} from 'vs/platform/message/common/message';
import {IProgressService} from 'vs/platform/progress/common/progress';
import {IStorageService, NullStorageService} from 'vs/platform/storage/common/storage';
import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspaceContextService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService, BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
import {IEditorWorkerService} from 'vs/editor/common/services/editorWorkerService';
import {EditorWorkerServiceImpl} from 'vs/editor/common/services/editorWorkerServiceImpl';
@ -244,7 +243,7 @@ export function getOrCreateStaticServices(services?: IEditorOverrideServices): I
name: null,
uid: null,
mtime: null
}, {});
});
serviceCollection.set(IWorkspaceContextService, contextService);
let telemetryService = services.telemetryService || NullTelemetryService;

View file

@ -6,6 +6,7 @@
import URI from 'vs/base/common/uri';
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
import paths = require('vs/base/common/paths');
export const IWorkspaceContextService = createDecorator<IWorkspaceContextService>('contextService');
@ -18,11 +19,6 @@ export interface IWorkspaceContextService {
*/
getWorkspace(): IWorkspace;
/**
* Provides access to the options object the platform is running with.
*/
getOptions(): any;
/**
* Returns iff the provided resource is inside the workspace or not.
*/
@ -70,4 +66,47 @@ export interface IWorkspace {
* is just derived from the workspace name.
*/
uid?: number;
}
/**
* Simple IWorkspaceContextService implementation to allow sharing of this service implementation
* between different layers of the platform.
*/
export class BaseWorkspaceContextService implements IWorkspaceContextService {
public _serviceBrand: any;
private workspace: IWorkspace;
constructor(workspace: IWorkspace) {
this.workspace = workspace;
}
public getWorkspace(): IWorkspace {
return this.workspace;
}
public isInsideWorkspace(resource: URI): boolean {
if (resource && this.workspace) {
return paths.isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath);
}
return false;
}
public toWorkspaceRelativePath(resource: URI): string {
if (this.isInsideWorkspace(resource)) {
return paths.normalize(paths.relative(this.workspace.resource.fsPath, resource.fsPath));
}
return null;
}
public toResource(workspaceRelativePath: string): URI {
if (typeof workspaceRelativePath === 'string' && this.workspace) {
return URI.file(paths.join(this.workspace.resource.fsPath, workspaceRelativePath));
}
return null;
}
}

View file

@ -1,59 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import URI from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
import {IWorkspaceContextService, IWorkspace} from 'vs/platform/workspace/common/workspace';
/**
* Simple IWorkspaceContextService implementation to allow sharing of this service implementation
* between different layers of the platform.
*/
export class BaseWorkspaceContextService implements IWorkspaceContextService {
public _serviceBrand: any;
protected options: any;
private workspace: IWorkspace;
constructor(workspace: IWorkspace, options: any = {}) {
this.workspace = workspace;
this.options = options;
}
public getWorkspace(): IWorkspace {
return this.workspace;
}
public getOptions(): any {
return this.options;
}
public isInsideWorkspace(resource: URI): boolean {
if (resource && this.workspace) {
return paths.isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath);
}
return false;
}
public toWorkspaceRelativePath(resource: URI): string {
if (this.isInsideWorkspace(resource)) {
return paths.normalize(paths.relative(this.workspace.resource.fsPath, resource.fsPath));
}
return null;
}
public toResource(workspaceRelativePath: string): URI {
if (typeof workspaceRelativePath === 'string' && this.workspace) {
return URI.file(paths.join(this.workspace.resource.fsPath, workspaceRelativePath));
}
return null;
}
}

View file

@ -18,7 +18,7 @@ import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput';
import nls = require('vs/nls');
import {IMessageService, Severity} from 'vs/platform/message/common/message';
import {IWindowConfiguration} from 'vs/workbench/electron-browser/window';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {IQuickOpenService, IPickOpenEntry} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {KeyMod} from 'vs/base/common/keyCodes';

View file

@ -21,9 +21,8 @@ import {IMainProcessExtHostIPC} from 'vs/platform/extensions/common/ipcRemoteCom
import {ExtHostExtensionService} from 'vs/workbench/api/node/extHostExtensionService';
import {ExtHostThreadService} from 'vs/workbench/services/thread/common/extHostThreadService';
import {RemoteTelemetryService} from 'vs/workbench/api/node/extHostTelemetry';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspaceContextService';
import {ExtensionScanner, MessagesCollector} from 'vs/workbench/node/extensionPoints';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService, BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {Client} from 'vs/base/parts/ipc/node/ipc.net';
import {IExtensionManagementChannel, ExtensionManagementChannelClient} from 'vs/platform/extensionManagement/common/extensionManagementIpc';
@ -73,7 +72,7 @@ export class ExtensionHostMain {
this._environment = initData.environment;
this._contextService = new BaseWorkspaceContextService(initData.contextService.workspace, initData.contextService.options);
this._contextService = new BaseWorkspaceContextService(initData.contextService.workspace);
const workspaceStoragePath = this._getOrCreateWorkspaceStoragePath();
const threadService = new ExtHostThreadService(remoteCom);

View file

@ -28,6 +28,8 @@ export class ConfigurationService extends CommonConfigurationService {
public _serviceBrand: any;
protected contextService: IWorkspaceContextService;
private toDispose: IDisposable;
constructor(

View file

@ -21,7 +21,7 @@ import {IContextKeyService} from 'vs/platform/contextkey/common/contextkey';
import {IKeybindingRule, KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {Registry} from 'vs/platform/platform';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {EventType, OptionsChangeEvent} from 'vs/workbench/common/events';
import {getNativeLabelProvider, getNativeAriaLabelProvider} from 'vs/workbench/services/keybinding/electron-browser/nativeKeymap';
import {IMessageService} from 'vs/platform/message/common/message';

View file

@ -176,9 +176,8 @@ class ExtensionHostProcessManager {
extensionTestsPath: this.environmentService.extensionTestsPath
},
contextService: {
workspace: this.contextService.getWorkspace(),
options: this.contextService.getOptions()
},
workspace: this.contextService.getWorkspace()
}
});
this.extensionHostProcessHandle.send(initPayload);

View file

@ -8,8 +8,7 @@ import {IOptions} from 'vs/workbench/common/options';
import {EventType, OptionsChangeEvent} from 'vs/workbench/common/events';
import {IEventService} from 'vs/platform/event/common/event';
import {createDecorator} from 'vs/platform/instantiation/common/instantiation';
import {IWorkspace, IWorkspaceContextService as IBaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspaceContextService';
import {IWorkspace, IWorkspaceContextService as IBaseWorkspaceContextService, BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
export const IWorkspaceContextService = createDecorator<IWorkspaceContextService>('contextService');
@ -28,14 +27,19 @@ export interface IWorkspaceContextService extends IBaseWorkspaceContextService {
}
export class WorkspaceContextService extends BaseWorkspaceContextService implements IWorkspaceContextService {
public _serviceBrand: any;
constructor(
private eventService: IEventService,
workspace: IWorkspace,
options: any = {}
private options: IOptions
) {
super(workspace, options);
super(workspace);
}
public getOptions(): IOptions {
return this.options;
}
public updateOptions(key: string, value: any): void {

View file

@ -10,8 +10,7 @@ import {Build, Builder} from 'vs/base/browser/builder';
import {Part} from 'vs/workbench/browser/part';
import * as Types from 'vs/base/common/types';
import * as TestUtils from 'vs/test/utils/servicesTestUtils';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspaceContextService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService, BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IStorageService} from 'vs/platform/storage/common/storage';
import {Storage, InMemoryLocalStorage} from 'vs/workbench/common/storage';
@ -105,7 +104,7 @@ suite('Workbench Part', () => {
fixture = document.createElement('div');
fixture.id = fixtureId;
document.body.appendChild(fixture);
context = new BaseWorkspaceContextService(TestUtils.TestWorkspace, null);
context = new BaseWorkspaceContextService(TestUtils.TestWorkspace);
storage = new Storage(new InMemoryLocalStorage(), null, context);
});

View file

@ -7,7 +7,7 @@
import 'vs/workbench/parts/search/browser/search.contribution'; // load contributions
import * as assert from 'assert';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspaceContextService';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {createSyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
import {ensureStaticPlatformServices, IEditorOverrideServices} from 'vs/editor/browser/standalone/standaloneServices';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';

View file

@ -6,7 +6,7 @@
'use strict';
import * as assert from 'assert';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspaceContextService';
import {BaseWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {StorageScope} from 'vs/platform/storage/common/storage';
import * as TestUtils from 'vs/test/utils/servicesTestUtils';
import {Memento, Scope} from 'vs/workbench/common/memento';
@ -17,7 +17,7 @@ suite('Workbench Memento', () => {
let storage;
setup(() => {
context = new BaseWorkspaceContextService(TestUtils.TestWorkspace, null);
context = new BaseWorkspaceContextService(TestUtils.TestWorkspace);
storage = new Storage(new InMemoryLocalStorage(), null, context);
});