how can we get which completion item is selected by the user

469 views Asked by At

I am using

provideCompletionItems

and giving it suggestion list i want to know how i can add a callback when user select a particular item.

this is how my suggestion look like

{
      label: 'apple',
      insertText:'apple',
      kind: monaco.languages.CompletionItemKind.Event,
      insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
      command: {
        id: 'editor.action.triggerSuggest',
        title: 'operator_additional_suggestions',
      },
      range,
      documentation: keyword?.description,
    }
1

There are 1 answers

0
MOSI On

You can pass arguments to the command object like so;

    command: {
        id: 'editor.action.triggerSuggest',
        title: 'operator_additional_suggestions',
        arguments:['apple']
      },

and access it in the registered command;


    editor.registerCommand('editor.action.triggerSuggest',(_:any,...args:any[])=>{
       // access the arguments here
     })