mirror of
https://github.com/neovim/neovim.git
synced 2026-05-02 03:55:00 +00:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user