mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
fix(lsp): Ensure users get feedback on references/symbols errors or empty results
Relates to https://github.com/neovim/neovim/issues/15050 Users should get some indication if there was an error or an empty result.
This commit is contained in:
parent
79fe9dedcf
commit
256570a7a6
@ -191,30 +191,37 @@ M['textDocument/codeLens'] = function(...)
|
|||||||
return require('vim.lsp.codelens').on_codelens(...)
|
return require('vim.lsp.codelens').on_codelens(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
|
||||||
M['textDocument/references'] = function(_, _, result)
|
|
||||||
if not result then return end
|
|
||||||
util.set_qflist(util.locations_to_items(result))
|
|
||||||
api.nvim_command("copen")
|
|
||||||
end
|
|
||||||
|
|
||||||
--@private
|
--@private
|
||||||
--- Prints given list of symbols to the quickfix list.
|
--- Return a function that converts LSP responses to quickfix items and opens the qflist
|
||||||
--@param _ (not used)
|
--
|
||||||
--@param _ (not used)
|
--@param map_result function `((resp, bufnr) -> list)` to convert the response
|
||||||
--@param result (list of Symbols) LSP method name
|
--@param entity name of the resource used in a `not found` error message
|
||||||
--@param result (table) result of LSP method; a location or a list of locations.
|
local function response_to_qflist(map_result, entity)
|
||||||
---(`textDocument/definition` can return `Location` or `Location[]`
|
return function(err, _, result, _, bufnr)
|
||||||
local symbol_handler = function(_, _, result, _, bufnr)
|
if err then
|
||||||
if not result or vim.tbl_isempty(result) then return end
|
vim.notify(err.message, vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
util.set_qflist(util.symbols_to_items(result, bufnr))
|
end
|
||||||
api.nvim_command("copen")
|
if not result or vim.tbl_isempty(result) then
|
||||||
|
vim.notify('No ' .. entity .. ' found')
|
||||||
|
else
|
||||||
|
util.set_qflist(map_result(result, bufnr))
|
||||||
|
api.nvim_command("copen")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
|
||||||
|
M['textDocument/references'] = response_to_qflist(util.locations_to_items, 'references')
|
||||||
|
|
||||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
|
||||||
M['textDocument/documentSymbol'] = symbol_handler
|
M['textDocument/documentSymbol'] = response_to_qflist(util.symbols_to_items, 'document symbols')
|
||||||
|
|
||||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol
|
||||||
M['workspace/symbol'] = symbol_handler
|
M['workspace/symbol'] = response_to_qflist(util.symbols_to_items, 'symbols')
|
||||||
|
|
||||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
|
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
|
||||||
M['textDocument/rename'] = function(_, _, result)
|
M['textDocument/rename'] = function(_, _, result)
|
||||||
|
Loading…
Reference in New Issue
Block a user