]> Sergey Matveev's repositories - vim-lsp.git/commit
Add support for CompletionItem commands
authorMagnus Groß <magnus@mggross.com>
Sun, 3 Sep 2023 22:57:59 +0000 (00:57 +0200)
committerMagnus Groß <magnus@mggross.com>
Mon, 4 Sep 2023 15:54:00 +0000 (17:54 +0200)
commit6f4fdc7bcc3a1ba041c6196b85b506bd0c207cf0
tree51a897f47ac7c77265ae61a2b084532250e1df5f
parent189207f216fa66221b57a8a3f30d50674614ac0c
Add support for CompletionItem commands

When we resolve a completion item with a "completionItem/resolve"
request, the LSP server returns a CompletionItem object [0], which may
contain an optional "command" field. This field describes a command that
must be called **after** inserting the completion.

For example the haskell-language-server may respond with the following
command after autocompleting an unimported function (arguments are left
out for brevity):

{'command': '10619:ghcide-extend-import-action:extendImport', 'arguments': [], 'title': 'extend import'}

Then when we send the matching "workspace/executeCommand" request, the
server will respond with a "workspace/applyEdit" request, that
autoimports the function.

Technically the specification dictates that servers should prefer to set
"additionalTextEdits" for that usecase, but there is still some use for
doing it this way, e.g. haskell-language-server also wants to display an
info message to the user, which doesn't happen with
"additionalTextEdits".

In any case it is important to support the "command" field, as it may
also contain actions unrelated to "additionalTextEdits".

[0] https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItem
autoload/lsp/completion.vim