ibhagwan / fzf-lua

Improved fzf.vim written in lua
GNU Affero General Public License v3.0
2.15k stars 141 forks source link

Highlighting is broken in :FzfLua lsp_live_workspace_symbols #1028

Closed I-Own-You closed 7 months ago

I-Own-You commented 7 months ago

Info

fzf-lua configuration ```lua require('fzf-lua').setup({ --My config is pretty much the defaults with some adding to inline commands rg, fd, the theme is default "telescope" at the top }) ```

Description

So, the problem is pretty much simple:

  1. when i type letters, the result is there, everything is highlighted as it should but the letters matching dont get highlighted.
  2. If i press ctrl+g to get fuzzy search, fzf window closes and insert mode is entered (i would want it to just switch, not close)
  3. if there was some input, and i press ctrl+g, then fuzzy search works, and letters are highlighted.
  4. any other commands of :FzfLua highlights the letters.

Here is an image of it:

image

And here is when its fuzzy search mode:

image

ibhagwan commented 7 months ago
  1. when i type letters, the result is there, everything is highlighted as it should but the letters matching dont get highlighted.

That is by design, live query uses fzf’s --disabled flag, the UI doesn’t do any matching (fuzzy or otherwise), it’s simply used to send a query to the LSP server and display the result.

Btw, the reason this works a bit differently in live grep is due to the underlying rg command highlighting the regex match.

  1. If i press ctrl+g to get fuzzy search, fzf window closes and insert mode is entered (i would want it to just switch, not close)

