mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
Merge branch 'master' into joh/remote
This commit is contained in:
@@ -35,6 +35,7 @@ import { ExtHostLanguageFeatures } from 'vs/workbench/api/node/extHostLanguageFe
|
||||
import { ExtHostApiCommands } from 'vs/workbench/api/node/extHostApiCommands';
|
||||
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
|
||||
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
|
||||
import { ExtHostCredentials } from 'vs/workbench/api/node/extHostCredentials';
|
||||
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
@@ -55,12 +56,6 @@ export interface IExtensionApiFactory {
|
||||
(extension: IExtensionDescription): typeof vscode;
|
||||
}
|
||||
|
||||
function assertProposedApi(extension: IExtensionDescription): void {
|
||||
if (!extension.enableProposedApi) {
|
||||
throw new Error(`[${extension.id}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${extension.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
function proposedApiFunction<T>(extension: IExtensionDescription, fn: T): T {
|
||||
if (extension.enableProposedApi) {
|
||||
return fn;
|
||||
@@ -100,6 +95,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 extHostCredentials = col.define(ExtHostContext.ExtHostCredentials).set<ExtHostCredentials>(new ExtHostCredentials(threadService));
|
||||
col.define(ExtHostContext.ExtHostExtensionService).set(extensionService);
|
||||
col.finish(false, threadService);
|
||||
|
||||
@@ -367,20 +363,17 @@ export function createApiFactory(
|
||||
set rootPath(value) {
|
||||
throw errors.readonly();
|
||||
},
|
||||
getContainingWorkspaceFolder(resource) {
|
||||
return extHostWorkspace.getEnclosingWorkspaceFolder(resource);
|
||||
getWorkspaceFolder(resource) {
|
||||
return extHostWorkspace.getWorkspaceFolder(resource);
|
||||
},
|
||||
get workspaceFolders() {
|
||||
// proposed api
|
||||
assertProposedApi(extension);
|
||||
apiUsage.publicLog('workspace#workspaceFolders');
|
||||
return extHostWorkspace.getWorkspaceFolders();
|
||||
},
|
||||
onDidChangeWorkspaceFolders: proposedApiFunction(extension, (listener, thisArgs?, disposables?) => {
|
||||
// proposed api
|
||||
onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
|
||||
apiUsage.publicLog('workspace#onDidChangeWorkspaceFolders');
|
||||
return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
|
||||
}),
|
||||
},
|
||||
asRelativePath: (pathOrUri) => {
|
||||
return extHostWorkspace.getRelativePath(pathOrUri);
|
||||
},
|
||||
@@ -479,8 +472,14 @@ export function createApiFactory(
|
||||
get activeDebugSession() {
|
||||
return extHostDebugService.activeDebugSession;
|
||||
},
|
||||
createDebugSession(config: vscode.DebugConfiguration) {
|
||||
return extHostDebugService.createDebugSession(config);
|
||||
startDebugging: proposedApiFunction(extension, (nameOrConfig: string | vscode.DebugConfiguration) => {
|
||||
return extHostDebugService.startDebugging(nameOrConfig);
|
||||
}),
|
||||
startDebugSession(config: vscode.DebugConfiguration) {
|
||||
return extHostDebugService.startDebugSession(config);
|
||||
},
|
||||
onDidStartDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
|
||||
},
|
||||
onDidTerminateDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
|
||||
@@ -493,6 +492,19 @@ export function createApiFactory(
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: credentials
|
||||
const credentials: typeof vscode.credentials = {
|
||||
readSecret(service: string, account: string): Thenable<string | undefined> {
|
||||
return extHostCredentials.readSecret(service, account);
|
||||
},
|
||||
writeSecret(service: string, account: string, secret: string): Thenable<void> {
|
||||
return extHostCredentials.writeSecret(service, account, secret);
|
||||
},
|
||||
deleteSecret(service: string, account: string): Thenable<boolean> {
|
||||
return extHostCredentials.deleteSecret(service, account);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
version: pkg.version,
|
||||
@@ -505,6 +517,11 @@ export function createApiFactory(
|
||||
workspace,
|
||||
scm,
|
||||
debug,
|
||||
get credentials() {
|
||||
return proposedApiFunction(extension, () => {
|
||||
return credentials;
|
||||
})();
|
||||
},
|
||||
// types
|
||||
CancellationTokenSource: CancellationTokenSource,
|
||||
CodeLens: extHostTypes.CodeLens,
|
||||
@@ -540,7 +557,7 @@ export function createApiFactory(
|
||||
TextEditorRevealType: extHostTypes.TextEditorRevealType,
|
||||
TextEditorSelectionChangeKind: extHostTypes.TextEditorSelectionChangeKind,
|
||||
DecorationRangeBehavior: extHostTypes.DecorationRangeBehavior,
|
||||
Uri: URI,
|
||||
Uri: <any>URI,
|
||||
ViewColumn: extHostTypes.ViewColumn,
|
||||
WorkspaceEdit: extHostTypes.WorkspaceEdit,
|
||||
ProgressLocation: extHostTypes.ProgressLocation,
|
||||
|
||||
@@ -262,7 +262,6 @@ export abstract class MainThreadTerminalServiceShape {
|
||||
$hide(terminalId: number): void { throw ni(); }
|
||||
$sendText(terminalId: number, text: string, addNewLine: boolean): void { throw ni(); }
|
||||
$show(terminalId: number, preserveFocus: boolean): void { throw ni(); }
|
||||
$registerOnData(terminalId: number): void { throw ni(); }
|
||||
}
|
||||
|
||||
export interface MyQuickPickItems extends IPickOpenEntry {
|
||||
@@ -348,10 +347,17 @@ export abstract class MainThreadSCMShape {
|
||||
export type DebugSessionUUID = string;
|
||||
|
||||
export abstract class MainThreadDebugServiceShape {
|
||||
$createDebugSession(config: vscode.DebugConfiguration): TPromise<DebugSessionUUID> { throw ni(); }
|
||||
$startDebugging(nameOrConfig: string | vscode.DebugConfiguration): TPromise<boolean> { throw ni(); }
|
||||
$startDebugSession(config: vscode.DebugConfiguration): TPromise<DebugSessionUUID> { throw ni(); }
|
||||
$customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): TPromise<any> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadCredentialsShape {
|
||||
$readSecret(service: string, account: string): Thenable<string | undefined> { throw ni(); }
|
||||
$writeSecret(service: string, account: string, secret: string): Thenable<void> { throw ni(); }
|
||||
$deleteSecret(service: string, account: string): Thenable<boolean> { throw ni(); }
|
||||
}
|
||||
|
||||
// -- extension host
|
||||
|
||||
export abstract class ExtHostCommandsShape {
|
||||
@@ -490,7 +496,6 @@ export abstract class ExtHostQuickOpenShape {
|
||||
export abstract class ExtHostTerminalServiceShape {
|
||||
$acceptTerminalClosed(id: number): void { throw ni(); }
|
||||
$acceptTerminalProcessId(id: number, processId: number): void { throw ni(); }
|
||||
$acceptTerminalData(id: number, data: string): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostSCMShape {
|
||||
@@ -505,11 +510,15 @@ export abstract class ExtHostTaskShape {
|
||||
}
|
||||
|
||||
export abstract class ExtHostDebugServiceShape {
|
||||
$acceptDebugSessionStarted(id: DebugSessionUUID, type: string, name: string): void { throw ni(); }
|
||||
$acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void { throw ni(); }
|
||||
$acceptDebugSessionActiveChanged(id: DebugSessionUUID | undefined, type?: string, name?: string): void { throw ni(); }
|
||||
$acceptDebugSessionCustomEvent(id: DebugSessionUUID, type: string, name: string, event: any): void { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class ExtHostCredentialsShape {
|
||||
}
|
||||
|
||||
// --- proxy identifiers
|
||||
|
||||
export const MainContext = {
|
||||
@@ -534,7 +543,8 @@ export const MainContext = {
|
||||
MainThreadWorkspace: createMainId<MainThreadWorkspaceShape>('MainThreadWorkspace', MainThreadWorkspaceShape),
|
||||
MainProcessExtensionService: createMainId<MainProcessExtensionServiceShape>('MainProcessExtensionService', MainProcessExtensionServiceShape),
|
||||
MainThreadSCM: createMainId<MainThreadSCMShape>('MainThreadSCM', MainThreadSCMShape),
|
||||
MainThreadTask: createMainId<MainThreadTaskShape>('MainThreadTask', MainThreadTaskShape)
|
||||
MainThreadTask: createMainId<MainThreadTaskShape>('MainThreadTask', MainThreadTaskShape),
|
||||
MainThreadCredentials: createMainId<MainThreadCredentialsShape>('MainThreadCredentials', MainThreadCredentialsShape),
|
||||
};
|
||||
|
||||
export const ExtHostContext = {
|
||||
@@ -556,4 +566,5 @@ export const ExtHostContext = {
|
||||
ExtHostSCM: createExtId<ExtHostSCMShape>('ExtHostSCM', ExtHostSCMShape),
|
||||
ExtHostTask: createExtId<ExtHostTaskShape>('ExtHostTask', ExtHostTaskShape),
|
||||
ExtHostWorkspace: createExtId<ExtHostWorkspaceShape>('ExtHostWorkspace', ExtHostWorkspaceShape),
|
||||
ExtHostCredentials: createExtId<ExtHostCredentialsShape>('ExtHostCredentials', ExtHostCredentialsShape),
|
||||
};
|
||||
|
||||
31
src/vs/workbench/api/node/extHostCredentials.ts
Normal file
31
src/vs/workbench/api/node/extHostCredentials.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { MainContext, MainThreadCredentialsShape, ExtHostCredentialsShape } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
|
||||
|
||||
export class ExtHostCredentials extends ExtHostCredentialsShape {
|
||||
|
||||
private _proxy: MainThreadCredentialsShape;
|
||||
|
||||
constructor(threadService: IThreadService) {
|
||||
super();
|
||||
this._proxy = threadService.get(MainContext.MainThreadCredentials);
|
||||
};
|
||||
|
||||
readSecret(service: string, account: string): Thenable<string | undefined> {
|
||||
return this._proxy.$readSecret(service, account);
|
||||
}
|
||||
|
||||
writeSecret(service: string, account: string, secret: string): Thenable<void> {
|
||||
return this._proxy.$writeSecret(service, account, secret);
|
||||
}
|
||||
|
||||
deleteSecret(service: string, account: string): Thenable<boolean> {
|
||||
return this._proxy.$deleteSecret(service, account);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
|
||||
private _debugServiceProxy: MainThreadDebugServiceShape;
|
||||
private _debugSessions: Map<DebugSessionUUID, ExtHostDebugSession> = new Map<DebugSessionUUID, ExtHostDebugSession>();
|
||||
|
||||
private _onDidStartDebugSession: Emitter<vscode.DebugSession>;
|
||||
get onDidStartDebugSession(): Event<vscode.DebugSession> { return this._onDidStartDebugSession.event; }
|
||||
|
||||
private _onDidTerminateDebugSession: Emitter<vscode.DebugSession>;
|
||||
get onDidTerminateDebugSession(): Event<vscode.DebugSession> { return this._onDidTerminateDebugSession.event; }
|
||||
|
||||
@@ -34,6 +37,7 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
|
||||
constructor(threadService: IThreadService) {
|
||||
super();
|
||||
|
||||
this._onDidStartDebugSession = new Emitter<vscode.DebugSession>();
|
||||
this._onDidTerminateDebugSession = new Emitter<vscode.DebugSession>();
|
||||
this._onDidChangeActiveDebugSession = new Emitter<vscode.DebugSession>();
|
||||
this._onDidReceiveDebugSessionCustomEvent = new Emitter<vscode.DebugSessionCustomEvent>();
|
||||
@@ -41,15 +45,30 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
|
||||
this._debugServiceProxy = threadService.get(MainContext.MainThreadDebugService);
|
||||
}
|
||||
|
||||
public createDebugSession(config: vscode.DebugConfiguration): TPromise<vscode.DebugSession> {
|
||||
public startDebugging(nameOrConfig: string | vscode.DebugConfiguration): TPromise<boolean> {
|
||||
|
||||
return this._debugServiceProxy.$createDebugSession(config).then((id: DebugSessionUUID) => {
|
||||
return this._debugServiceProxy.$startDebugging(nameOrConfig);
|
||||
}
|
||||
|
||||
public startDebugSession(config: vscode.DebugConfiguration): TPromise<vscode.DebugSession> {
|
||||
|
||||
return this._debugServiceProxy.$startDebugSession(config).then((id: DebugSessionUUID) => {
|
||||
const debugSession = new ExtHostDebugSession(this._debugServiceProxy, id, config.type, config.name);
|
||||
this._debugSessions.set(id, debugSession);
|
||||
return debugSession;
|
||||
});
|
||||
}
|
||||
|
||||
public $acceptDebugSessionStarted(id: DebugSessionUUID, type: string, name: string): void {
|
||||
|
||||
let debugSession = this._debugSessions.get(id);
|
||||
if (!debugSession) {
|
||||
debugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name);
|
||||
this._debugSessions.set(id, debugSession);
|
||||
}
|
||||
this._onDidStartDebugSession.fire(debugSession);
|
||||
}
|
||||
|
||||
public $acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void {
|
||||
|
||||
let debugSession = this._debugSessions.get(id);
|
||||
|
||||
@@ -20,8 +20,6 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
private _pidPromise: TPromise<number>;
|
||||
private _pidPromiseComplete: TValueCallback<number>;
|
||||
|
||||
private _onDataCallback: (data: string) => any;
|
||||
|
||||
constructor(
|
||||
proxy: MainThreadTerminalServiceShape,
|
||||
name?: string,
|
||||
@@ -69,11 +67,6 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
this._queueApiRequest(this._proxy.$hide, []);
|
||||
}
|
||||
|
||||
public onData(callback: (data: string) => any): void {
|
||||
this._onDataCallback = callback;
|
||||
this._queueApiRequest(this._proxy.$registerOnData, []);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (!this._disposed) {
|
||||
this._disposed = true;
|
||||
@@ -86,10 +79,6 @@ export class ExtHostTerminal implements vscode.Terminal {
|
||||
this._pidPromiseComplete = null;
|
||||
}
|
||||
|
||||
public _onData(data: string): void {
|
||||
this._onDataCallback(data);
|
||||
}
|
||||
|
||||
private _queueApiRequest(callback: (...args: any[]) => void, args: any[]) {
|
||||
let request: ApiRequest = new ApiRequest(callback, args);
|
||||
if (!this._id) {
|
||||
@@ -149,11 +138,6 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
|
||||
terminal._setProcessId(processId);
|
||||
}
|
||||
|
||||
public $acceptTerminalData(id: number, data: string): void {
|
||||
let terminal = this._getTerminalById(id);
|
||||
terminal._onData(data);
|
||||
}
|
||||
|
||||
private _getTerminalById(id: number): ExtHostTerminal {
|
||||
let index = this._getTerminalIndexById(id);
|
||||
return index !== null ? this._terminals[index] : null;
|
||||
|
||||
@@ -488,14 +488,12 @@ export class TextEdit {
|
||||
}
|
||||
}
|
||||
|
||||
export class Uri extends URI { }
|
||||
|
||||
export class WorkspaceEdit {
|
||||
|
||||
private _values: [Uri, TextEdit[]][] = [];
|
||||
private _values: [URI, TextEdit[]][] = [];
|
||||
private _index = new Map<string, number>();
|
||||
|
||||
replace(uri: Uri, range: Range, newText: string): void {
|
||||
replace(uri: URI, range: Range, newText: string): void {
|
||||
let edit = new TextEdit(range, newText);
|
||||
let array = this.get(uri);
|
||||
if (array) {
|
||||
@@ -505,19 +503,19 @@ export class WorkspaceEdit {
|
||||
}
|
||||
}
|
||||
|
||||
insert(resource: Uri, position: Position, newText: string): void {
|
||||
insert(resource: URI, position: Position, newText: string): void {
|
||||
this.replace(resource, new Range(position, position), newText);
|
||||
}
|
||||
|
||||
delete(resource: Uri, range: Range): void {
|
||||
delete(resource: URI, range: Range): void {
|
||||
this.replace(resource, range, '');
|
||||
}
|
||||
|
||||
has(uri: Uri): boolean {
|
||||
has(uri: URI): boolean {
|
||||
return this._index.has(uri.toString());
|
||||
}
|
||||
|
||||
set(uri: Uri, edits: TextEdit[]): void {
|
||||
set(uri: URI, edits: TextEdit[]): void {
|
||||
const idx = this._index.get(uri.toString());
|
||||
if (typeof idx === 'undefined') {
|
||||
let newLen = this._values.push([uri, edits]);
|
||||
@@ -527,12 +525,12 @@ export class WorkspaceEdit {
|
||||
}
|
||||
}
|
||||
|
||||
get(uri: Uri): TextEdit[] {
|
||||
get(uri: URI): TextEdit[] {
|
||||
let idx = this._index.get(uri.toString());
|
||||
return typeof idx !== 'undefined' && this._values[idx][1];
|
||||
}
|
||||
|
||||
entries(): [Uri, TextEdit[]][] {
|
||||
entries(): [URI, TextEdit[]][] {
|
||||
return this._values;
|
||||
}
|
||||
|
||||
@@ -1297,7 +1295,7 @@ export enum ProgressLocation {
|
||||
|
||||
export class TreeItem {
|
||||
|
||||
iconPath?: string | Uri | { light: string | Uri; dark: string | Uri };
|
||||
iconPath?: string | URI | { light: string | URI; dark: string | URI };
|
||||
command?: vscode.Command;
|
||||
contextValue?: string;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import URI from 'vs/base/common/uri';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { normalize } from 'vs/base/common/paths';
|
||||
import { isFalsyOrEmpty, delta } from 'vs/base/common/arrays';
|
||||
import { delta } from 'vs/base/common/arrays';
|
||||
import { relative, basename } from 'path';
|
||||
import { Workspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
@@ -19,32 +19,50 @@ import * as vscode from 'vscode';
|
||||
import { compare } from "vs/base/common/strings";
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { TrieMap } from 'vs/base/common/map';
|
||||
|
||||
|
||||
class Workspace2 {
|
||||
class Workspace2 extends Workspace {
|
||||
|
||||
static fromData(data: IWorkspaceData) {
|
||||
return data ? new Workspace2(data) : null;
|
||||
}
|
||||
|
||||
readonly workspace: Workspace;
|
||||
readonly folders: vscode.WorkspaceFolder[];
|
||||
private readonly _folder: vscode.WorkspaceFolder[] = [];
|
||||
private readonly _structure = new TrieMap<vscode.WorkspaceFolder>(s => s.split('/'));
|
||||
|
||||
private constructor(data: IWorkspaceData) {
|
||||
this.workspace = new Workspace(data.id, data.name, data.roots);
|
||||
this.folders = this.workspace.roots.map((uri, index) => ({ name: basename(uri.fsPath), uri, index }));
|
||||
super(data.id, data.name, data.roots);
|
||||
|
||||
// setup the workspace folder data structure
|
||||
this.roots.forEach((uri, index) => {
|
||||
const folder = {
|
||||
name: basename(uri.fsPath),
|
||||
uri,
|
||||
index
|
||||
};
|
||||
this._folder.push(folder);
|
||||
this._structure.insert(folder.uri.toString(), folder);
|
||||
});
|
||||
}
|
||||
|
||||
getRoot(uri: URI): vscode.WorkspaceFolder {
|
||||
const root = this.workspace.getRoot(uri);
|
||||
if (root) {
|
||||
for (const folder of this.folders) {
|
||||
if (folder.uri.toString() === uri.toString()) {
|
||||
return folder;
|
||||
get folders(): vscode.WorkspaceFolder[] {
|
||||
return this._folder.slice(0);
|
||||
}
|
||||
|
||||
getWorkspaceFolder(uri: URI): vscode.WorkspaceFolder {
|
||||
let str = uri.toString();
|
||||
let folder = this._structure.lookUp(str);
|
||||
if (folder) {
|
||||
// `uri` is a workspace folder so we
|
||||
let parts = str.split('/');
|
||||
while (parts.length) {
|
||||
if (parts.pop()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
str = parts.join('/');
|
||||
}
|
||||
return undefined;
|
||||
return this._structure.findSubstr(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +85,7 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
// --- workspace ---
|
||||
|
||||
get workspace(): Workspace {
|
||||
return this._workspace && this._workspace.workspace;
|
||||
return this._workspace;
|
||||
}
|
||||
|
||||
getWorkspaceFolders(): vscode.WorkspaceFolder[] {
|
||||
@@ -78,11 +96,11 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
}
|
||||
}
|
||||
|
||||
getEnclosingWorkspaceFolder(uri: vscode.Uri): vscode.WorkspaceFolder {
|
||||
getWorkspaceFolder(uri: vscode.Uri): vscode.WorkspaceFolder {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
}
|
||||
return this._workspace.getRoot(<URI>uri);
|
||||
return this._workspace.getWorkspaceFolder(<URI>uri);
|
||||
}
|
||||
|
||||
getPath(): string {
|
||||
@@ -92,16 +110,11 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
}
|
||||
const { roots } = this._workspace.workspace;
|
||||
const { roots } = this._workspace;
|
||||
if (roots.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
// if (roots.length === 1) {
|
||||
return roots[0].fsPath;
|
||||
// }
|
||||
// return `undefined` when there no or more than 1
|
||||
// root folder.
|
||||
// return undefined;
|
||||
}
|
||||
|
||||
getRelativePath(pathOrUri: string | vscode.Uri): string {
|
||||
@@ -117,19 +130,20 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
return path;
|
||||
}
|
||||
|
||||
if (!this._workspace || isFalsyOrEmpty(this._workspace.workspace.roots)) {
|
||||
const folder = this.getWorkspaceFolder(typeof pathOrUri === 'string'
|
||||
? URI.file(pathOrUri)
|
||||
: pathOrUri
|
||||
);
|
||||
|
||||
if (!folder) {
|
||||
return normalize(path);
|
||||
}
|
||||
|
||||
for (const { fsPath } of this._workspace.workspace.roots) {
|
||||
let result = relative(fsPath, path);
|
||||
if (!result || result.indexOf('..') === 0) {
|
||||
continue;
|
||||
}
|
||||
return normalize(result);
|
||||
let result = relative(folder.uri.fsPath, path);
|
||||
if (this.workspace.roots.length > 1) {
|
||||
result = `${folder.name}/${result}`;
|
||||
}
|
||||
|
||||
return normalize(path);
|
||||
return normalize(result);
|
||||
}
|
||||
|
||||
$acceptWorkspaceData(data: IWorkspaceData): void {
|
||||
|
||||
Reference in New Issue
Block a user