diff options
author | Hirokazu Hata <h.hata.ai.t@gmail.com> | 2020-02-19 07:39:56 +0900 |
---|---|---|
committer | Hirokazu Hata <h.hata.ai.t@gmail.com> | 2020-02-19 07:39:56 +0900 |
commit | f3d4ddd0f8b654d58fb4653d88ac7f652e3ad364 (patch) | |
tree | 3436f23bf23ec7307046e6d282ad5680a93d5ae6 /runtime/lua/vim/lsp/util.lua | |
parent | c1bfc8093f4fb4487a2293f09558f46c7de49315 (diff) | |
download | rneovim-f3d4ddd0f8b654d58fb4653d88ac7f652e3ad364.tar.gz rneovim-f3d4ddd0f8b654d58fb4653d88ac7f652e3ad364.tar.bz2 rneovim-f3d4ddd0f8b654d58fb4653d88ac7f652e3ad364.zip |
lsp: make functions private and use filter function
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 0a24444328..6b12b37ec2 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -129,28 +129,6 @@ 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) - local matched_items = {} - for _, item in ipairs(items) do - local word = item.insertText or item.label - if vim.startswith(word, prefix) then - table.insert(matched_items, item) - end - end - return matched_items -end - --- Apply the TextDocumentEdit response. -- @params TextDocumentEdit [table] see https://microsoft.github.io/language-server-protocol/specification function M.apply_text_document_edit(text_document_edit) @@ -170,6 +148,24 @@ function M.get_current_line_to_cursor() return line:sub(pos[2]+1) end +-- Sort by CompletionItem.sortText +-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion +local function 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. +local function remove_unmatch_completion_items(items, prefix) + return vim.tbl_filter(function(item) + local word = item.insertText or item.label + return vim.startswith(word, prefix) + end, items) +end + --- Getting vim complete-items with incomplete flag. -- @params CompletionItem[], CompletionList or nil (https://microsoft.github.io/language-server-protocol/specification#textDocument_completion) -- @return { matches = complete-items table, incomplete = boolean } @@ -179,8 +175,8 @@ function M.text_document_completion_list_to_complete_items(result, prefix) return {} end - items = M.remove_unmatch_completion_items(items, prefix) - M.sort_completion_items(items) + items = remove_unmatch_completion_items(items, prefix) + sort_completion_items(items) local matches = {} |