mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-08 23:32:36 -05:00
Merge pull request #1101 from Microsoft/joh/apiCommands
add addApiCommand call which can be found by a doc tool
This commit is contained in:
37
src/vs/platform/keybinding/common/commands.ts
Normal file
37
src/vs/platform/keybinding/common/commands.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 {IDisposable} from 'vs/base/common/lifecycle';
|
||||
import Event, {Emitter} from 'vs/base/common/event';
|
||||
|
||||
|
||||
export class ApiCommands {
|
||||
|
||||
static Instance = new ApiCommands();
|
||||
|
||||
private _commands: { [id: string]: [(...args: any[]) => any, any] } = Object.create(null);
|
||||
private _onDidAddCommand = new Emitter<{ id: string; handler: (...args: any[]) => any; thisArg?: any }>();
|
||||
|
||||
add(id: string, handler: (...args: any[]) => any, thisArg?: any) {
|
||||
if (this._commands[id]) {
|
||||
throw new Error();
|
||||
}
|
||||
this._commands[id] = [handler, thisArg];
|
||||
this._onDidAddCommand.fire({ id, handler, thisArg });
|
||||
}
|
||||
|
||||
track(callback: (event: { id: string; handler: (...args: any[]) => any; thisArg?: any }) => any): IDisposable {
|
||||
for (let id in this._commands) {
|
||||
let [handler, thisArg] = this._commands[id];
|
||||
callback({ id, handler, thisArg });
|
||||
}
|
||||
return this._onDidAddCommand.event(callback);
|
||||
}
|
||||
}
|
||||
|
||||
export function addApiCommand(id: string, handler: (...args: any[]) => any, thisArg?: any) {
|
||||
ApiCommands.Instance.add(id, handler, thisArg);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import {Registry} from 'vs/platform/platform';
|
||||
import {ICommandHandler, ICommandsMap, IKeybindingItem, IKeybindings, IKeybindingContextRule} from 'vs/platform/keybinding/common/keybindingService';
|
||||
import {KeybindingsUtils} from 'vs/platform/keybinding/common/keybindingsUtils';
|
||||
import {KeyMod, KeyCode, BinaryKeybindings} from 'vs/base/common/keyCodes';
|
||||
import {ApiCommands} from 'vs/platform/keybinding/common/commands';
|
||||
import Platform = require('vs/base/common/platform');
|
||||
|
||||
export interface ICommandRule extends IKeybindings {
|
||||
@@ -67,6 +68,17 @@ class KeybindingsRegistryImpl implements IKeybindingsRegistry {
|
||||
constructor() {
|
||||
this._keybindings = [];
|
||||
this._commands = Object.create(null);
|
||||
ApiCommands.Instance.track(event => {
|
||||
this.registerCommandDesc({
|
||||
id: event.id,
|
||||
handler: function(accessor, args) {
|
||||
event.handler.apply(event.thisArg, args);
|
||||
},
|
||||
weight: this.WEIGHT.externalExtension(0),
|
||||
context: undefined,
|
||||
primary: undefined
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public registerCommandRule(rule:ICommandRule): void {
|
||||
|
||||
@@ -35,6 +35,7 @@ import {NavigateTypesSupportRegistry, INavigateTypesSupport, ITypeBearing} from
|
||||
import {RenameRegistry} from 'vs/editor/contrib/rename/common/rename';
|
||||
import {FormatRegistry, FormatOnTypeRegistry} from 'vs/editor/contrib/format/common/format';
|
||||
import {ICodeLensData} from 'vs/editor/contrib/codelens/common/codelens';
|
||||
import {addApiCommand} from 'vs/platform/keybinding/common/commands';
|
||||
|
||||
export class ExtHostLanguageFeatureCommands {
|
||||
|
||||
@@ -44,28 +45,30 @@ export class ExtHostLanguageFeatureCommands {
|
||||
constructor(commands: PluginHostCommands) {
|
||||
this._commands = commands;
|
||||
|
||||
this._register('vscode.executeWorkspaceSymbolProvider', this._executeWorkspaceSymbolProvider);
|
||||
this._register('vscode.executeDefinitionProvider', this._executeDefinitionProvider);
|
||||
this._register('vscode.executeHoverProvider', this._executeHoverProvider);
|
||||
this._register('vscode.executeDocumentHighlights', this._executeDocumentHighlights);
|
||||
this._register('vscode.executeReferenceProvider', this._executeReferenceProvider);
|
||||
this._register('vscode.executeDocumentRenameProvider', this._executeDocumentRenameProvider);
|
||||
this._register('vscode.executeSignatureHelpProvider', this._executeSignatureHelpProvider);
|
||||
this._register('vscode.executeDocumentSymbolProvider', this._executeDocumentSymbolProvider);
|
||||
this._register('vscode.executeCompletionItemProvider', this._executeCompletionItemProvider);
|
||||
this._register('vscode.executeCodeActionProvider', this._executeCodeActionProvider);
|
||||
this._register('vscode.executeCodeLensProvider', this._executeCodeLensProvider);
|
||||
this._register('vscode.executeFormatDocumentProvider', this._executeFormatDocumentProvider);
|
||||
this._register('vscode.executeFormatRangeProvider', this._executeFormatRangeProvider);
|
||||
this._register('vscode.executeFormatOnTypeProvider', this._executeFormatOnTypeProvider);
|
||||
}
|
||||
|
||||
private _register(id: string, callback: (...args: any[]) => any): void {
|
||||
this._disposables.push(this._commands.registerCommand(id, callback, this));
|
||||
addApiCommand('vscode.executeWorkspaceSymbolProvider', this._executeWorkspaceSymbolProvider, this);
|
||||
addApiCommand('vscode.executeDefinitionProvider', this._executeDefinitionProvider, this);
|
||||
addApiCommand('vscode.executeHoverProvider', this._executeHoverProvider, this);
|
||||
addApiCommand('vscode.executeDocumentHighlights', this._executeDocumentHighlights, this);
|
||||
addApiCommand('vscode.executeReferenceProvider', this._executeReferenceProvider, this);
|
||||
addApiCommand('vscode.executeDocumentRenameProvider', this._executeDocumentRenameProvider, this);
|
||||
addApiCommand('vscode.executeSignatureHelpProvider', this._executeSignatureHelpProvider, this);
|
||||
addApiCommand('vscode.executeDocumentSymbolProvider', this._executeDocumentSymbolProvider, this);
|
||||
addApiCommand('vscode.executeCompletionItemProvider', this._executeCompletionItemProvider, this);
|
||||
addApiCommand('vscode.executeCodeActionProvider', this._executeCodeActionProvider, this);
|
||||
addApiCommand('vscode.executeCodeLensProvider', this._executeCodeLensProvider, this);
|
||||
addApiCommand('vscode.executeFormatDocumentProvider', this._executeFormatDocumentProvider, this);
|
||||
addApiCommand('vscode.executeFormatRangeProvider', this._executeFormatRangeProvider, this);
|
||||
addApiCommand('vscode.executeFormatOnTypeProvider', this._executeFormatOnTypeProvider, this);
|
||||
}
|
||||
|
||||
// --- command impl
|
||||
|
||||
/**
|
||||
* Execute workspace symbol provider.
|
||||
*
|
||||
* @param query Search string to match query symbol names
|
||||
* @return A promise that resolves to an array of symbol information.
|
||||
*/
|
||||
private _executeWorkspaceSymbolProvider(query: string): Thenable<types.SymbolInformation[]> {
|
||||
return this._commands.executeCommand<ITypeBearing[]>('_executeWorkspaceSymbolProvider', { query }).then(value => {
|
||||
if (Array.isArray(value)) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {PluginHostEditors} from 'vs/workbench/api/common/pluginHostEditors';
|
||||
import {IMessageService, Severity} from 'vs/platform/message/common/message';
|
||||
import {canSerialize} from 'vs/base/common/marshalling';
|
||||
import {toErrorMessage} from 'vs/base/common/errors';
|
||||
import {ApiCommands} from 'vs/platform/keybinding/common/commands';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
@Remotable.PluginHostContext('PluginHostCommands')
|
||||
@@ -27,6 +28,11 @@ export class PluginHostCommands {
|
||||
constructor(@IThreadService threadService: IThreadService) {
|
||||
this._pluginHostEditors = threadService.getRemotable(PluginHostEditors);
|
||||
this._proxy = threadService.getRemotable(MainThreadCommands);
|
||||
|
||||
ApiCommands.Instance.track(event => {
|
||||
let {id, handler, thisArg} = event;
|
||||
this.registerCommand(id, handler, thisArg);
|
||||
});
|
||||
}
|
||||
|
||||
registerCommand(id: string, command: <T>(...args: any[]) => T | Thenable<T>, thisArgs?: any): vscode.Disposable {
|
||||
|
||||
Reference in New Issue
Block a user