Trigger DocumentHighlightProvider Programmatically #3643
Unanswered
xinshemeigui
asked this question in
Q&A
Replies: 1 comment
-
I sometimes use this code to get all commands/actions with their corresponding ID, keybinding if set, and when clause. Note that this uses an unofficial internal API to get those, so it might break in the future. type Keybinding = { command: string; keybinding?: string, when?: string; };
/**
* CAUTION: Uses an internal API to get a list of all keybindings sorted by command/action name.
*/
function getKeybindings(editor: monaco.editor.IStandaloneCodeEditor): Keybinding[] {
const keybindings = editor._standaloneKeybindingService._getResolver()._keybindings.map(x => (<Keybinding>{
command: x.command,
keybinding: x.resolvedKeybinding.getAriaLabel(),
when: x.when?.serialize()
}));
// add actions without default keybinding
for (const action of Object.values(editor._actions)) {
if (keybindings.some(x => x.command === action.id))
continue;
keybindings.push({
command: action.id,
when: action._precondition?.serialize()
});
}
return keybindings.sort((a, z) => a.command.localeCompare(z.command));
} The result is a list like [
{
"command": "acceptAlternativeSelectedSuggestion",
"keybinding": "Shift+Tab",
"when": "suggestWidgetVisible && textInputFocus && textInputFocus"
},
{
"command": "acceptAlternativeSelectedSuggestion",
"keybinding": "Shift+Enter",
"when": "suggestWidgetVisible && textInputFocus && textInputFocus"
},
{
"command": "acceptRenameInput",
"keybinding": "Enter",
"when": "editorFocus && renameInputVisible"
},
{
"command": "acceptRenameInputWithPreview",
"keybinding": "Shift+Enter",
"when": "config.editor.rename.enablePreview && editorFocus && renameInputVisible"
},
{
"command": "acceptSelectedSuggestion",
"keybinding": "Tab",
"when": "suggestWidgetVisible && textInputFocus"
},
{
"command": "acceptSelectedSuggestion",
"keybinding": "Enter",
"when": "acceptSuggestionOnEnter && suggestWidgetVisible && suggestionMakesTextEdit && textInputFocus"
},
{
"command": "actions.find",
"keybinding": "Control+F",
"when": "editorFocus || editorIsOpen"
}
// ...
] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
edit.trigger('anyString', id)
i know the id of CompletionItemProvider is editor.action.triggerSuggest
but How do I find the id of other event?
eg. DocumentHighlightProvider
Beta Was this translation helpful? Give feedback.
All reactions