mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Merge branch 'master' into colorpicker
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;
|
||||
@@ -90,7 +85,7 @@ export function createApiFactory(
|
||||
const extHostDocumentSaveParticipant = col.define(ExtHostContext.ExtHostDocumentSaveParticipant).set<ExtHostDocumentSaveParticipant>(new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadWorkspace)));
|
||||
const extHostEditors = col.define(ExtHostContext.ExtHostEditors).set<ExtHostEditors>(new ExtHostEditors(threadService, extHostDocumentsAndEditors));
|
||||
const extHostCommands = col.define(ExtHostContext.ExtHostCommands).set<ExtHostCommands>(new ExtHostCommands(threadService, extHostHeapService));
|
||||
const extHostTreeViews = col.define(ExtHostContext.ExtHostTreeViews).set<ExtHostTreeViews>(new ExtHostTreeViews(threadService, extHostCommands));
|
||||
const extHostTreeViews = col.define(ExtHostContext.ExtHostTreeViews).set<ExtHostTreeViews>(new ExtHostTreeViews(threadService.get(MainContext.MainThreadTreeViews), extHostCommands));
|
||||
const extHostWorkspace = col.define(ExtHostContext.ExtHostWorkspace).set<ExtHostWorkspace>(new ExtHostWorkspace(threadService, initData.workspace));
|
||||
const extHostConfiguration = col.define(ExtHostContext.ExtHostConfiguration).set<ExtHostConfiguration>(new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration));
|
||||
const extHostDiagnostics = col.define(ExtHostContext.ExtHostDiagnostics).set<ExtHostDiagnostics>(new ExtHostDiagnostics(threadService));
|
||||
@@ -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);
|
||||
|
||||
@@ -131,6 +127,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 {
|
||||
@@ -278,8 +288,16 @@ export function createApiFactory(
|
||||
get visibleTextEditors() {
|
||||
return extHostEditors.getVisibleTextEditors();
|
||||
},
|
||||
showTextDocument(document: vscode.TextDocument, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): TPromise<vscode.TextEditor> {
|
||||
return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus);
|
||||
showTextDocument(documentOrUri: vscode.TextDocument | vscode.Uri, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions, preserveFocus?: boolean): TPromise<vscode.TextEditor> {
|
||||
let documentPromise: TPromise<vscode.TextDocument>;
|
||||
if (URI.isUri(documentOrUri)) {
|
||||
documentPromise = TPromise.wrap(workspace.openTextDocument(documentOrUri));
|
||||
} else {
|
||||
documentPromise = TPromise.wrap(<vscode.TextDocument>documentOrUri);
|
||||
}
|
||||
return documentPromise.then(document => {
|
||||
return extHostEditors.showTextDocument(document, columnOrOptions, preserveFocus);
|
||||
});
|
||||
},
|
||||
createTextEditorDecorationType(options: vscode.DecorationRenderOptions): vscode.TextEditorDecorationType {
|
||||
return extHostEditors.createTextEditorDecorationType(options);
|
||||
@@ -351,30 +369,23 @@ 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();
|
||||
},
|
||||
get workspaceFolders() {
|
||||
assertProposedApi(extension);
|
||||
telemetryService.publicLog('api-getter', {
|
||||
name: 'workspace#workspaceFolders',
|
||||
extension: extension.id
|
||||
});
|
||||
return extHostWorkspace.getRoots();
|
||||
getWorkspaceFolder(resource) {
|
||||
return extHostWorkspace.getWorkspaceFolder(resource);
|
||||
},
|
||||
onDidChangeWorkspaceFolders: proposedApiFunction(extension, (listener, thisArgs?, disposables?) => {
|
||||
telemetryService.publicLog('api-getter', {
|
||||
name: 'workspace#onDidChangeWorkspaceFolders',
|
||||
extension: extension.id
|
||||
});
|
||||
get workspaceFolders() {
|
||||
apiUsage.publicLog('workspace#workspaceFolders');
|
||||
return extHostWorkspace.getWorkspaceFolders();
|
||||
},
|
||||
onDidChangeWorkspaceFolders: function (listener, thisArgs?, disposables?) {
|
||||
apiUsage.publicLog('workspace#onDidChangeWorkspaceFolders');
|
||||
return extHostWorkspace.onDidChangeWorkspace(listener, thisArgs, disposables);
|
||||
}),
|
||||
},
|
||||
asRelativePath: (pathOrUri) => {
|
||||
return extHostWorkspace.getRelativePath(pathOrUri);
|
||||
},
|
||||
@@ -446,7 +457,10 @@ export function createApiFactory(
|
||||
}),
|
||||
registerTaskProvider: (type: string, provider: vscode.TaskProvider) => {
|
||||
return extHostTask.registerTaskProvider(extension, provider);
|
||||
}
|
||||
},
|
||||
registerFileSystemProvider: proposedApiFunction(extension, (authority, provider) => {
|
||||
return extHostWorkspace.registerFileSystemProvider(authority, provider);
|
||||
})
|
||||
};
|
||||
|
||||
// namespace: scm
|
||||
@@ -467,12 +481,40 @@ export function createApiFactory(
|
||||
|
||||
// namespace: debug
|
||||
const debug: typeof vscode.debug = {
|
||||
createDebugSession: proposedApiFunction(extension, (config: vscode.DebugConfiguration) => {
|
||||
return extHostDebugService.createDebugSession(config);
|
||||
get activeDebugSession() {
|
||||
return extHostDebugService.activeDebugSession;
|
||||
},
|
||||
startDebugging: proposedApiFunction(extension, (folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration) => {
|
||||
return extHostDebugService.startDebugging(folder, nameOrConfig);
|
||||
}),
|
||||
onDidTerminateDebugSession: proposedApiFunction(extension, (listener, thisArg?, disposables?) => {
|
||||
startDebugSession(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration) {
|
||||
return extHostDebugService.startDebugSession(folder, config);
|
||||
},
|
||||
onDidStartDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidStartDebugSession(listener, thisArg, disposables);
|
||||
},
|
||||
onDidTerminateDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidTerminateDebugSession(listener, thisArg, disposables);
|
||||
})
|
||||
},
|
||||
onDidChangeActiveDebugSession(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidChangeActiveDebugSession(listener, thisArg, disposables);
|
||||
},
|
||||
onDidReceiveDebugSessionCustomEvent(listener, thisArg?, disposables?) {
|
||||
return extHostDebugService.onDidReceiveDebugSessionCustomEvent(listener, thisArg, disposables);
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -487,6 +529,11 @@ export function createApiFactory(
|
||||
workspace,
|
||||
scm,
|
||||
debug,
|
||||
get credentials() {
|
||||
return proposedApiFunction(extension, () => {
|
||||
return credentials;
|
||||
})();
|
||||
},
|
||||
// types
|
||||
CancellationTokenSource: CancellationTokenSource,
|
||||
CodeLens: extHostTypes.CodeLens,
|
||||
@@ -524,7 +571,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,
|
||||
|
||||
Reference in New Issue
Block a user