microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
39.87k stars 3.56k forks source link

Invalid completion items when using dots in completion item label #2136

Open lmvco opened 4 years ago

lmvco commented 4 years ago

monaco-editor version: 0.20.0 Browser: Chrome OS: Windows Playground code that reproduces the issue:

function getSuggestions(range) {
    return [
        {
            label: 'parameters.In1',
            kind: monaco.languages.CompletionItemKind.Field,
            insertText: 'parameters.In1',
            insertTextRules: null,
            range: range
        }
    ];
}

monaco.languages.registerCompletionItemProvider('javascript', {
    provideCompletionItems: function(model, position) {
        return {
            suggestions: getSuggestions(null)
        };
    }
});

monaco.editor.create(document.getElementById("container"), {
    language: "javascript"
});

I was only able to reproduce this when registering a completion item provider which return completion items with dots in the label/insertText.

Repro steps:

  1. Execute the code above
  2. Type param and choose the option parameters.In1
  3. Type again type Result: The completion menu shows an option "parameters" which was not returned by my provider neither exists in the Javascript language.

See the gif below: issue-autocomplete2

spahnke commented 4 years ago

It's even easier to reproduce. Just type foo. into the playground editor directly after the sample code and trigger suggestions https://microsoft.github.io/monaco-editor/playground.html. Since you can't infer anything there (foo is of type any as far as the language server is concerned) the editor shows you words used in the document to be at least a little helpful. image I thought these were word-based/quick suggestion but neither wordBasedSuggestions: false nor quickSuggestions: false make a difference so I'm actually not sure anymore.

spahnke commented 4 years ago

I thought these were word-based/quick suggestion but neither wordBasedSuggestions: false nor quickSuggestions: false make a difference so I'm actually not sure anymore.

Ah, that's because of #1980

orta commented 3 years ago

Yep, just confirming this is a response from the typescript side:

    {"seq":0,"type":"response","command":"completionInfo","request_seq":24,"success":true,"performanceData":{"updateGraphDurationMs":5.120795011520386},"body":{"isGlobalCompletion":false,"isMemberCompletion":true,"isNewIdentifierLocation":false,"entries":[{"name":"alert","kind":"warning","kindModifiers":"","sortText":"7"},{"name":"foo","kind":"warning","kindModifiers":"","sortText":"7"},{"name":"hello","kind":"warning","kindModifiers":"","sortText":"7"}]}}

If someone wants to solve this they'll need to add a flag to the UserPreferences type in TypeScript which surpasses passing file identifiers JS, get that shipped in a TS release and then have monaco-typescript support setting the new option if wordBasedSuggestions is false