提交 9754a210 编写于 作者: B Benjamin Pasero

Revert "extract more functionality into IWorkspace"

This reverts commit 25b4b172.
上级 7a927e30
......@@ -22,7 +22,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 } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService, WorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService, WorkspaceContextService } 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';
......@@ -115,9 +115,9 @@ export module StaticServices {
export const instantiationService = define<IInstantiationService>(IInstantiationService, () => new InstantiationService(_serviceCollection, true));
export const contextService = define(IWorkspaceContextService, () => new WorkspaceContextService(new Workspace(
URI.from({ scheme: 'inmemory', authority: 'model', path: '/' })
)));
export const contextService = define(IWorkspaceContextService, () => new WorkspaceContextService({
resource: URI.from({ scheme: 'inmemory', authority: 'model', path: '/' })
}));
export const telemetryService = define(ITelemetryService, () => new StandaloneTelemetryService());
......
......@@ -65,26 +65,27 @@ export interface IWorkspace {
name?: string;
}
export class Workspace implements IWorkspace {
export class WorkspaceContextService implements IWorkspaceContextService {
constructor(private _resource: URI, private _uid?: number, private _name?: string) {
}
public _serviceBrand: any;
public get resource(): URI {
return this._resource;
private workspace: IWorkspace;
constructor(workspace: IWorkspace) {
this.workspace = workspace;
}
public get uid(): number {
return this._uid;
public getWorkspace(): IWorkspace {
return this.workspace;
}
public get name(): string {
return this._name;
public hasWorkspace(): boolean {
return !!this.workspace;
}
public isInsideWorkspace(resource: URI): boolean {
if (resource) {
return isEqualOrParent(resource.fsPath, this._resource.fsPath, !isLinux /* ignorecase */);
if (resource && this.workspace) {
return isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath, !isLinux /* ignorecase */);
}
return false;
......@@ -92,48 +93,17 @@ export class Workspace implements IWorkspace {
public toWorkspaceRelativePath(resource: URI, toOSPath?: boolean): string {
if (this.isInsideWorkspace(resource)) {
return paths.normalize(paths.relative(this._resource.fsPath, resource.fsPath), toOSPath);
return paths.normalize(paths.relative(this.workspace.resource.fsPath, resource.fsPath), toOSPath);
}
return null;
}
public toResource(workspaceRelativePath: string): URI {
if (typeof workspaceRelativePath === 'string') {
return URI.file(paths.join(this._resource.fsPath, workspaceRelativePath));
if (typeof workspaceRelativePath === 'string' && this.workspace) {
return URI.file(paths.join(this.workspace.resource.fsPath, workspaceRelativePath));
}
return null;
}
}
export class WorkspaceContextService implements IWorkspaceContextService {
public _serviceBrand: any;
private workspace: Workspace;
constructor(workspace?: Workspace) {
this.workspace = workspace;
}
public getWorkspace(): IWorkspace {
return this.workspace;
}
public hasWorkspace(): boolean {
return !!this.workspace;
}
public isInsideWorkspace(resource: URI): boolean {
return this.workspace ? this.workspace.isInsideWorkspace(resource) : false;
}
public toWorkspaceRelativePath(resource: URI, toOSPath?: boolean): string {
return this.workspace ? this.workspace.toWorkspaceRelativePath(resource, toOSPath) : null;
}
public toResource(workspaceRelativePath: string): URI {
return this.workspace ? this.workspace.toResource(workspaceRelativePath) : null;
}
}
\ No newline at end of file
......@@ -3,11 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Workspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
import URI from 'vs/base/common/uri';
export const TestWorkspace = new Workspace(
URI.file('C:\\testWorkspace'),
Date.now(),
'Test Workspace'
);
export const TestWorkspace: IWorkspace = {
resource: URI.file('C:\\testWorkspace'),
name: 'Test Workspace',
uid: Date.now()
};
......@@ -18,7 +18,7 @@ import paths = require('vs/base/common/paths');
import uri from 'vs/base/common/uri';
import strings = require('vs/base/common/strings');
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { WorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspace, WorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { WorkspaceConfigurationService } from 'vs/workbench/services/configuration/node/configurationService';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
import { realpath, stat } from 'vs/base/node/pfs';
......@@ -116,7 +116,7 @@ function toInputs(paths: IPath[], isUntitledFile?: boolean): IResourceInput[] {
});
}
function getWorkspace(workspacePath: string): TPromise<Workspace> {
function getWorkspace(workspacePath: string): TPromise<IWorkspace> {
if (!workspacePath) {
return TPromise.as(null);
}
......@@ -135,23 +135,23 @@ function getWorkspace(workspacePath: string): TPromise<Workspace> {
const folderName = path.basename(realWorkspacePath) || realWorkspacePath;
return stat(realWorkspacePath).then(folderStat => {
return new Workspace(
workspaceResource,
platform.isLinux ? folderStat.ino : folderStat.birthtime.getTime(),
folderName // On Linux, birthtime is ctime, so we cannot use it! We use the ino instead!
);
return <IWorkspace>{
'resource': workspaceResource,
'name': folderName,
'uid': platform.isLinux ? folderStat.ino : folderStat.birthtime.getTime() // On Linux, birthtime is ctime, so we cannot use it! We use the ino instead!
};
});
}, error => {
}, (error) => {
errors.onUnexpectedError(error);
return null; // treat invalid paths as empty workspace
});
}
function openWorkbench(environment: IWindowConfiguration, workspace: Workspace, options: IOptions): TPromise<void> {
function openWorkbench(environment: IWindowConfiguration, workspace: IWorkspace, options: IOptions): TPromise<void> {
const environmentService = new EnvironmentService(environment, environment.execPath);
const contextService = new WorkspaceContextService(workspace);
const configurationService = new WorkspaceConfigurationService(environmentService, workspace);
const configurationService = new WorkspaceConfigurationService(contextService, environmentService);
const timerService = new TimerService((<any>window).MonacoEnvironment.timers as IInitData, !contextService.hasWorkspace());
// Since the configuration service is one of the core services that is used in so many places, we initialize it
......
......@@ -15,7 +15,7 @@ import { ExtHostThreadService } from 'vs/workbench/services/thread/common/extHos
import { QueryType, ISearchQuery } from 'vs/platform/search/common/search';
import { DiskSearch } from 'vs/workbench/services/search/node/searchService';
import { RemoteTelemetryService } from 'vs/workbench/api/node/extHostTelemetry';
import { IWorkspaceContextService, WorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceContextService, WorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IInitData, IEnvironment, MainContext } from 'vs/workbench/api/node/extHost.protocol';
import * as errors from 'vs/base/common/errors';
......@@ -43,14 +43,7 @@ export class ExtensionHostMain {
constructor(remoteCom: IRemoteCom, initData: IInitData) {
// services
this._environment = initData.environment;
const workspaceRaw = initData.contextService.workspace;
let workspace: Workspace;
if (workspaceRaw) {
workspace = new Workspace(workspaceRaw.resource, workspaceRaw.uid, workspaceRaw.name);
}
this._contextService = new WorkspaceContextService(workspace);
this._contextService = new WorkspaceContextService(initData.contextService.workspace);
const threadService = new ExtHostThreadService(remoteCom);
const telemetryService = new RemoteTelemetryService('pluginHostTelemetry', threadService);
this._extensionService = new ExtHostExtensionService(initData, threadService, telemetryService, this._contextService);
......
......@@ -8,7 +8,7 @@
import * as assert from 'assert';
import { Platform } from 'vs/base/common/platform';
import { TerminalLinkHandler, LineColumnInfo } from 'vs/workbench/parts/terminal/electron-browser/terminalLinkHandler';
import { WorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { IWorkspace, WorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import URI from 'vs/base/common/uri';
import * as strings from 'vs/base/common/strings';
import * as path from 'path';
......@@ -44,9 +44,10 @@ interface LinkFormatInfo {
column?: string;
}
class TestWorkspace extends Workspace {
constructor(private basePath: string) {
super(new TestURI(basePath));
class TestWorkspace implements IWorkspace {
resource: URI;
constructor(basePath: string) {
this.resource = new TestURI(basePath);
}
}
......
......@@ -12,6 +12,7 @@ import extfs = require('vs/base/node/extfs');
import objects = require('vs/base/common/objects');
import { RunOnceScheduler } from 'vs/base/common/async';
import collections = require('vs/base/common/collections');
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { readFile } from 'vs/base/node/pfs';
......@@ -23,7 +24,7 @@ import { ConfigurationService as BaseConfigurationService } from 'vs/platform/co
import { IWorkspaceConfigurationValues, IWorkspaceConfigurationService, IWorkspaceConfigurationValue, WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME, WORKSPACE_STANDALONE_CONFIGURATIONS, WORKSPACE_CONFIG_DEFAULT_PATH } from 'vs/workbench/services/configuration/common/configuration';
import { FileChangeType, FileChangesEvent, isEqual } from 'vs/platform/files/common/files';
import Event, { Emitter } from 'vs/base/common/event';
import { Workspace } from "vs/platform/workspace/common/workspace";
interface IStat {
resource: uri;
......@@ -61,8 +62,8 @@ export class WorkspaceConfigurationService extends Disposable implements IWorksp
private reloadConfigurationScheduler: RunOnceScheduler;
constructor(
private environmentService: IEnvironmentService,
private workspace?: Workspace,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
private workspaceSettingsRootFolder: string = WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME
) {
super();
......@@ -215,13 +216,13 @@ export class WorkspaceConfigurationService extends Disposable implements IWorksp
private loadWorkspaceConfigFiles<T>(): TPromise<{ [relativeWorkspacePath: string]: IConfigModel<T> }> {
// Return early if we don't have a workspace
if (!this.workspace) {
if (!this.contextService.hasWorkspace()) {
return TPromise.as(Object.create(null));
}
// once: when invoked for the first time we fetch json files that contribute settings
if (!this.bulkFetchFromWorkspacePromise) {
this.bulkFetchFromWorkspacePromise = resolveStat(this.workspace.toResource(this.workspaceSettingsRootFolder)).then(stat => {
this.bulkFetchFromWorkspacePromise = resolveStat(this.contextService.toResource(this.workspaceSettingsRootFolder)).then(stat => {
if (!stat.isDirectory) {
return TPromise.as([]);
}
......@@ -232,11 +233,11 @@ export class WorkspaceConfigurationService extends Disposable implements IWorksp
return false; // only JSON files
}
return this.isWorkspaceConfigurationFile(this.workspace.toWorkspaceRelativePath(stat.resource)); // only workspace config files
return this.isWorkspaceConfigurationFile(this.contextService.toWorkspaceRelativePath(stat.resource)); // only workspace config files
}).map(stat => stat.resource));
}, err => [] /* never fail this call */)
.then((contents: IContent[]) => {
contents.forEach(content => this.workspaceFilePathToConfiguration[this.workspace.toWorkspaceRelativePath(content.resource)] = TPromise.as(this.createConfigModel(content)));
contents.forEach(content => this.workspaceFilePathToConfiguration[this.contextService.toWorkspaceRelativePath(content.resource)] = TPromise.as(this.createConfigModel(content)));
}, errors.onUnexpectedError);
}
......@@ -258,7 +259,7 @@ export class WorkspaceConfigurationService extends Disposable implements IWorksp
continue; // only JSON files or the actual settings folder
}
const workspacePath = this.workspace.toWorkspaceRelativePath(resource);
const workspacePath = this.contextService.toWorkspaceRelativePath(resource);
if (!workspacePath) {
continue; // event is not inside workspace
}
......@@ -294,7 +295,7 @@ export class WorkspaceConfigurationService extends Disposable implements IWorksp
}
private createConfigModel<T>(content: IContent): IConfigModel<T> {
const path = this.workspace.toWorkspaceRelativePath(content.resource);
const path = this.contextService.toWorkspaceRelativePath(content.resource);
if (path === WORKSPACE_CONFIG_DEFAULT_PATH) {
return new WorkspaceSettingsConfigModel<T>(content.value, content.resource.toString());
} else {
......
......@@ -15,7 +15,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Registry } from 'vs/platform/platform';
import { ParsedArgs, IEnvironmentService } from 'vs/platform/environment/common/environment';
import { parseArgs } from 'vs/platform/environment/node/argv';
import { WorkspaceContextService, IWorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { WorkspaceContextService, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import extfs = require('vs/base/node/extfs');
import { TestTextFileService, TestEditorGroupService, TestLifecycleService, TestBackupFileService } from 'vs/workbench/test/workbenchTestServices';
......@@ -113,11 +113,9 @@ suite('ConfigurationEditingService', () => {
clearServices();
instantiationService = new TestInstantiationService();
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
instantiationService.stub(IEnvironmentService, environmentService);
const workspace = noWorkspace ? null : new Workspace(URI.file(workspaceDir));
instantiationService.stub(IWorkspaceContextService, new WorkspaceContextService(workspace));
const configurationService = new WorkspaceConfigurationService(environmentService, workspace);
instantiationService.stub(IEnvironmentService, new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile));
instantiationService.stub(IWorkspaceContextService, new WorkspaceContextService(noWorkspace ? null : { resource: URI.file(workspaceDir) }));
const configurationService = instantiationService.createInstance(WorkspaceConfigurationService);
instantiationService.stub(IConfigurationService, configurationService);
instantiationService.stub(ILifecycleService, new TestLifecycleService());
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
......
......@@ -13,7 +13,7 @@ import * as sinon from 'sinon';
import { TPromise } from 'vs/base/common/winjs.base';
import { Registry } from 'vs/platform/platform';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
import { Workspace } from 'vs/platform/workspace/common/workspace';
import { WorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { parseArgs } from 'vs/platform/environment/node/argv';
import extfs = require('vs/base/node/extfs');
......@@ -47,9 +47,9 @@ suite('WorkspaceConfigurationService - Node', () => {
}
function createService(workspaceDir: string, globalSettingsFile: string): TPromise<WorkspaceConfigurationService> {
const workspace = new Workspace(URI.file(workspaceDir));
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const service = new WorkspaceConfigurationService(environmentService, workspace);
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
return service.initialize().then(() => service);
}
......@@ -204,9 +204,9 @@ suite('WorkspaceConfigurationService - Node', () => {
test('workspace change triggers event', (done: () => void) => {
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
const workspace = new Workspace(URI.file(workspaceDir));
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const service = new WorkspaceConfigurationService(environmentService, workspace);
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
return service.initialize().then(() => {
service.onDidUpdateConfiguration(event => {
......@@ -230,9 +230,9 @@ suite('WorkspaceConfigurationService - Node', () => {
test('workspace reload should triggers event if content changed', (done: () => void) => {
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
const workspace = new Workspace(URI.file(workspaceDir));
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const service = new WorkspaceConfigurationService(environmentService, workspace);
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
return service.initialize().then(() => {
const settingsFile = path.join(workspaceDir, '.vscode', 'settings.json');
......@@ -255,9 +255,9 @@ suite('WorkspaceConfigurationService - Node', () => {
test('workspace reload should not trigger event if nothing changed', (done: () => void) => {
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
const workspace = new Workspace(URI.file(workspaceDir));
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const service = new WorkspaceConfigurationService(environmentService, workspace);
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
return service.initialize().then(() => {
const settingsFile = path.join(workspaceDir, '.vscode', 'settings.json');
......@@ -280,9 +280,9 @@ suite('WorkspaceConfigurationService - Node', () => {
test('workspace reload should not trigger event if there is no model', (done: () => void) => {
createWorkspace((workspaceDir, globalSettingsFile, cleanUp) => {
const workspace = new Workspace(URI.file(workspaceDir));
const workspaceContextService = new WorkspaceContextService({ resource: URI.file(workspaceDir) });
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const service = new WorkspaceConfigurationService(environmentService, workspace);
const service = new WorkspaceConfigurationService(workspaceContextService, environmentService);
return service.initialize().then(() => {
const target = sinon.stub();
......
......@@ -7,7 +7,7 @@
import 'vs/workbench/parts/search/browser/search.contribution'; // load contributions
import * as assert from 'assert';
import { WorkspaceContextService, IWorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { WorkspaceContextService, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ISearchService } from 'vs/platform/search/common/search';
......@@ -73,7 +73,7 @@ suite('QuickOpen performance (integration)', () => {
[ITelemetryService, telemetryService],
[IConfigurationService, new SimpleConfigurationService()],
[IModelService, new ModelServiceImpl(null, configurationService)],
[IWorkspaceContextService, new WorkspaceContextService(new Workspace(URI.file(testWorkspacePath)))],
[IWorkspaceContextService, new WorkspaceContextService({ resource: URI.file(testWorkspacePath) })],
[IWorkbenchEditorService, new TestEditorService()],
[IEditorGroupService, new TestEditorGroupService()],
[IEnvironmentService, TestEnvironmentService],
......
......@@ -8,7 +8,7 @@
import 'vs/workbench/parts/search/browser/search.contribution'; // load contributions
import * as assert from 'assert';
import * as fs from 'fs';
import { WorkspaceContextService, IWorkspaceContextService, Workspace } from 'vs/platform/workspace/common/workspace';
import { WorkspaceContextService, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ISearchService, IQueryOptions } from 'vs/platform/search/common/search';
......@@ -62,7 +62,7 @@ suite('TextSearch performance (integration)', () => {
[ITelemetryService, telemetryService],
[IConfigurationService, new SimpleConfigurationService()],
[IModelService, new ModelServiceImpl(null, configurationService)],
[IWorkspaceContextService, new WorkspaceContextService(new Workspace(URI.file(testWorkspacePath)))],
[IWorkspaceContextService, new WorkspaceContextService({ resource: URI.file(testWorkspacePath) })],
[IWorkbenchEditorService, new TestEditorService()],
[IEditorGroupService, new TestEditorGroupService()],
[IEnvironmentService, TestEnvironmentService],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册