aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--runtime/doc/lsp.txt8
-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
5 files changed, 31 insertions, 1 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index 8140b6a15e..249136f32f 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -49,6 +49,7 @@ go-to-definition, hover, etc. Example config: >
nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
+ nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
Nvim provides the |vim.lsp.omnifunc| 'omnifunc' handler which allows
|i_CTRL-X_CTRL-O| to consume LSP completion. Example config (note the use of
@@ -783,6 +784,13 @@ signature_help() *vim.lsp.buf.signature_help()*
type_definition() *vim.lsp.buf.type_definition()*
TODO: Documentation
+workspace_symbol({query}) *vim.lsp.buf.workspace_symbol()*
+ Lists all symbols in the current workspace in the quickfix
+ window. The list is filtered against the optional argument
+ {query}; if the argument is omitted from the call, the user
+ is prompted to enter a string on the command line. An empty
+ string means no filtering is done.
+
==============================================================================
Lua module: vim.lsp.callbacks *lsp-callbacks*
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;