Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some workspace symbols are missing when using lsp_workspace_symbols() #44

Closed
greenhat opened this issue Aug 15, 2021 · 15 comments
Closed
Labels
enhancement New feature or request

Comments

@greenhat
Copy link
Contributor

However, Telescope's lsp_dynamic_workspace_symbols() show them all while Telescope's lsp_workspace_symbols() have some of them missing as well.
I quickly glanced through Telescope's source and did not figure out the reason. I see both Telescope's dynamic/regular calls are using the same "workspace/symbol" LSP method.

@ibhagwan
Copy link
Owner

Probably a different query parameter to the LSP server, I’ll figure it out.

@ibhagwan
Copy link
Owner

I looked into both Telescope’s dynamic_workspace_symbols and workspace_symbols and it seems they’re both using an empty query, the only difference is that dynamic uses the asynchronous LSP interface (which fzf-lua) uses and the other uses the blocking LSP interface, but the query is the same and the results at least on my system seem to be matching.

I did notice however that it takes time for the LSP server to load up all the results, sometimes depending on what file you’re at, is it possible you first used the regular call and then the dynamic and the LSP populated more symbols in the meantime? Did you try to switch to dynamic/regular back and forth?

I recently added an option to use the blocking version of the LSP calls by adding { async = false } to all LSP functions (aside from diagnostics which works differently), can you try running lsp_workspace_symbols({ async = false }) and see if it makes a difference?

@greenhat
Copy link
Contributor Author

I looked into both Telescope’s dynamic_workspace_symbols and workspace_symbols and it seems they’re both using an empty query, the only difference is that dynamic uses the asynchronous LSP interface (which fzf-lua) uses and the other uses the blocking LSP interface, but the query is the same and the results at least on my system seem to be matching.

I did notice however that it takes time for the LSP server to load up all the results, sometimes depending on what file you’re at, is it possible you first used the regular call and then the dynamic and the LSP populated more symbols in the meantime? Did you try to switch to dynamic/regular back and forth?

I've tried to call them one after the other a few times from different files and the result is the same, some symbols are missing in regular(non-dynamic) version of Telescope. It's hard to gauge the total amount of symbols since Telescope limits to 128.

I recently added an option to use the blocking version of the LSP calls by adding { async = false } to all LSP functions (aside from diagnostics which works differently), can you try running lsp_workspace_symbols({ async = false }) and see if it makes a difference?

I tried it and found no difference. The results seems the same compared to regular(non-dynamic) Telescope.
I also test it on another large multi-crate Rust project and results are the same.
However, on a small one crate Rust project both Telescope versions and fzf-lua show the same result without missing symbols. Seems like the total amount of symbols in the project matter here.

@greenhat
Copy link
Contributor Author

I have an idea!
I did not mention that I found what symbols are missing by typing them in, narrowing the list.
I suspect that "dynamic" in Telescope means, that it sends LSP request on my every keystroke. While "regular" might grab all the symbols from LSP and filter in locally. Assuming that there is some cap on results amount from LSP it would explain the issue.

@ibhagwan
Copy link
Owner

I have an idea!
I did not mention that I found what symbols are missing by typing them in, narrowing the list.
I suspect that "dynamic" in Telescope means, that it sends LSP request on my every keystroke. While "regular" might grab all the symbols from LSP and filter in locally. Assuming that there is some cap on results amount from LSP it would explain the issue.

This has to be it, unfortunately that means the solution is rather complex as I have to use fzf’s change:reload event to resend the LSP query (similar to live grep) while still keeping the current result set. This might have to wait till I’m done with other higher priority tasks such as adding the builtin previewer with treesitter support.

@ibhagwan
Copy link
Owner

Ok so the best I could do now was add lsp_live_workspace_symbols where it would re-populate the result list based on what you type (similar to live_grep).

It works well, the only caveat is that the way it's currently supported via nvim-fzf is that the queries needed to be synchronous, that means that if your LSP is slow for some reason the UI will hang in between typing characters.

Test it out and lmk what you think?

@ibhagwan
Copy link
Owner

Opened nvim-fzf issue #23 so we can make this properly asynchronous.

@greenhat
Copy link
Contributor Author

Whoa! That was quick! Thanks!
It's working now! The missing symbols are there.
It has a problem with sorting(see screenshot). I typed transaction and the top items are not the most relevant. See there are Transaction and transaction above it. Also, there is no highlighting for the matched chars.
image

@ibhagwan
Copy link
Owner

Both issues here stem from the fact that fzf here doesn’t act as as a fuzzy finder anymore, the way change:reload works in fzf it is now acting only as a selector interface, every keystroke sends a new request to the LSP server and new results are displayed, the fuzzy search function is disabled.

I can add sorting before returning the results to fzf which might make it a bit more intuitive but it still won’t be exactly what you want, it will just be sorted but it doesn’t guarantee the most relevant results will be first.

One option is to add a keybind that once pressed changes fzf back to fuzzy mode which will stop sending dynamic LSP requests and fuzzy search the current result set but this sounds very convoluted and unintuitive.

The “real solution” to your issue here is adding another fuzzy algorithm on top which would fuzzy find and highlight the results before returning them to fzf, something like native lua fzf/fzy - sounds like another plug-in you know lol?

Bottom line, I can add sorting for you to try if you wish but that’s about all I can do without having to rewrite this as Telescope.

@greenhat
Copy link
Contributor Author

Got it. Thanks for the detailed explanation! And thank you for your efforts!
I agree, simple sorting does not add much and does not seems to be worth it.

@ibhagwan
Copy link
Owner

On the plus side, turns out I missed a function in nvim-fzf so I can make this asynchronous (as I planned originally) for slightly better performance.

@ibhagwan ibhagwan added the enhancement New feature or request label Aug 20, 2021
@ibhagwan
Copy link
Owner

The async version doesn’t seem to make a big difference here, I’m gonna leave it as is for now and close this issue.

@ibhagwan
Copy link
Owner

ibhagwan commented Sep 4, 2021

If you’re still interested in this I just discovered skim has an option to go back and forth from “interactive” and “command” modes (ctrl-q) by default, run this out to understand how it works:

sk --ansi -i -c 'rg --color=always --line-number "{}"'

When in the sk prompt you can press ctrl-q to run fuzzy search on the rg result set or press ctrl-q again to go back to “live grep”.

If you set fzf_bin = 'sk' and change the “send to quick fix” bind (by default ctrl-q) you can have what you were after here.

@greenhat
Copy link
Contributor Author

Thanks for letting me know about this!
sk --ansi -i -c 'rg --color=always --line-number "{}"' shows empty list, but sk -i works.

@ibhagwan
Copy link
Owner

Thanks for letting me know about this!
sk --ansi -i -c 'rg --color=always --line-number "{}"' shows empty list, but sk -i works.

I reworked lsp_live_workspace_symbols to the same code route as live_grep, you can now see empty queries in both fzf and sk (default behavior now in live symbols), this also enables the functionality of "continuous search" where the last query typed is saved and will be the one used the next time you open lsp symbols, if you wish to control these functionalities use the below:

:lua require('fzf-lua').lsp_live_workspace_symbols({ exec_empty_query = false, continue_last_search = false })

litao91 pushed a commit to litao91/fzf-lua that referenced this issue Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants