diff --git a/extensions/vscode-api-tests/src/commands.test.ts b/extensions/vscode-api-tests/src/commands.test.ts new file mode 100644 index 00000000000..fe5a4e7aa11 --- /dev/null +++ b/extensions/vscode-api-tests/src/commands.test.ts @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * 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 * as assert from 'assert'; +import {commands} from 'vscode'; +import {join} from 'path'; + +suite("commands namespace tests", () => { + + test('getCommands', function(done) { + + let p1 = commands.getCommands().then(commands => { + let hasOneWithUnderscore = false; + for (let command of commands) { + if (command[0] === '_') { + hasOneWithUnderscore = true; + break; + } + } + assert.ok(hasOneWithUnderscore); + }, done); + + let p2 = commands.getCommands(true).then(commands => { + let hasOneWithUnderscore = false; + for (let command of commands) { + if (command[0] === '_') { + hasOneWithUnderscore = true; + break; + } + } + assert.ok(!hasOneWithUnderscore); + }, done); + + Promise.all([p1, p2]).then(() => { + done(); + }, done); + }); +}); \ No newline at end of file diff --git a/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts b/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts index 4f21cfa8b24..34c98b4e2fd 100644 --- a/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts +++ b/src/vs/platform/keybinding/browser/keybindingServiceImpl.ts @@ -215,7 +215,7 @@ export class KeybindingService extends AbstractKeybindingService implements IKey private _getAllCommandsAsComment(): string { var boundCommands = this._resolver.getDefaultBoundCommands(); - var unboundCommands = Object.keys(KeybindingsRegistry.getCommands()).filter((commandId) => !boundCommands[commandId]); + var unboundCommands = Object.keys(KeybindingsRegistry.getCommands()).filter(commandId => commandId[0] !== '_' && !boundCommands[commandId]); var pretty = unboundCommands.join('\n// - '); return '// ' + nls.localize('unboundCommands', "Here are other available commands: ") + '\n// - ' + pretty; diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 2b9a4eab7aa..5a840f2b0b4 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -2648,11 +2648,13 @@ declare namespace vscode { export function executeCommand(command: string, ...rest: any[]): Thenable; /** - * Retrieve the list of all available commands. + * Retrieve the list of all available commands. Commands starting an underscore are + * treated as internal commands. * + * @param filterInternal Set `true` to not see internal commands (starting with an underscore) * @return Thenable that resolves to a list of command ids. */ - export function getCommands(): Thenable; + export function getCommands(filterInternal?: boolean): Thenable; } /** diff --git a/src/vs/workbench/api/common/pluginHostCommands.ts b/src/vs/workbench/api/common/pluginHostCommands.ts index bc57ffe3992..e6867b96d4b 100644 --- a/src/vs/workbench/api/common/pluginHostCommands.ts +++ b/src/vs/workbench/api/common/pluginHostCommands.ts @@ -110,8 +110,13 @@ export class PluginHostCommands { } } - getCommands(): Thenable { - return this._proxy._getCommands(); + getCommands(filterUnderscoreCommands: boolean = false): Thenable { + return this._proxy._getCommands().then(result => { + if (filterUnderscoreCommands) { + result = result.filter(command => command[0] !== '_'); + } + return result; + }); } }