Monaco-editor: trigger auto-complete (suggestions) programmatically

Created on 19 Jul 2016  Â·  10Comments  Â·  Source: microsoft/monaco-editor

I have a suggestion as follows:
insertText: 'sum({{}})'
When the text is inserted the cursor is within the parenthesis appropriately. However, as soon as the text is inserted, I want to pop up the suggestions for what should go there without the user taking an action. I could not figure out how to accomplish this with a suggestion trigger which seems to have to be typed in by the user.

Thanks.

feature-request suggest

Most helpful comment

Is this fixed by this: https://github.com/Microsoft/vscode/issues/34565 ? If so, any chance monaco-editor-core version could be bumped?

All 10 comments

editor.trigger('source - use any string you like', 'editor.action.triggerSuggest', {});

I tried the above and it doesn't seem to trigger the suggestion. In addition, it's a strange construct. The text matching matches the line to the current point (supposedly) but it actually returns "sum()" instead of "sum(" which I would have expected since the cursor is in-between the parenthesis. But even when I change the match to "sum()" it still doesn't actually show the auto-complete even though I'm returning a list.

@jrieken This touches on the support to execute something/a command (that just happens to be to pop up suggestions again) when a completion item is accepted. Maybe you keep this request also in mind when designing it?

@alexandrudima how to send suggest items when do the triggerSuggest?

My case is when I input the ., it tips the table column list, and the language is SQL.

editor.onDidChangeModelContent(e => {
  if (e.text === '.') {
    monaco.languages.registerCompletionItemProvider('sql', {
      provideCompletionItems: () => {
        return [
          {
            label: 'column1',
            kind: monaco.languages.CompletionItemKind.Text
          },
          {
            label: 'column2',
            kind: monaco.languages.CompletionItemKind.Text
          }
        ]
      }
    });
    editor.trigger('source - use any string you like', 'editor.action.triggerSuggest', {});
  }
})

if i use registerCompletionItemProvider, it should input col... then completion show, bug I want auto show the column1, column2 completetion.

I have researsh this case for about two days, i need some tip. Thanks!
@alexandrudima

@alexandrudima Some response?

Any update on this feature? I would love to have the possibility to re-open suggestion dialog once user accepts a previous completion item.

any other workaround to know when suggestion was accepted?

I would love to have the possibility to re-open suggestion dialog once user accepts a previous completion item

We can do that, set editor.action.triggerSuggest as command on a suggestion.

Is this fixed by this: https://github.com/Microsoft/vscode/issues/34565 ? If so, any chance monaco-editor-core version could be bumped?

A new release will come eventually (not sure yet). Closing this issue because the underlying issue is fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inf9144 picture inf9144  Â·  3Comments

akosyakov picture akosyakov  Â·  3Comments

Kang-Jun-sik picture Kang-Jun-sik  Â·  3Comments

hawkerm picture hawkerm  Â·  3Comments

brandalorian picture brandalorian  Â·  3Comments