mirror of
https://github.com/Microsoft/vscode
synced 2024-10-05 19:02:54 +00:00
KeybindingService owns entire schema for keybindings.json (#66458)
This commit is contained in:
parent
57213395e6
commit
aa690a9d4c
|
@ -22,9 +22,6 @@ const fadedDecoration = vscode.window.createTextEditorDecorationType({
|
|||
let pendingLaunchJsonDecoration: NodeJS.Timer;
|
||||
|
||||
export function activate(context: vscode.ExtensionContext): void {
|
||||
//keybindings.json command-suggestions
|
||||
context.subscriptions.push(registerKeybindingsCompletions());
|
||||
|
||||
//settings.json suggestions
|
||||
context.subscriptions.push(registerSettingsCompletions());
|
||||
|
||||
|
@ -94,23 +91,6 @@ function autoFixSettingsJSON(willSaveEvent: vscode.TextDocumentWillSaveEvent): v
|
|||
vscode.workspace.applyEdit(edit));
|
||||
}
|
||||
|
||||
function registerKeybindingsCompletions(): vscode.Disposable {
|
||||
const commands = vscode.commands.getCommands(true);
|
||||
|
||||
return vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {
|
||||
|
||||
provideCompletionItems(document, position, _token) {
|
||||
const location = getLocation(document.getText(), document.offsetAt(position));
|
||||
if (location.path[1] === 'command') {
|
||||
|
||||
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
|
||||
return commands.then(ids => ids.map(id => newSimpleCompletionItem(JSON.stringify(id), range)));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function registerSettingsCompletions(): vscode.Disposable {
|
||||
return vscode.languages.registerCompletionItemProvider({ language: 'jsonc', pattern: '**/settings.json' }, {
|
||||
provideCompletionItems(document, position, token) {
|
||||
|
@ -207,16 +187,6 @@ function provideInstalledExtensionProposals(extensionsContent: IExtensionsConten
|
|||
return undefined;
|
||||
}
|
||||
|
||||
function newSimpleCompletionItem(label: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
|
||||
const item = new vscode.CompletionItem(label);
|
||||
item.kind = vscode.CompletionItemKind.Value;
|
||||
item.detail = description;
|
||||
item.insertText = insertText || label;
|
||||
item.range = range;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined): void {
|
||||
if (!editor || path.basename(editor.document.fileName) !== 'launch.json') {
|
||||
return;
|
||||
|
|
|
@ -572,6 +572,8 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
|
|||
|
||||
let schemaId = 'vscode://schemas/keybindings';
|
||||
let commandsSchemas: IJSONSchema[] = [];
|
||||
let commandsEnum: string[] = [];
|
||||
let commandsEnumDescriptions: string[] = [];
|
||||
let schema: IJSONSchema = {
|
||||
'id': schemaId,
|
||||
'type': 'array',
|
||||
|
@ -605,6 +607,8 @@ let schema: IJSONSchema = {
|
|||
},
|
||||
'command': {
|
||||
'type': 'string',
|
||||
'enum': commandsEnum,
|
||||
'enumDescriptions': commandsEnumDescriptions,
|
||||
'description': nls.localize('keybindings.json.command', "Name of the command to execute"),
|
||||
},
|
||||
'when': {
|
||||
|
@ -626,6 +630,12 @@ function updateSchema() {
|
|||
const allCommands = CommandsRegistry.getCommands();
|
||||
for (let commandId in allCommands) {
|
||||
const commandDescription = allCommands[commandId].description;
|
||||
|
||||
if (!/^_/.test(commandId)) {
|
||||
commandsEnum.push(commandId);
|
||||
commandsEnumDescriptions.push(commandDescription && commandDescription.description);
|
||||
}
|
||||
|
||||
if (!commandDescription || !commandDescription.args || commandDescription.args.length !== 1 || !commandDescription.args[0].schema) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue