diff options
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 1 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 6 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/callbacks.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/protocol.lua | 28 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 25 |
5 files changed, 51 insertions, 13 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 4c1c52c796..61da2130c8 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -533,6 +533,7 @@ function lsp.start_client(config) or (not client.resolved_capabilities.goto_definition and method == 'textDocument/definition') or (not client.resolved_capabilities.implementation and method == 'textDocument/implementation') or (not client.resolved_capabilities.document_symbol and method == 'textDocument/documentSymbol') + or (not client.resolved_capabilities.workspace_symbol and method == 'textDocument/workspaceSymbol') then callback(unsupported_method(method), method, nil, client_id, bufnr) return diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 587d1f52e9..0b45951a56 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -137,6 +137,12 @@ function M.document_symbol() request('textDocument/documentSymbol', params) end +function M.workspace_symbol(query) + query = query or npcall(vfn.input, "Query: ") + local params = {query = query} + request('workspace/symbol', params) +end + --- Send request to server to resolve document highlights for the --- current text document position. This request can be associated --- to key mapping or to events such as `CursorHold`, eg: diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua index bd2cbf1ea7..70d21be8e7 100644 --- a/runtime/lua/vim/lsp/callbacks.lua +++ b/runtime/lua/vim/lsp/callbacks.lua @@ -54,13 +54,15 @@ M['textDocument/references'] = function(_, _, result) api.nvim_command("wincmd p") end -M['textDocument/documentSymbol'] = function(_, _, result, _, bufnr) +local symbol_callback = function(_, _, result, _, bufnr) if not result or vim.tbl_isempty(result) then return end util.set_qflist(util.symbols_to_items(result, bufnr)) api.nvim_command("copen") api.nvim_command("wincmd p") end +M['textDocument/documentSymbol'] = symbol_callback +M['workspace/symbol'] = symbol_callback M['textDocument/rename'] = function(_, _, result) if not result then return end diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua index 41e8119c8c..76817e3a4a 100644 --- a/runtime/lua/vim/lsp/protocol.lua +++ b/runtime/lua/vim/lsp/protocol.lua @@ -644,6 +644,18 @@ function protocol.make_client_capabilities() -- TODO(tjdevries): Implement this contextSupport = false; }; + declaration = { + linkSupport = true; + }; + definition = { + linkSupport = true; + }; + implementation = { + linkSupport = true; + }; + typeDefinition = { + linkSupport = true; + }; hover = { dynamicRegistration = false; contentFormat = { protocol.MarkupKind.Markdown; protocol.MarkupKind.PlainText }; @@ -677,7 +689,21 @@ function protocol.make_client_capabilities() hierarchicalDocumentSymbolSupport = true; }; }; - workspace = nil; + workspace = { + symbol = { + dynamicRegistration = false; + symbolKind = { + valueSet = (function() + local res = {} + for k in pairs(protocol.SymbolKind) do + if type(k) == 'number' then table.insert(res, k) end + end + return res + end)(); + }; + hierarchicalWorkspaceSymbolSupport = true; + }; + }; experimental = nil; } end diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 82b9a0b3aa..6a1e799489 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -424,8 +424,10 @@ function M.make_floating_popup_options(width, height, opts) end function M.jump_to_location(location) - if location.uri == nil then return end - local bufnr = vim.uri_to_bufnr(location.uri) + -- location may be Location or LocationLink + local uri = location.uri or location.targetUri + if uri == nil then return end + local bufnr = vim.uri_to_bufnr(uri) -- Save position in jumplist vim.cmd "normal! m'" @@ -436,8 +438,9 @@ function M.jump_to_location(location) --- Jump to new location api.nvim_set_current_buf(bufnr) - local row = location.range.start.line - local col = location.range.start.character + local range = location.range or location.targetSelectionRange + local row = range.start.line + local col = range.start.character local line = api.nvim_buf_get_lines(0, row, row+1, true)[1] col = vim.str_byteindex(line, col) api.nvim_win_set_cursor(0, {row + 1, col}) @@ -876,9 +879,11 @@ function M.locations_to_items(locations) end; }) for _, d in ipairs(locations) do - local start = d.range.start - local fname = assert(vim.uri_to_fname(d.uri)) - table.insert(grouped[fname], {start = start}) + -- locations may be Location or LocationLink + local uri = d.uri or d.targetUri + local fname = assert(vim.uri_to_fname(uri)) + local range = d.range or d.targetSelectionRange + table.insert(grouped[fname], {start = range.start}) end @@ -956,10 +961,8 @@ function M.symbols_to_items(symbols, bufnr) text = '['..kind..'] '..symbol.name }) if symbol.children then - for _, child in ipairs(symbol) do - for _, v in ipairs(_symbols_to_items(child, _items, _bufnr)) do - vim.list_extend(_items, v) - end + for _, v in ipairs(_symbols_to_items(symbol.children, _items, _bufnr)) do + vim.list_extend(_items, v) end end end |