mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
filter commands that start with an underscore, make it option in the API
This commit is contained in:
parent
c6a9f70e99
commit
ec720bfa9a
42
extensions/vscode-api-tests/src/commands.test.ts
Normal file
42
extensions/vscode-api-tests/src/commands.test.ts
Normal file
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
|
|
6
src/vs/vscode.d.ts
vendored
6
src/vs/vscode.d.ts
vendored
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue