aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorChristian Clason <christian.clason@uni-due.de>2020-05-02 17:56:05 +0200
committerGitHub <noreply@github.com>2020-05-02 17:56:05 +0200
commitea347b18d883999ed9a8d2e7c00068058135232f (patch)
treeca1271a72e36e45d6450f8009f9f6e668576c1f5 /runtime/lua/vim
parent2f42e4d0c86163e64eb56077939fe405dc434e42 (diff)
downloadrneovim-ea347b18d883999ed9a8d2e7c00068058135232f.tar.gz
rneovim-ea347b18d883999ed9a8d2e7c00068058135232f.tar.bz2
rneovim-ea347b18d883999ed9a8d2e7c00068058135232f.zip
lsp: add workspace/symbol (#12224)
* lsp: add workspace/symbol * refactor symbol callback * set hierarchical symbol support to true * add documentation and default mapping Co-authored-by: Hirokazu Hata <h.hata.ai.t@gmail.com>
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp.lua1
-rw-r--r--runtime/lua/vim/lsp/buf.lua6
-rw-r--r--runtime/lua/vim/lsp/callbacks.lua4
-rw-r--r--runtime/lua/vim/lsp/protocol.lua13
4 files changed, 23 insertions, 1 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 bca4840674..1c499d23a6 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -688,6 +688,19 @@ function protocol.make_client_capabilities()
};
hierarchicalDocumentSymbolSupport = true;
};
+ workspaceSymbol = {
+ 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;
+ };
};
workspace = nil;
experimental = nil;