gfanto/fzf-lsp.nvim

WorkspaceSymbols not working w/o arguments

octavz opened this issue · 11 comments

Hi,

Just typing :WorkspaceSymbols<CR> will show Work Space symbol not found

Expectation: Show all symbols.

Thank you.

I don't have enought information to solve your problem if i do the same, for example right now i'm using rust-analyzer as language server and if i type :WorkspaceSymbols it gives me the symbols as expeced.
I don't think it's a fzf-lsp related problem.
Have you tried:

  1. using other commands like :DocumentSymbols
  2. inspecting if your connected language server typing :lua print(vim.inspect(vim.lsp.buf_get_clients()))
  3. maybe in your language server document symbols should be anabled via configuration (python servers for example)
  4. with the default neovim api it works maybe with a clean configuration file? (:lua vim.lsp.buf.workspace_symbol())

I am using nvim-metals, everything works fine w/o fzf-lsp

DocumentSymbol works fine, WorkspaceSymbols work fine when I add an argument.
It fails when is used w/o arguments.

Please see the attached recording.

Thank you

workspace.mp4

also it works fine when typing:

:lua vim.lsp.buf.workspace_symbol()

Just a fly by comment that this actually is probably more of an issue with Metals than with with fzf-lsp. I actually noticed it when trying out the same type of functionality with telescope. The LSP spec says that you can send the server "" to get all the workspace symbols, but in that scenario Metals doesn't return anything. I think this was historically done to not literally return thousands and thousands of symbols in large projects, but it's something we can definitely look into. Feel free to actually bring this up in an issue in the Metals repo, and we can discuss there.

Thank for the advice @ckipp01, that exactly what i do, i just send "" in that case. Unfortunately i haven't take the time yet to try with metals, in fact i'm not a java/scala developer so i don't have it right now to test other cases (maybe sending nil instead of ""? i don't know at the moment i'm writing). Another thing i don't understand it's why @octavz says that :lua vim.lsp.buf.workspace_symbol() works fine it feels weird because in my understanding :lua vim.lsp.buf.workspace_symbol() ask for a query and send "" if just <CR> is pressed.
Thanks again and if you have any other advice on something that i can look please feel free to let me know.

maybe sending nil instead of ""?

No, it'd be the same result at least for Metals. We require something to be sent just to at least limit some of the results.

Another thing i don't understand it's why @octavz says that :lua vim.lsp.buf.workspace_symbol() works fine it feels weird because in my understanding :lua vim.lsp.buf.workspace_symbol() ask for a query and send "" if just is pressed.

I guess it depend on the definition of working. 😆 In this situation yea, it just sends "", but we do a very simple check on the Metals side, and if the query is empty we return nothing. So it in LSP terms it ends up looking like this:

[Trace - 02:31:18 PM] Received request 'workspace/symbol - (8)'
Params: {
  "query": ""
}


[Trace - 02:31:18 PM] Sending response 'workspace/symbol - (8)'. Processing request took 0ms
Result: []

And we just return nothing.

Thanks again and if you have any other advice on something that i can look please feel free to let me know.

Nope, all good. I think this is something we need to potentially change on our end, depending on if we start to get requests for it. Up to this point apart from me hitting on it, we haven't heard any complaints on the Metals side.

vim.mp4

It seems to me that it works fine calling it via :lua

i don't expect to start searching, prompting for a query is fine as well, is not a crash.

@octavz a short term solution would be to just wrap it in a function of your own, something like:

-- settings/workspace_symbol.lua
local M = {}
M.lsp_workspace_symbols = function()
    local input = vim.fn.input('Query: ')
    vim.api.nvim_command('normal :esc<CR>')
    if not input or #input == 0 then return end
    require'fzf_lsp'.workspace_symbol_handler { query = input } -- this is just a guess, I don't know how it's exposed in fzf-lsp
end

return M

And then instead of doing your mapping to fzf_lsp.workspace_symbol_hander() directly, do it to require'settings.workspace_sy,bol'.lsp_workspace_symbols() which will prompt you first for input before sending to the server.

Also, as an aside I can view any of your videos, I just see "Video can't be played because the file is corrupt".

@ckipp01 you are too fast for me 😅
Yeah @ckipp01 it's absolutely right in the code it has sent, even the guess it's almost 100% right you have just to replace workspace_symbol_handler with workspace_symbol_call because the _handler function have the neovim lsp handler signature.

@octavz i don't understand your point when you say:

i don't expect to start searching, prompting for a query is fine as well, is not a crash.

I don't see a message "no symbols found" as a "crash" if the server send me an empty result,
the command WorspaceSymbols accept the query argument so if you want a query just pass the query!

Maybe your are saying that if there are no result insted of printing "no result found" i should ask for a "Query" but this doesn't make sens, it's a double trip to the server and it can be that there are no results found it's not impossible.

At the end, maybe if you want something in vim script like the solution proposed by @ckipp01 that ask for a query if you don't pass a query i can translate it for you, no problem about that, it's super simple.

ok thank you @gfanto, @ckipp01 the symbols should be returned when no query using some kind of pagination or priority. I suppose I can open a feature request on metals.