From b5220f9b1910c139b11d2ddd705c0444b52e0f9c Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 8 Dec 2015 09:48:19 +0100 Subject: [PATCH] add addApiCommand call which can be found by a doc tool --- src/vs/platform/keybinding/common/commands.ts | 37 ++++++++++++++++++ .../keybinding/common/keybindingsRegistry.ts | 12 ++++++ .../common/extHostLanguageFeatureCommands.ts | 39 ++++++++++--------- .../api/common/pluginHostCommands.ts | 6 +++ 4 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 src/vs/platform/keybinding/common/commands.ts diff --git a/src/vs/platform/keybinding/common/commands.ts b/src/vs/platform/keybinding/common/commands.ts new file mode 100644 index 00000000000..d3bfa2c93a7 --- /dev/null +++ b/src/vs/platform/keybinding/common/commands.ts @@ -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); +} \ No newline at end of file diff --git a/src/vs/platform/keybinding/common/keybindingsRegistry.ts b/src/vs/platform/keybinding/common/keybindingsRegistry.ts index 65ac634a595..7275deb876e 100644 --- a/src/vs/platform/keybinding/common/keybindingsRegistry.ts +++ b/src/vs/platform/keybinding/common/keybindingsRegistry.ts @@ -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 { diff --git a/src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts b/src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts index 9c8b5e54693..260dc0aaae6 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts @@ -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 { return this._commands.executeCommand('_executeWorkspaceSymbolProvider', { query }).then(value => { if (Array.isArray(value)) { diff --git a/src/vs/workbench/api/common/pluginHostCommands.ts b/src/vs/workbench/api/common/pluginHostCommands.ts index bc57ffe3992..4c9defc22c5 100644 --- a/src/vs/workbench/api/common/pluginHostCommands.ts +++ b/src/vs/workbench/api/common/pluginHostCommands.ts @@ -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: (...args: any[]) => T | Thenable, thisArgs?: any): vscode.Disposable { -- GitLab