tigersoldier / company-lsp

Company completion backend for lsp-mode
GNU General Public License v3.0
251 stars 26 forks source link

Support flex matching #110

Closed tigersoldier closed 5 years ago

tigersoldier commented 5 years ago

Adding a customizable option company-lsp-match-candidate-predicate. The default value is set to company-lsp-match-candidate-flex. Also provide company-lsp-match-candidate-prefix in case some people prefer the old way.

tigersoldier commented 5 years ago

Fixes #110

@yyoncho this should also handle the XML case in #103

yyoncho commented 5 years ago

I tried it with xml language server and it works fine. One issue though - among with filtering we should do sorting based on the match. For example, if we have the items (abc bcd) and the pattern is bc we should put bcd first in the list.

Here it is how vscode does that.

https://github.com/Microsoft/vscode/blob/master/src/vs/base/common/filters.ts#L524

tigersoldier commented 5 years ago

@yyoncho Added sorting. It's different from VS Code because the flex matching algorithm is a simple O(M+N) greedy match instead of O(M * N) dynamic programming. Performance wise it's better but some candidates may result in sub-optimal scoring. Hopefully it's sufficient for common cases.

yyoncho commented 5 years ago

Hm, I tried the PR but I still get the items unsorted but I can see that the sort method is called. I will investigate further and let you know.

tigersoldier commented 5 years ago

@yyoncho Try clearing company-transformers. If you use spacemacs it will be set to some value that re-orders the candidates by occurance

yyoncho commented 5 years ago

@tigersoldier thank you, that was the case. It works very well! Now, will it be fine to turn on client filtering by default for all clients?