fix: lsp_workspace_symbols (#1535)

This commit is contained in:
Simon Hauser
2021-12-02 18:00:26 +01:00
committed by GitHub
parent 7462999202
commit 4b3efd2341

View File

@@ -101,6 +101,7 @@ lsp.implementations = function(opts)
end end
lsp.document_symbols = function(opts) lsp.document_symbols = function(opts)
local bufnr = vim.api.nvim_get_current_buf()
local params = vim.lsp.util.make_position_params() local params = vim.lsp.util.make_position_params()
vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(err, result, _ctx, _config) vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(err, result, _ctx, _config)
if err then if err then
@@ -113,9 +114,7 @@ lsp.document_symbols = function(opts)
return return
end end
local locations = {} local locations = vim.lsp.util.symbols_to_items(result or {}, bufnr) or {}
vim.list_extend(locations, vim.lsp.util.symbols_to_items(result, 0) or {})
locations = utils.filter_symbols(locations, opts) locations = utils.filter_symbols(locations, opts)
if locations == nil then if locations == nil then
-- error message already printed in `utils.filter_symbols` -- error message already printed in `utils.filter_symbols`
@@ -332,6 +331,7 @@ lsp.range_code_actions = function(opts)
end end
lsp.workspace_symbols = function(opts) lsp.workspace_symbols = function(opts)
local bufnr = vim.api.nvim_get_current_buf()
local params = { query = opts.query or "" } local params = { query = opts.query or "" }
vim.lsp.buf_request(0, "workspace/symbol", params, function(err, server_result, _ctx, _config) vim.lsp.buf_request(0, "workspace/symbol", params, function(err, server_result, _ctx, _config)
if err then if err then
@@ -339,15 +339,7 @@ lsp.workspace_symbols = function(opts)
return return
end end
local locations = {} local locations = vim.lsp.util.symbols_to_items(server_result or {}, bufnr) or {}
if server_result and not vim.tbl_isempty(server_result) then
-- Some LSPs (like Clangd and intelephense) might return { { result = {} } }, so make sure we have result
if server_result and server_result.result and not vim.tbl_isempty(server_result.result) then
vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_result.result, 0) or {})
end
end
locations = utils.filter_symbols(locations, opts) locations = utils.filter_symbols(locations, opts)
if locations == nil then if locations == nil then
-- error message already printed in `utils.filter_symbols` -- error message already printed in `utils.filter_symbols`