diff options
author | Mathias Fussenegger <f.mathias@zignar.net> | 2021-07-11 10:47:47 +0200 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-09-16 14:36:49 +0100 |
commit | 33000bd9cff3efe54c4ca14756008300d18ac07b (patch) | |
tree | af120be6a23959b4a791141edb631a1badbefae0 /runtime/lua/vim/lsp/handlers.lua | |
parent | 9f73b7c214c679bd2d82d192751e70a6b6251d69 (diff) | |
download | rneovim-33000bd9cff3efe54c4ca14756008300d18ac07b.tar.gz rneovim-33000bd9cff3efe54c4ca14756008300d18ac07b.tar.bz2 rneovim-33000bd9cff3efe54c4ca14756008300d18ac07b.zip |
backport: 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.
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 41852b9d88..4266134fe6 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -191,30 +191,37 @@ M['textDocument/codeLens'] = function(...) return require('vim.lsp.codelens').on_codelens(...) 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 ---- Prints given list of symbols to the quickfix list. ---@param _ (not used) ---@param _ (not used) ---@param result (list of Symbols) LSP method name ---@param result (table) result of LSP method; a location or a list of locations. ----(`textDocument/definition` can return `Location` or `Location[]` -local symbol_handler = 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") +--@private +--- Return a function that converts LSP responses to quickfix items and opens the qflist +-- +--@param map_result function `((resp, bufnr) -> list)` to convert the response +--@param entity name of the resource used in a `not found` error message +local function response_to_qflist(map_result, entity) + return function(err, _, result, _, bufnr) + if err then + vim.notify(err.message, vim.log.levels.ERROR) + return + end + 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 + + +--@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 -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 -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 M['textDocument/rename'] = function(_, _, result) |