mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
adopt IWorkspace2, implement proper workspaceContains, #28526
This commit is contained in:
@@ -91,7 +91,7 @@ export function createApiFactory(
|
||||
const extHostTerminalService = col.define(ExtHostContext.ExtHostTerminalService).set<ExtHostTerminalService>(new ExtHostTerminalService(threadService));
|
||||
const extHostSCM = col.define(ExtHostContext.ExtHostSCM).set<ExtHostSCM>(new ExtHostSCM(threadService, extHostCommands));
|
||||
const extHostTask = col.define(ExtHostContext.ExtHostTask).set<ExtHostTask>(new ExtHostTask(threadService));
|
||||
const extHostWorkspace = col.define(ExtHostContext.ExtHostWorkspace).set<ExtHostWorkspace>(new ExtHostWorkspace(threadService, initData.workspace && [initData.workspace.resource]));
|
||||
const extHostWorkspace = col.define(ExtHostContext.ExtHostWorkspace).set<ExtHostWorkspace>(new ExtHostWorkspace(threadService, initData.workspace));
|
||||
col.define(ExtHostContext.ExtHostExtensionService).set(extensionService);
|
||||
col.finish(false, threadService);
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
|
||||
import { StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/platform/statusbar/common/statusbar';
|
||||
import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
|
||||
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { IProgressOptions, IProgressStep } from 'vs/platform/progress/common/progress';
|
||||
|
||||
import * as editorCommon from 'vs/editor/common/editorCommon';
|
||||
@@ -57,10 +56,15 @@ export interface IEnvironment {
|
||||
extensionTestsPath: string;
|
||||
}
|
||||
|
||||
export interface IWorkspaceData {
|
||||
id: string;
|
||||
roots: URI[];
|
||||
}
|
||||
|
||||
export interface IInitData {
|
||||
parentPid: number;
|
||||
environment: IEnvironment;
|
||||
workspace: IWorkspace;
|
||||
workspace: IWorkspaceData;
|
||||
extensions: IExtensionDescription[];
|
||||
configuration: IWorkspaceConfigurationValues;
|
||||
telemetryInfo: ITelemetryInfo;
|
||||
@@ -405,7 +409,7 @@ export abstract class ExtHostTreeViewsShape {
|
||||
}
|
||||
|
||||
export abstract class ExtHostWorkspaceShape {
|
||||
$acceptWorkspaceData(folders: URI[]): void { throw ni(); }
|
||||
$acceptWorkspaceData(workspace: IWorkspaceData): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostExtensionServiceShape {
|
||||
|
||||
@@ -15,8 +15,7 @@ import { ExtHostStorage } from 'vs/workbench/api/node/extHostStorage';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { createApiFactory, initializeExtensionApi } from 'vs/workbench/api/node/extHost.api.impl';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { MainContext, MainProcessExtensionServiceShape, IEnvironment, IInitData } from './extHost.protocol';
|
||||
import { MainContext, MainProcessExtensionServiceShape, IWorkspaceData, IEnvironment, IInitData } from './extHost.protocol';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
const hasOwnProperty = Object.hasOwnProperty;
|
||||
@@ -103,13 +102,13 @@ class ExtensionMemento implements IExtensionMemento {
|
||||
|
||||
class ExtensionStoragePath {
|
||||
|
||||
private readonly _workspace: IWorkspace;
|
||||
private readonly _workspace: IWorkspaceData;
|
||||
private readonly _environment: IEnvironment;
|
||||
|
||||
private readonly _ready: TPromise<string>;
|
||||
private _value: string;
|
||||
|
||||
constructor(workspace: IWorkspace, environment: IEnvironment) {
|
||||
constructor(workspace: IWorkspaceData, environment: IEnvironment) {
|
||||
this._workspace = workspace;
|
||||
this._environment = environment;
|
||||
this._ready = this._getOrCreateWorkspaceStoragePath().then(value => this._value = value);
|
||||
@@ -130,10 +129,10 @@ class ExtensionStoragePath {
|
||||
if (!this._workspace) {
|
||||
return TPromise.as(undefined);
|
||||
}
|
||||
|
||||
// TODO@joh what to do with multiple roots?
|
||||
const storageName = createHash('md5')
|
||||
.update(this._workspace.resource.fsPath)
|
||||
.update(this._workspace.uid ? this._workspace.uid.toString() : '')
|
||||
.update(this._workspace.roots[0].fsPath)
|
||||
.update(this._workspace.id || '')
|
||||
.digest('hex');
|
||||
|
||||
const storagePath = join(this._environment.appSettingsHome, 'workspaceStorage', storageName);
|
||||
|
||||
@@ -12,7 +12,7 @@ import { IThreadService } from 'vs/workbench/services/thread/common/threadServic
|
||||
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { fromRange, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { ExtHostWorkspaceShape, MainContext, MainThreadWorkspaceShape } from './extHost.protocol';
|
||||
import { IWorkspaceData, ExtHostWorkspaceShape, MainContext, MainThreadWorkspaceShape } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
@@ -20,18 +20,19 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
private static _requestIdPool = 0;
|
||||
|
||||
private readonly _proxy: MainThreadWorkspaceShape;
|
||||
private _workspaceFolders: URI[];
|
||||
private _workspace: IWorkspaceData;
|
||||
|
||||
constructor(threadService: IThreadService, folders: URI[]) {
|
||||
constructor(threadService: IThreadService, workspace: IWorkspaceData) {
|
||||
super();
|
||||
this._proxy = threadService.get(MainContext.MainThreadWorkspace);
|
||||
this._workspaceFolders = folders;
|
||||
this._workspace = workspace;
|
||||
}
|
||||
|
||||
// --- workspace ---
|
||||
|
||||
getPath(): string {
|
||||
return isFalsyOrEmpty(this._workspaceFolders) ? undefined : this._workspaceFolders[0].fsPath;
|
||||
// TODO@Joh handle roots.length > 1 case
|
||||
return this._workspace ? this._workspace.roots[0].fsPath : undefined;
|
||||
}
|
||||
|
||||
getRelativePath(pathOrUri: string | vscode.Uri): string {
|
||||
@@ -47,11 +48,11 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
return path;
|
||||
}
|
||||
|
||||
if (isFalsyOrEmpty(this._workspaceFolders)) {
|
||||
if (!this._workspace || isFalsyOrEmpty(this._workspace.roots)) {
|
||||
return normalize(path);
|
||||
}
|
||||
|
||||
for (const { fsPath } of this._workspaceFolders) {
|
||||
for (const { fsPath } of this._workspace.roots) {
|
||||
let result = relative(fsPath, path);
|
||||
if (!result || result.indexOf('..') === 0) {
|
||||
continue;
|
||||
@@ -62,9 +63,9 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
return normalize(path);
|
||||
}
|
||||
|
||||
$acceptWorkspaceData(workspaceFolders: URI[]): void {
|
||||
$acceptWorkspaceData(workspace: IWorkspaceData): void {
|
||||
//TODO@joh equality-check, emit event etc.
|
||||
this._workspaceFolders = workspaceFolders;
|
||||
this._workspace = workspace;
|
||||
}
|
||||
|
||||
// --- search ---
|
||||
|
||||
Reference in New Issue
Block a user