Not sure if I understand what you mean, but if you mean the interface seems like it’s reopening a new interface that is, again because this is exactly what happens, the first fzf process is terminated and a new fzf window is opened which queries the LSP with the last query used by the live interface, this time with fuzzy matching enabled (I.e. without --disabled.

From man fzf:

--disabled
Do not perform search. With this option, fzf becomes a simple selector interface rather than a "fuzzy finder".
You can later enable the search using enable-search or toggle-search action
I-Own-You commented 7 months ago

Thanks for the explanation, i will try myself to change this behaviour in the code, because its annoying that window just closes if no query was present, again, great plugin, thanks!

ibhagwan commented 7 months ago

Thanks for the explanation, i will try myself to change this behaviour in the code, because its annoying that window just closes if no query was present, again, great plugin, thanks!

That is not something you can easily chanfe, some LSP servers support displaying all workspace symbols with no query and some require having a query, that is LSP server dependent, for example they with lua_ls and you won’t have this issue.

I-Own-You commented 7 months ago

Thanks for the explanation, i will try myself to change this behaviour in the code, because its annoying that window just closes if no query was present, again, great plugin, thanks!

That is not something you can easily chanfe, some LSP servers support displaying all workspace symbols with no query and some require having a query, that is LSP server dependent, for example they with lua_ls and you won’t have this issue.

yes i have tried now, i understand better what you meant, sadly no highlighting i will get with :FzfLua lsp_live_workspace_symbols. :Telescope lsp_dynamic_workspace_symbols on the other hand highlights the search but i dont like using telescope because its slower.

ibhagwan commented 7 months ago

sadly no highlighting i will get with :FzfLua lsp_live_workspace_symbols

That is something we can easily solve in fzf-lua code btw.

I-Own-You commented 7 months ago

sadly no highlighting i will get with :FzfLua lsp_live_workspace_symbols

That is something we can easily solve in fzf-lua code btw.

would you mind telling me how ? or where ?

ibhagwan commented 7 months ago

sadly no highlighting i will get with :FzfLua lsp_live_workspace_symbols

That is something we can easily solve in fzf-lua code btw.

would you mind telling me how ? or where ?

Somewhere in the symbol handler: https://github.com/ibhagwan/fzf-lua/blob/8ab5d68dd82aa4c5c57c521e04c113cea4f5216f/lua/fzf-lua/providers/lsp.lua#L144

The question is should it be an exact march only (probably)? Otherwise we’d need to also implement some type of fuzzy matching algorithm which I’d rather avoid now.

I-Own-You commented 7 months ago

sadly no highlighting i will get with :FzfLua lsp_live_workspace_symbols

That is something we can easily solve in fzf-lua code btw.

would you mind telling me how ? or where ?

Somewhere in the symbol handler:

https://github.com/ibhagwan/fzf-lua/blob/8ab5d68dd82aa4c5c57c521e04c113cea4f5216f/lua/fzf-lua/providers/lsp.lua#L144

The question is should it be an exact march only (probably)? Otherwise we’d need to also implement some type of fuzzy matching algorithm which I’d rather avoid now.

honestly, i dont care exact or fuzzy, most of the time, exact is preferable for all devs, so let it be exact for how long you want, it wont really matter, its not some type of completion that people often dont know what to type, symbols are something people usually know what they search for, and when you will have time and desire you could do a fuzzy one also.

ibhagwan commented 7 months ago

honestly, i dont care exact or fuzzy, most of the time, exact is preferable for all devs, so let it be exact for how long you want, it wont really matter, its not some type of completion that people often dont know what to type, symbols are something people usually know what they search for, and when you will have time and desire you could do a fuzzy one also.

Alright, let me do some testing for this and see how it comes out.

ibhagwan commented 7 months ago

@I-Own-You, try https://github.com/ibhagwan/fzf-lua/commit/f40b2764963de0b7c03e8ab204cbc787d688d6ed, the only potential issue I see with it is that the LSP doesn't always return exact matches and the ordering of the results (which is also determined by the LSP server) doesn't prioritize eact matches so that might raise quesions in the eyes of users.

For example (from my own neovim config), searching for vim , the matching does help: image

But when I search for edit I have to scroll a few pages to get to the exact matches: image

Technically we could highlight every character of the query (input prompt) but I'm not yet sure about it.

I-Own-You commented 7 months ago

@I-Own-You, try f40b276, the only potential issue I see with it is that the LSP doesn't always return exact matches and the ordering of the results (which is also determined by the LSP server) doesn't prioritize eact matches so that might raise quesions in the eyes of users.

For example (from my own neovim config), searching for vim , the matching does help: image

But when I search for edit I have to scroll a few pages to get to the exact matches: image

Technically we could highlight every character of the query (input prompt) but I'm not yet sure about it.

yea, sometimes the results are not even shown, because they are way above, and the highlighting is not exact, yes its kind of weird looking, i think your idea about: Technically we could highlight every character of the query (input prompt) but I'm not yet sure about it. is not that bad because all text that is matched will be highlighted and it will not look at least weird, and will improve much better for eye sight

ibhagwan commented 7 months ago

yea, sometimes the results are not even shown, because they are way above, and the highlighting is not exact, yes its kind of weird looking, i think your idea about: Technically we could highlight every character of the query (input prompt) but I'm not yet sure about it. is not that bad because all text that is matched will be highlighted and it will not look at least weird, and will improve much better for eye sight

It might be better in this context due to the LSP’s weird results, I’ll give it a try.

I-Own-You commented 7 months ago

yea, sometimes the results are not even shown, because they are way above, and the highlighting is not exact, yes its kind of weird looking, i think your idea about: Technically we could highlight every character of the query (input prompt) but I'm not yet sure about it. is not that bad because all text that is matched will be highlighted and it will not look at least weird, and will improve much better for eye sight

It might be better in this context due to the LSP’s weird results, I’ll give it a try.

could you also provide a highlight group for it ? i would want to customize it for my colorscheme, if its not that hard ?

ibhagwan commented 7 months ago

could you also provide a highlight group for it ? i would want to customize it for my colorscheme, if its not that hard ?

It's not that hard but ATM the behavior matches that of live_grep which highlights the matches with terminal red which I find consistent.

https://github.com/ibhagwan/fzf-lua/commit/30d63fe35f80dd78817169a9934f59d41db4f806 - Try the latest commit, every letter should be highlighted similar to what telescope does.

I-Own-You commented 7 months ago

could you also provide a highlight group for it ? i would want to customize it for my colorscheme, if its not that hard ?

It's not that hard but ATM the behavior matches that of live_grep which highlights the matches with terminal red which I find consistent.

30d63fe - Try the latest commit, every letter should be highlighted similar to what telescope does.

yes it does highlight all, b first and a second even thouht i typed ab is really funny, the matching is really broken as hell, but at leas its there

image image

ibhagwan commented 7 months ago

yes it does highlight all, b first and a second even thouht i typed ab is really funny, the matching is really broken as hell, but at leas its there

The result set comes out directly from the LSP, Telescope works similarly and matches all characters without additional sort.

This can be considered best effort without implementing an additional sorting algorithm just for live LSP symbols.

I-Own-You commented 7 months ago

yes it does highlight all, b first and a second even thouht i typed ab is really funny, the matching is really broken as hell, but at leas its there

The result set comes out directly from the LSP, Telescope works similarly and matches all characters without additional sort.

This can be considered best effort without implementing an additional sorting algorithm just for live LSP symbols.

yeah, its already nice

ibhagwan commented 7 months ago

yeah, its already nice

Great! closing until I decide what to do regarding a new hl group just for this.