-
Notifications
You must be signed in to change notification settings - Fork 76
Completion should be fuzzy search rather than exact search #66
Comments
This should be an enhancement and it should highly dependent on what server you use. I can try to implement though. |
Please update to the latest branch and use this setting let g:completion_enable_fuzzy_match = 1 |
A compromise between strict and fuzzy matching would be substring matching (i.e., matching on |
Some completion engine applying multiple match algorithm. For example, coc.nvim does matching It is very good experience, I think. |
So you always want |
prefix exact -> prefix ignorecase -> substr -> fuzzy etc... I think always check |
@clason @hrsh7th Thanks you both for the suggestion. I think I can create a option like g:completion_match_strategy = ['prefix', 'substr', 'fuzzy'] When matching a word, simply loop through this option and assign priority from high to low. That way, users like me who only like one strategy can still only use one of them, others who wants more matching can setup the strategy they want. I'll need to refactor the code a little bit so it might takes some time implementing this. |
@clason An issue with substring match is it will suggest a lot of items when your prefix is a single character. Any thought on how to deal with this issue? Or I should simply avoid it when using substring match? |
@haorenW1025 I don't have the issue (at least in my use cases): Searching filters a list of candidates shown after a trigger character is entered, any match will reduce the number suggestions, whether initial or substring? But I see your point. Maybe make the number of prefix characters (optionally?) configurable per match method (i.e., it can be different for prefix, substring, and fuzzy matching)? But then it quickly starts to become complicated... Maybe people will just avoid substring matching if their source returns too many irrelevant candidates. |
@clason I'd say it would be too complicated. I'll suggest not using substring match if user encounter this problem in the documentation. Also, feel free to try the PR and tell me what you think, you can enable multiple matching by let g:completion_matching_strategy_list = ['exact', 'substr', 'fuzzy'] |
Works fine, from what I can tell! (And really speeds up filtering long lists of matches to the point where only a few Two questions:
|
Not yet, I'm thinking of having this as a separate option since all three matching strategy can benefit from this.
Yes, why should I take menu into account? I think that should only be a additional information to the word. Can you explain a little? |
Makes sense, just seeing that I haven't missed anything.
Indeed, and that additional information could be useful ;) For example, you could filter on information contained in signature help. (My specific use case is the following: the word is a key to a bibliography entry, and menu -- or rather, the completion item -- contains the full entry such as the authors, title etc. So if I don't remember the key, I can filter on author name or a word in the title that I don't remember. Admittedly not the typical lsp use case...) |
Yeah that seems to only happens in let g:completion_matching_items = ['word', 'menu', 'kind' ...] |
Makes sense. If it's only one server, maybe don't worry about it for now. (It's nice to have, but I can always fall back to omnicomplete (from vimtex) for that.) I'm a bit worried about losing the blazing performance that completion-nvim now has ;) Case insensitive is I think more important to me. |
@clason Try update to the latest commit and set this let g:completion_matching_ignore_case = 1 |
@haorenW1025 Yes, that works nicely, thank you! (But now I can't get fuzzy matching working anymore -- did that option change?) |
@clason I didn't change that... Did you use the option |
@haorenW1025 You're right, this is due to a change in texlab at the same time (I didn't realize that this would affect this): latex-lsp/texlab@38fabd6 Is this something that fundamentally conflicts with fuzzy matching, or can this be worked around somehow? |
Going down the rabbit hole of server- vs client-side filtering: microsoft/language-server-protocol#898 (comment) (Spoiler: it's complicated.) It seems to me to be useful to a) have a mechanism to decide whether client or server is responsible for sorting and filtering, b) make it configurable/overridable in the |
@clason The problem now is fuzzy match and substring match are highly dependent on what server returns. If the server decided to filter out irrelevant items(like texlab did recently) then it'll not work. Another example is clangd also filter out all the irrelevant things. As a completion engine I think there is little we can do about that... If the language server did provide the mechanism you mentioned I think it should be setup in |
@haorenW1025 Yes, this is a difficult situation. I agree that if the server filters/sorts, the client cannot (and should not) do anything about it. Unfortunately, there does not seem to be a good way according to the protocol to negotiate this -- and since it's not in the specification, it probably won't be in nvim-lsp, either. The simplest way is therefore to let the user make an informed decision: tell completion-nvim to either match/sort or not (as you already can), but on a per-server basis. One way could be to have optional keys for the on_attach({sorter={"none"}, matcher = {"exact", "substring"}}) with some reasonable defaults? (To be sure: I'm not saying completion-nvim should configure the server behavior -- I don't think that's possible -- but be configurable depending on the (fixed) server behavior: If the user knows that the server filters, they can disable matching by completion-nvim; if they know the server doesn't, they can enable matching by completion-nvim. The only issue here is that the user may have different servers, some of which filter and some of which don't...) |
Yeah that's possible and should also be a better way to setup than using global variables. I'll work on that in the same PR to avoid continuously changing interface on master branch. Thanks for the suggestion:) |
PR have been merged, feel free to reopen or open another issue for any feature suggestion:) |
Thanks for merging this! Did you change the API back from the |
Nope the |
Hmm, yes, you're right, it's just throwing an error:
(also, I think there's a typo in the readme: the second |
Ah, because it's |
It seems I change it and forgot about it...But |
No worries. Thanks for that useful feature! |
I don't know how can I explain but giving this context, correct completion is only provided when you start typing the word as it is supposed to be.
I think
marrig
should also providemargin-right
but it does not.I'm sorry in advance if it's related to language server client that I'm using.
The text was updated successfully, but these errors were encountered: