microsoft / vscode

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

Using sortText and textEdit simultaneously when providing completion suggestions in a language server does not work #79393

Closed OliverSchmitt closed 5 years ago

OliverSchmitt commented 5 years ago

When implementing a Language Server that supports the Language Server Protocol VS Code does not behave according to the specification in a certain case. The case includes using the textEdit and sortText simultaneously while providing a list of CompletionItems for the completion request. In this case the sortText property is ignored.

Examples for the problem using the VS Code completion and the pygls language server framework for python can be found in this issue against the Language Server Protocol. This seems to be an issue effecting different language server implementations as well as different language clients.

vscodebot[bot] commented 5 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

dbaeumer commented 5 years ago

@OliverSchmitt can you provide a test case (best based on the completion item sample) that demos this using pure VS Code extension API

OliverSchmitt commented 5 years ago

Yes, I can. I actually already did that in this issue.

jrieken commented 5 years ago

Seems to work just fine. What is your issue? Can you add steps, expected and actual behaviour?

Screenshot 2019-08-21 at 12 04 00
OliverSchmitt commented 5 years ago

You triggered the completion by pressing ctrl+space, right? It does work for me if I do that as well. I am starting to think the issue might be the trigger kind because I noticed different behavior depending on how the completion is triggered.

a) Steps:

  1. Pressing ctrl+space

Result: Screenshot from 2019-08-21 13-14-55

b) Steps:

  1. Typing L

Result: Screenshot from 2019-08-21 13-20-51

c) Steps:

  1. Typing La

Result: Screenshot from 2019-08-21 13-22-04

d) Steps:

  1. Pressing ctrl+space
  2. Typing La

Result: Screenshot from 2019-08-21 13-23-13

If I test the same cases with the insertText instead of the textEdit property of the CompletionItem case b) and c) have the same results as case d), also with the prefix highlighting.

jrieken commented 5 years ago

This is because the completion using the textEdit always uses the current position as range. The range is the "text selection" that is to be replaced and therefore it also defines what prefix is used for filtering/sorting. If there is no prefix (no text selection, range is cursor position) then there is nothing to compare against with. When not having a prefix, the default is the current word. When showing suggestions, press Cmd/Ctrl+/ so get a explainer.

vscodebot[bot] commented 5 years ago

We have a great developer community over on slack where extension authors help each other. This is a great place for you to ask questions and find support.

Happy Coding!