mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Merge branch 'master' into joh/remote
This commit is contained in:
@@ -131,6 +131,20 @@ export function createApiFactory(
|
||||
}
|
||||
}
|
||||
|
||||
const apiUsage = new class {
|
||||
private _seen = new Set<string>();
|
||||
publicLog(apiName: string) {
|
||||
if (this._seen.has(apiName)) {
|
||||
return undefined;
|
||||
}
|
||||
this._seen.add(apiName);
|
||||
return telemetryService.publicLog('apiUsage', {
|
||||
name: apiName,
|
||||
extension: extension.id
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// namespace: commands
|
||||
const commands: typeof vscode.commands = {
|
||||
registerCommand<T>(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
|
||||
@@ -347,28 +361,24 @@ export function createApiFactory(
|
||||
// namespace: workspace
|
||||
const workspace: typeof vscode.workspace = {
|
||||
get rootPath() {
|
||||
telemetryService.publicLog('api-getter', {
|
||||
name: 'workspace#rootPath',
|
||||
extension: extension.id
|
||||
});
|
||||
apiUsage.publicLog('workspace#rootPath');
|
||||
return extHostWorkspace.getPath();
|
||||
},
|
||||
set rootPath(value) {
|
||||
throw errors.readonly();
|
||||
},
|
||||
getContainingWorkspaceFolder(resource) {
|
||||
return extHostWorkspace.getEnclosingWorkspaceFolder(resource);
|
||||
},
|
||||
get workspaceFolders() {
|
||||
// proposed api
|
||||
assertProposedApi(extension);
|
||||
telemetryService.publicLog('api-getter', {
|
||||
name: 'workspace#workspaceFolders',
|
||||
extension: extension.id
|
||||
});
|
||||
return extHostWorkspace.getRoots();
|
||||
apiUsage.publicLog('workspace#workspaceFolders');
|
||||
return extHostWorkspace.getWorkspaceFolders();
|
||||
},
|
||||
onDidChangeWorkspaceFolders: proposedApiFunction(extension, (listener, thisArgs?, disposables?) => {
|
||||
telemetryService.publicLog('api-getter', {
|
||||
name: 'workspace#onDidChangeWorkspaceFolders',
|
||||
extension: extension.id
|
||||
});
|
||||
// proposed api
|
||||
apiUsage.publicLog('workspace#onDidChangeWorkspaceFolders');
|
||||
return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
|
||||
}),
|
||||
asRelativePath: (pathOrUri) => {
|
||||
@@ -467,7 +477,6 @@ export function createApiFactory(
|
||||
// namespace: debug
|
||||
const debug: typeof vscode.debug = {
|
||||
get activeDebugSession() {
|
||||
assertProposedApi(extension);
|
||||
return extHostDebugService.activeDebugSession;
|
||||
},
|
||||
createDebugSession(config: vscode.DebugConfiguration) {
|
||||
@@ -476,12 +485,12 @@ export function createApiFactory(
|
||||
onDidTerminateDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
|
||||
},
|
||||
onDidChangeActiveDebugSession: proposedApiFunction(extension, (listener, thisArg?, disposables?) => {
|
||||
onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
|
||||
}),
|
||||
onDidReceiveDebugSessionCustomEvent: proposedApiFunction(extension, (listener, thisArg?, disposables?) => {
|
||||
},
|
||||
onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -468,7 +468,7 @@ export abstract class ExtHostLanguageFeaturesShape {
|
||||
$provideHover(handle: number, resource: URI, position: IPosition): TPromise<modes.Hover> { throw ni(); }
|
||||
$provideDocumentHighlights(handle: number, resource: URI, position: IPosition): TPromise<modes.DocumentHighlight[]> { throw ni(); }
|
||||
$provideReferences(handle: number, resource: URI, position: IPosition, context: modes.ReferenceContext): TPromise<modes.Location[]> { throw ni(); }
|
||||
$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.CodeAction[]> { throw ni(); }
|
||||
$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.Command[]> { throw ni(); }
|
||||
$provideDocumentFormattingEdits(handle: number, resource: URI, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); }
|
||||
$provideDocumentRangeFormattingEdits(handle: number, resource: URI, range: IRange, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); }
|
||||
$provideOnTypeFormattingEdits(handle: number, resource: URI, position: IPosition, ch: string, options: modes.FormattingOptions): TPromise<editorCommon.ISingleEditOperation[]> { throw ni(); }
|
||||
|
||||
@@ -399,11 +399,11 @@ export class ExtHostApiCommands {
|
||||
resource,
|
||||
range: typeConverters.fromRange(range)
|
||||
};
|
||||
return this._commands.executeCommand<modes.CodeAction[]>('_executeCodeActionProvider', args).then(value => {
|
||||
return this._commands.executeCommand<modes.Command[]>('_executeCodeActionProvider', args).then(value => {
|
||||
if (!Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
return value.map(quickFix => this._commands.converter.fromInternal(quickFix.command));
|
||||
return value.map(quickFix => this._commands.converter.fromInternal(quickFix));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ class QuickFixAdapter {
|
||||
this._provider = provider;
|
||||
}
|
||||
|
||||
provideCodeActions(resource: URI, range: IRange): TPromise<modes.CodeAction[]> {
|
||||
provideCodeActions(resource: URI, range: IRange): TPromise<modes.Command[]> {
|
||||
|
||||
const doc = this._documents.getDocumentData(resource).document;
|
||||
const ran = TypeConverters.toRange(range);
|
||||
@@ -291,12 +291,7 @@ class QuickFixAdapter {
|
||||
if (!Array.isArray(commands)) {
|
||||
return undefined;
|
||||
}
|
||||
return commands.map((command, i) => {
|
||||
return <modes.CodeAction>{
|
||||
command: this._commands.toInternal(command),
|
||||
score: i
|
||||
};
|
||||
});
|
||||
return commands.map(command => this._commands.toInternal(command));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -713,7 +708,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
return ExtHostLanguageFeatures._handlePool++;
|
||||
}
|
||||
|
||||
private _withAdapter<A, R>(handle: number, ctor: { new (...args: any[]): A }, callback: (adapter: A) => TPromise<R>): TPromise<R> {
|
||||
private _withAdapter<A, R>(handle: number, ctor: { new(...args: any[]): A }, callback: (adapter: A) => TPromise<R>): TPromise<R> {
|
||||
let adapter = this._adapter.get(handle);
|
||||
if (!(adapter instanceof ctor)) {
|
||||
return TPromise.wrapError<R>(new Error('no adapter found'));
|
||||
@@ -843,7 +838,7 @@ export class ExtHostLanguageFeatures extends ExtHostLanguageFeaturesShape {
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.CodeAction[]> {
|
||||
$provideCodeActions(handle: number, resource: URI, range: IRange): TPromise<modes.Command[]> {
|
||||
return this._withAdapter(handle, QuickFixAdapter, adapter => adapter.provideCodeActions(resource, range));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,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 { relative } from 'path';
|
||||
import { relative, basename } from 'path';
|
||||
import { Workspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
@@ -20,36 +20,71 @@ import { compare } from "vs/base/common/strings";
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
|
||||
|
||||
class Workspace2 {
|
||||
|
||||
static fromData(data: IWorkspaceData) {
|
||||
return data ? new Workspace2(data) : null;
|
||||
}
|
||||
|
||||
readonly workspace: Workspace;
|
||||
readonly folders: vscode.WorkspaceFolder[];
|
||||
|
||||
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 }));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
|
||||
private static _requestIdPool = 0;
|
||||
|
||||
private readonly _onDidChangeWorkspace = new Emitter<vscode.WorkspaceFoldersChangeEvent>();
|
||||
private readonly _proxy: MainThreadWorkspaceShape;
|
||||
private _workspace: Workspace;
|
||||
private _workspace: Workspace2;
|
||||
|
||||
readonly onDidChangeWorkspace: Event<vscode.WorkspaceFoldersChangeEvent> = this._onDidChangeWorkspace.event;
|
||||
|
||||
constructor(threadService: IThreadService, data: IWorkspaceData) {
|
||||
super();
|
||||
this._proxy = threadService.get(MainContext.MainThreadWorkspace);
|
||||
this._workspace = data ? new Workspace(data.id, data.name, data.roots) : null;
|
||||
this._workspace = Workspace2.fromData(data);
|
||||
}
|
||||
|
||||
// --- workspace ---
|
||||
|
||||
get workspace(): Workspace {
|
||||
return this._workspace;
|
||||
return this._workspace && this._workspace.workspace;
|
||||
}
|
||||
|
||||
getRoots(): URI[] {
|
||||
getWorkspaceFolders(): vscode.WorkspaceFolder[] {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
} else {
|
||||
return this._workspace.roots.slice(0);
|
||||
return this._workspace.folders.slice(0);
|
||||
}
|
||||
}
|
||||
|
||||
getEnclosingWorkspaceFolder(uri: vscode.Uri): vscode.WorkspaceFolder {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
}
|
||||
return this._workspace.getRoot(<URI>uri);
|
||||
}
|
||||
|
||||
getPath(): string {
|
||||
// this is legacy from the days before having
|
||||
// multi-root and we keep it only alive if there
|
||||
@@ -57,7 +92,7 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
}
|
||||
const { roots } = this._workspace;
|
||||
const { roots } = this._workspace.workspace;
|
||||
if (roots.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -82,11 +117,11 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
return path;
|
||||
}
|
||||
|
||||
if (!this._workspace || isFalsyOrEmpty(this._workspace.roots)) {
|
||||
if (!this._workspace || isFalsyOrEmpty(this._workspace.workspace.roots)) {
|
||||
return normalize(path);
|
||||
}
|
||||
|
||||
for (const { fsPath } of this._workspace.roots) {
|
||||
for (const { fsPath } of this._workspace.workspace.roots) {
|
||||
let result = relative(fsPath, path);
|
||||
if (!result || result.indexOf('..') === 0) {
|
||||
continue;
|
||||
@@ -99,23 +134,23 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
|
||||
|
||||
$acceptWorkspaceData(data: IWorkspaceData): void {
|
||||
|
||||
// compute delta
|
||||
const oldRoots = this._workspace ? this._workspace.roots.sort(ExtHostWorkspace._compareUri) : [];
|
||||
const newRoots = data ? data.roots.sort(ExtHostWorkspace._compareUri) : [];
|
||||
const { added, removed } = delta(oldRoots, newRoots, ExtHostWorkspace._compareUri);
|
||||
// keep old workspace folder, build new workspace, and
|
||||
// capture new workspace folders. Compute delta between
|
||||
// them send that as event
|
||||
const oldRoots = this._workspace ? this._workspace.folders.sort(ExtHostWorkspace._compareWorkspaceFolder) : [];
|
||||
|
||||
// update state
|
||||
this._workspace = data ? new Workspace(data.id, data.name, data.roots) : null;
|
||||
this._workspace = Workspace2.fromData(data);
|
||||
const newRoots = this._workspace ? this._workspace.folders.sort(ExtHostWorkspace._compareWorkspaceFolder) : [];
|
||||
|
||||
// send event
|
||||
const { added, removed } = delta(oldRoots, newRoots, ExtHostWorkspace._compareWorkspaceFolder);
|
||||
this._onDidChangeWorkspace.fire(Object.freeze({
|
||||
addedFolders: Object.freeze<vscode.Uri[]>(added),
|
||||
removedFolders: Object.freeze<vscode.Uri[]>(removed)
|
||||
added: Object.freeze<vscode.WorkspaceFolder[]>(added),
|
||||
removed: Object.freeze<vscode.WorkspaceFolder[]>(removed)
|
||||
}));
|
||||
}
|
||||
|
||||
private static _compareUri(a: vscode.Uri, b: vscode.Uri): number {
|
||||
return compare(a.toString(), b.toString());
|
||||
private static _compareWorkspaceFolder(a: vscode.WorkspaceFolder, b: vscode.WorkspaceFolder): number {
|
||||
return compare(a.uri.toString(), b.uri.toString());
|
||||
}
|
||||
|
||||
// --- search ---
|
||||
|
||||
Reference in New Issue
Block a user