Search code examples
monaco-editor

Monaco editor: Tokens selected in intellisense popup seem to be prefixed with numbers ("1_", "2_"...)


We've have a custom language in place.

When user clicks Ctrl+Space, the intellisense logic provides auto-suggestions. It triggers our logic, and our getCompletionsAtPosition returns an array of items, for example:

[{
    label: 'foo',
    type: 1
},
{
    label: 'bar',
    type: 1
}]

If the user select "bar", what's being "pasted" to the editor is not "bar", but actually "3_bar".

It looks like the prefix "3_" has been added by Monaco.

The prefix doesn't depend on the position of the item in the list - it seems to depend on the role (keyword, operator etc.)

We'd like to understand what causes it and how to remove it.

Thanks!

"monaco-editor": "0.21.2"

Solution

  • False alarm: it turns out this was my mistake.

    As the monaco.languages.CompletionItem signature changed, I misspelled the sortText so it became insertText (for sortText we've been prepending these numbers).