microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.71k stars 29.08k forks source link

Some CompletionItems are being ignored by vscode #104490

Closed davidmedinasigasi closed 4 years ago

davidmedinasigasi commented 4 years ago

I am currently developing a vscode extension that connects to language server using the LSP protocol. I have encountered an issue while developing support for completion: Whenever I trigger a completion on, for example, `include the server sends a list of competion items that look like this:

{
    "label": "uvm.sv",
    "kind": 12,
    "sortText": "00000",
    "textEdit": {
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 9
            }
        },
        "newText": "`include \"uvm.sv\""
    }
}

However, vscode doesn't show any suggestions. I know the message structure is correct because other completions work

jrieken commented 4 years ago

A completion item provider is invoked, returns completions but they don't show up! 😕 What's the issue? Filtering! Filtering compares completions with a prefix and hides those that don't match.

Example

Extensions Rule!

The above sample was using "defaults" to determine the prefix and the filter criteria.

When to use what? It depends on the language, its word definition, and if you control/understand the word definition or not. The defaults usually work well enough but some languages might use a non-intuitive word definition, or completions span multiple words, or completions include non-word character etc. In all those cases the range-property should be used.