Home > Net >  VS Code Branching Snippet Completion Items Extension
VS Code Branching Snippet Completion Items Extension

Time:08-15

I am attempting to add Completion snippets to an extension I'm writing based on the completions sample ( choice completions demo


As an interesting aside (and more proof that the command is running before the snippet choice and thus of no use is code like this:

const SetCompletion = new vscode.CompletionItem('SET');
SetCompletion.insertText = new vscode.SnippetString('${TM_FILENAME_BASE/(.*)/${1:/upcase}/}');

SetCompletion.command = { command: 'folder-operations.setCompletionCommand', title: 'Re-trigger completions...' };

With the command defined as

const setCompletionHandler = vscode.commands.registerCommand('folder-operations.setCompletionCommand', async () => {
  await vscode.commands.executeCommand('editor.action.triggerSuggest');
  await vscode.commands.executeCommand('acceptSelectedSuggestion');
});
context.subscriptions.push(setCompletionHandler);

If you run that in a FOO.<some extension> or BAR.<ext> or BAS.<ext> it will work as expected. The snippet fileNameBase is resolved before the command is run - the command just selects the top choice.

snippet choice completions with a working command

  • Related