diff options
author | Hirokazu Hata <h.hata.ai.t@gmail.com> | 2020-05-08 05:23:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-07 16:23:25 -0400 |
commit | 9a67b030d9a054648296b45b615684dee768582d (patch) | |
tree | 57315d01d1a2f7f82eb0eb84b41d1eb029995a8a /runtime/lua/vim/lsp/util.lua | |
parent | 1407899c32018f1988936adfddc1dede73c559cb (diff) | |
download | rneovim-9a67b030d9a054648296b45b615684dee768582d.tar.gz rneovim-9a67b030d9a054648296b45b615684dee768582d.tar.bz2 rneovim-9a67b030d9a054648296b45b615684dee768582d.zip |
lsp: Handle unknown CompletionItemKind and SymbolKind (#12257)
* lsp: handle kinds not specified in protocol
fix: #12200
If the client set "symbolKind.valueSet",
the client must handle it properly even if it receives a value outside the specification.
* test: add lsp.util.{get_completion_item_kind_name, get_symbol_kind_name} test case
* lsp: make lsp.util.{get_completion_item_kind_name, get_symbol_kind_name} private
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index eaa5f0f02f..4d4762dac8 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -203,6 +203,13 @@ local function remove_unmatch_completion_items(items, prefix) end, items) end +-- Acording to LSP spec, if the client set "completionItemKind.valueSet", +-- the client must handle it properly even if it receives a value outside the specification. +-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion +function M._get_completion_item_kind_name(completion_item_kind) + return protocol.CompletionItemKind[completion_item_kind] or "Unknown" +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 } @@ -234,7 +241,7 @@ function M.text_document_completion_list_to_complete_items(result, prefix) table.insert(matches, { word = word, abbr = completion_item.label, - kind = protocol.CompletionItemKind[completion_item.kind] or '', + kind = M._get_completion_item_kind_name(completion_item.kind), menu = completion_item.detail or '', info = info, icase = 1, @@ -935,6 +942,13 @@ function M.set_qflist(items) }) end +-- Acording to LSP spec, if the client set "symbolKind.valueSet", +-- the client must handle it properly even if it receives a value outside the specification. +-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol +function M._get_symbol_kind_name(symbol_kind) + return protocol.SymbolKind[symbol_kind] or "Unknown" +end + --- Convert symbols to quickfix list items --- --@symbols DocumentSymbol[] or SymbolInformation[] @@ -943,7 +957,7 @@ function M.symbols_to_items(symbols, bufnr) for _, symbol in ipairs(_symbols) do if symbol.location then -- SymbolInformation type local range = symbol.location.range - local kind = protocol.SymbolKind[symbol.kind] + local kind = M._get_symbol_kind_name(symbol.kind) table.insert(_items, { filename = vim.uri_to_fname(symbol.location.uri), lnum = range.start.line + 1, @@ -952,7 +966,7 @@ function M.symbols_to_items(symbols, bufnr) text = '['..kind..'] '..symbol.name, }) elseif symbol.range then -- DocumentSymbole type - local kind = protocol.SymbolKind[symbol.kind] + local kind = M._get_symbol_kind_name(symbol.kind) table.insert(_items, { -- bufnr = _bufnr, filename = vim.api.nvim_buf_get_name(_bufnr), |