atom / atom-languageclient

Language Server Protocol support for Atom (the basis of Atom-IDE)
https://ide.atom.io/
MIT License
388 stars 78 forks source link

fuzzaldrin filtering gives odd completions #207

Closed tomgr closed 6 years ago

tomgr commented 6 years ago

At the moment it seems that the completion results are filtered by fuzzaldrin in many cases. This produces some peculiar code completions in many cases, as fuzzaldrin uses a completely different scoring system to the language server. This can be observed when using clangd as the language server: if you manually ask for completions immediately after a = then you get back a very useful list of suggestions (i.e. local variables of the correct type, etc); If instead you ask for completions with a space after =, then you get back a list of mostly useless suggestions with the useful ones actually filtered out (i.e. typically for me I get back suggestions of log/sin/exp).

It seems odd to me to be using fuzzaldrin at all if the server was asked to provide completions as the server should know best what the ranking is. It is certainly very odd to be doing filtering using fuzzaldrin as fuzzaldrin has no way of knowing whether what it filtered out was impossible at this point or not.

Could this behaviour be changed? I can think of a few possibilities:

  1. Remove the use of fuzzaldrin completely;
  2. Allow language client plugins to suppress the use of fuzzaldrin (by a property on AutoLanguageClient);
  3. Suppress the use of fuzzaldrin if each completion contains a sortText value (indicating the server has done filtering+ranking).
damieng commented 6 years ago

The problem is the client is expected to perform filtering. In the past we just called the language server every keypress and some of them took the current word into consideration and others did not. Those that did also were often unusably slow.

If the language server wants to compute the results itself every time it can set IsIncomplete to true on the response it gives to indicate that.

https://github.com/atom/atom-languageclient/issues/150

tomgr commented 6 years ago

Ok that makes sense, thanks.

It does seem odd that the completions are different if you ask for completions after x = vs x =<space>. Looking at the code, maybe filter should only be called if request.prefix contains some non-whitespace characters? With clangd running on C++ code, filter is being called with request.prefix set to a single space whenever you ask for completions with whitespace after an equals sign.

damieng commented 6 years ago

I don't disagree - personally I think the language server should return all the results and we shouldn't do any client filtering for the best experience but alas the spec and server authors disagree - primarily because of performance I believe.

We could definitely improve the filtering trigger to consider more whitespace - you want to send a PR?