diff options
author | Hirokazu Hata <h.hata.ai.t@gmail.com> | 2020-02-18 13:40:24 +0900 |
---|---|---|
committer | Hirokazu Hata <h.hata.ai.t@gmail.com> | 2020-02-19 07:27:35 +0900 |
commit | c1bfc8093f4fb4487a2293f09558f46c7de49315 (patch) | |
tree | 169b5786954dae360164d63ec5957618a38adac2 /runtime/lua/vim/lsp/util.lua | |
parent | 4ac376740c85ee337fc10627a793452300801ce0 (diff) | |
download | rneovim-c1bfc8093f4fb4487a2293f09558f46c7de49315.tar.gz rneovim-c1bfc8093f4fb4487a2293f09558f46c7de49315.tar.bz2 rneovim-c1bfc8093f4fb4487a2293f09558f46c7de49315.zip |
lsp: respect the sort order if there is sortText
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 620037d24d..0a24444328 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -129,6 +129,15 @@ function M.extract_completion_items(result) end end +-- Sort by CompletionItem.sortText +-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion +function M.sort_completion_items(items) + if items[1] and items[1].sortText then + table.sort(items, function(a, b) return a.sortText < b.sortText + end) + end +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. function M.remove_unmatch_completion_items(items, prefix) @@ -171,6 +180,7 @@ function M.text_document_completion_list_to_complete_items(result, prefix) end items = M.remove_unmatch_completion_items(items, prefix) + M.sort_completion_items(items) local matches = {} |