提交 ec720bfa 编写于 作者: J Johannes Rieken

filter commands that start with an underscore, make it option in the API

上级 c6a9f70e
/*---------------------------------------------------------------------------------------------
* 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
......@@ -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;
......
......@@ -2648,11 +2648,13 @@ declare namespace vscode {
export function executeCommand<T>(command: string, ...rest: any[]): Thenable<T>;
/**
* 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<string[]>;
export function getCommands(filterInternal?: boolean): Thenable<string[]>;
}
/**
......
......@@ -110,8 +110,13 @@ export class PluginHostCommands {
}
}
getCommands(): Thenable<string[]> {
return this._proxy._getCommands();
getCommands(filterUnderscoreCommands: boolean = false): Thenable<string[]> {
return this._proxy._getCommands().then(result => {
if (filterUnderscoreCommands) {
result = result.filter(command => command[0] !== '_');
}
return result;
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册