vscode: auto complete should replace if the response returns a text edit with range value

VS Code version:

Version: 1.40.2 (user setup)
Commit: f359dd69833dd8800b54d458f6d37ab7c78df520
Date: 2019-11-25T14:54:45.096Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363

When i manually type import java. in Java file, it didn’t replace the words. See the gif. autocomplete_bug

Below is the completion response returned by the Java LS. Actually it returns a textEdit to replace the target range with the newText, but looks like VS Code didn’t apply the TextEdit well.

[Trace - 12:24:21 PM] Received response 'completionItem/resolve - (54)' in 4ms.
Result: {
    "label": "java.awt.color",
    "kind": 9,
    "detail": "(package) java.awt.color",
    "sortText": "999999215",
    "insertTextFormat": 2,
    "textEdit": {
        "range": {
            "start": {
                "line": 21,
                "character": 7
            },
            "end": {
                "line": 21,
                "character": 12
            }
        },
        "newText": "java.awt.color.*;"
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

doesn’t calculate textEdit property during completion response, and it will lazy set it during resolving.

That’s not good and you are lucky that this has been working in the past. I believe it was a coincidence because in the past we didn’t cache ranges of completion items - something that we have changed for https://github.com/microsoft/vscode/issues/10266.

For sorting and filtering the range (derived from the edit) is needed because it defines what leading text to compare with. Also there is no guarantee that resolve is called at all, and when inserting/accepting an item we do not await resolving (this is some background why we cannot do that).

There is doc about that but I will make sure this is more clear and that we print warnings when resolve is doing too much.

For the Java-extension the only way out is to return items that are ready to be inserted when onCompletion is called and to only add detail and documentation during resolve.