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

Include sortText in completions and improve suggestions #2332

Merged
merged 20 commits into from
Nov 10, 2021

Conversation

pepeiborra
Copy link
Collaborator

@pepeiborra pepeiborra commented Nov 6, 2021

Changes:

  • Merge sort (by fuzzy score) all the sources of completions (module names, keywords, and identifiers). Previously they were individually sorted but never merged, leading to some poor completion choices
  • Sort qualified completions up - previously some keywords could appear before
  • Sort prefix completions up - e.g. head for hea over NoHeapProfiling
  • Sort suggestions alphabetically
  • Show the provenance in the detail field when no type info available

image

Closes #2291 and #2082

Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for improving this

@pepeiborra
Copy link
Collaborator Author

I made some more changes this morning after realising that alphabetical ordering is incompatible with qualified completions, so I have ditched the multi-dimensional sort key and gone back to a flat numbered sequence.

pepeiborra and others added 3 commits November 7, 2021 13:58
This fixes the ugly "Imported from 'Just B'" and other inconsistencies
@michaelpj
Copy link
Collaborator

I made some more changes this morning after realising that alphabetical ordering is incompatible with qualified completions, so I have ditched the multi-dimensional sort key and gone back to a flat numbered sequence.

Is it incompatible? It seems to me like this means that there are three lexicographically ordered sorting factors:

  1. local/nonlocal/global
  2. qualified/unqualified (or maybe this is first? not sure)
  3. name

We can encode all this into the sort text if we want: an integer for 1, and integer for 2, and then the text for 3.

(But I think I must be missing something, since it looks like you tried something like that already?)

@pepeiborra
Copy link
Collaborator Author

I made some more changes this morning after realising that alphabetical ordering is incompatible with qualified completions, so I have ditched the multi-dimensional sort key and gone back to a flat numbered sequence.

Is it incompatible? It seems to me like this means that there are three lexicographically ordered sorting factors:

  1. local/nonlocal/global
  2. qualified/unqualified (or maybe this is first? not sure)
  3. name

We can encode all this into the sort text if we want: an integer for 1, and integer for 2, and then the text for 3.

(But I think I must be missing something, since it looks like you tried something like that already?)

Yes, this is true, we could extend the product with another factor to track qualified suggestions. It just gets a bit tedious to encode the triple in a string for the alphabetical ordering used by the client.

Basically, there are two ways that we can go about it:

a. Extend our sorting to cover all 3 (currently it's missing the last one, name) and then do a flat sequential ordering.
b. Encode all 3 factors in a string for the LSP client to sort alphabetically

It probably makes more sense to go with a, since we crop the list of suggestions by maxFactor before sending it, and we want to sort it optimally before cropping to ensure that we send the best suggestions.

@michaelpj
Copy link
Collaborator

It probably makes more sense to go with a, since we crop the list of suggestions by maxFactor before sending it, and we want to sort it optimally before cropping to ensure that we send the best suggestions.

Ooh, this is a great point, worth including in the comment. I think this alone basically means that the client can't realistically sort the results, since it doesn't have access to the full list. So we might as well just force our ordering.

@pepeiborra pepeiborra changed the title Include sortText in completions Include sortText in completions and improve suggestions Nov 8, 2021
@pepeiborra
Copy link
Collaborator Author

pepeiborra commented Nov 8, 2021

It probably makes more sense to go with a, since we crop the list of suggestions by maxFactor before sending it, and we want to sort it optimally before cropping to ensure that we send the best suggestions.

Ooh, this is a great point, worth including in the comment. I think this alone basically means that the client can't realistically sort the results, since it doesn't have access to the full list. So we might as well just force our ordering.

The client can sort, but if we don't sort then the quality of suggestions will be worse. I have implemented a few more improvements (see PR description) including alphabetical sorting but have not enabled alphabetical sorting since it breaks a lot of tests and I'm lazy

@pepeiborra pepeiborra added the merge me Label to trigger pull request merge label Nov 10, 2021
@mergify mergify bot merged commit 26668f7 into master Nov 10, 2021
@tomsmeding
Copy link

This is awesome! Thanks for the work!

Match the first character case-sensitively - e.g. don't suggest truncate for Tru, only True

Is it reasonable to have this be configurable? I'd like to reduce my usage of the shift key, and I was very happy with the past behaviour where the whole match was case insensitive. If you consider this too much of a maintenance burden, that's fine too. :)

