diff options
author | Matthieu Coudron <mattator@gmail.com> | 2020-04-20 21:31:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 21:31:19 +0200 |
commit | 9678fe4cfba9f7a9dacbd6d5a56c58241e98aa60 (patch) | |
tree | 854b1c13deab54eadd807b032228ed6ddfa99e83 /runtime/lua/vim/lsp/util.lua | |
parent | 8745247cba17bba41eb3f4fc396d30335625ab83 (diff) | |
parent | 49045b173e0d67a2d140cf914513dc99d2d0d51b (diff) | |
download | rneovim-9678fe4cfba9f7a9dacbd6d5a56c58241e98aa60.tar.gz rneovim-9678fe4cfba9f7a9dacbd6d5a56c58241e98aa60.tar.bz2 rneovim-9678fe4cfba9f7a9dacbd6d5a56c58241e98aa60.zip |
Merge pull request #11989 from Weypare/textEdit
LSP/completion: add textEdit support
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 82a4223102..ce5baf5b4b 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -157,11 +157,23 @@ local function sort_completion_items(items) end end +-- Returns text that should be inserted when selecting completion item. The precedence is as follows: +-- textEdit.newText > insertText > label +-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion +local function get_completion_word(item) + if item.textEdit ~= nil and item.textEdit.newText ~= nil then + return item.textEdit.newText + elseif item.insertText ~= nil then + return item.insertText + end + return item.label +end + -- Some lanuguage servers return complementary candidates whose prefixes do not match are also returned. -- So we exclude completion candidates whose prefix does not match. local function remove_unmatch_completion_items(items, prefix) return vim.tbl_filter(function(item) - local word = item.insertText or item.label + local word = get_completion_word(item) return vim.startswith(word, prefix) end, items) end @@ -193,7 +205,7 @@ function M.text_document_completion_list_to_complete_items(result, prefix) end end - local word = completion_item.insertText or completion_item.label + local word = get_completion_word(completion_item) table.insert(matches, { word = word, abbr = completion_item.label, |