yoshitsugu pushed a commit to yoshitsugu/haskell-language-server that referenced this pull request Nov 12, 2021
* sort completions

* add an example

* Include fuzzy scores in completions sort text

* hlints

* Extend completion documentation to inform whether an identifier is alreaady imported

* Ditch alphabetical ordering - it's incompatible with qualified completions

* Fix bugs in completion help text

This fixes the ugly "Imported from 'Just B'" and other inconsistencies

* added tests for qualified completions

* Fix redundant import

* Inline Fuzzy.match to apply [1] and to be case-sensitive on first match

[1] - joom/fuzzy#4

* fixup! Fix bugs in completion help text

* Sort qualified completions first

* Filter out global suggestions that overlap with local

For example, don't suggest GHC.Exts.fromList when Data.Map.fromList is in scope alraedy

* Sort completions alphabetically

* Show provenance in detail text

* Sort local/in-scope completions first

* Fix build with GHC 9

* Ignore func symbol tests

Co-authored-by: Alex Naspo <alex.naspo@protonmail.com>
Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
jneira added a commit that referenced this pull request Nov 15, 2021
* Skip parsing without haddock for above GHC9.0

* Use runtime ghc version check

* Need parse twice in getParsedModuleRule

* Include sortText in completions and improve suggestions (#2332)

* sort completions

* add an example

* Include fuzzy scores in completions sort text

* hlints

* Extend completion documentation to inform whether an identifier is alreaady imported

* Ditch alphabetical ordering - it's incompatible with qualified completions

* Fix bugs in completion help text

This fixes the ugly "Imported from 'Just B'" and other inconsistencies

* added tests for qualified completions

* Fix redundant import

* Inline Fuzzy.match to apply [1] and to be case-sensitive on first match

[1] - joom/fuzzy#4

* fixup! Fix bugs in completion help text

* Sort qualified completions first

* Filter out global suggestions that overlap with local

For example, don't suggest GHC.Exts.fromList when Data.Map.fromList is in scope alraedy

* Sort completions alphabetically

* Show provenance in detail text

* Sort local/in-scope completions first

* Fix build with GHC 9

* Ignore func symbol tests

Co-authored-by: Alex Naspo <alex.naspo@protonmail.com>
Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>

* Give unique names to post-jobs (#2337)

* Restore comment

* Parse only with Haddock above GHC90

* Remove obsolete comment

Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>
Co-authored-by: Alex Naspo <alex.naspo@protonmail.com>
Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
@jneira jneira linked an issue Nov 16, 2021 that may be closed by this pull request
pepeiborra added a commit that referenced this pull request Nov 19, 2021
* Skip parsing without haddock for above GHC9.0

* Use runtime ghc version check

* Need parse twice in getParsedModuleRule

* Include sortText in completions and improve suggestions (#2332)

* sort completions

* add an example

* Include fuzzy scores in completions sort text

* hlints

* Extend completion documentation to inform whether an identifier is alreaady imported

* Ditch alphabetical ordering - it's incompatible with qualified completions

* Fix bugs in completion help text

This fixes the ugly "Imported from 'Just B'" and other inconsistencies

* added tests for qualified completions

* Fix redundant import

* Inline Fuzzy.match to apply [1] and to be case-sensitive on first match

[1] - joom/fuzzy#4

* fixup! Fix bugs in completion help text

* Sort qualified completions first

* Filter out global suggestions that overlap with local

For example, don't suggest GHC.Exts.fromList when Data.Map.fromList is in scope alraedy

* Sort completions alphabetically

* Show provenance in detail text

* Sort local/in-scope completions first

* Fix build with GHC 9

* Ignore func symbol tests

Co-authored-by: Alex Naspo <alex.naspo@protonmail.com>
Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>

* Give unique names to post-jobs (#2337)

* Restore comment

* Parse only with Haddock above GHC90

* Remove obsolete comment

Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>
Co-authored-by: Alex Naspo <alex.naspo@protonmail.com>
Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: provide sortText with completionItems Autocompletion no longer counts qualified imports
5 participants