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

feature request: provide sortText with completionItems #2291

Closed
mjlbach opened this issue Oct 21, 2021 · 3 comments · Fixed by #2332
Closed

feature request: provide sortText with completionItems #2291

mjlbach opened this issue Oct 21, 2021 · 3 comments · Fixed by #2332
Labels

Comments

@mjlbach
Copy link

mjlbach commented Oct 21, 2021

We received this issue on the neovim client: neovim/neovim#15414

One thing that was reported by @tomsmeding (regarding HLS) is that the results are pre-sorted by the server to include

  • case-insensitive matching
  • typo-fixing
  • intelligent result ordering so that most likely matches come first

According to the specification, if sortText is not supplied, the client should sort on the label. See here

 * A string that should be used when comparing this item
 * with other items. When `falsy` the label is used
 * as the sort text for this item.
sortText?: string;

If the results should not be sorted, sortText should be supplied to indicate the results should not be sorted as such, otherwise according to the spec we should sort on the label as we currently do which perturbs the HLS returned ordering.

I can look into providing a PR if welcome :) I don't any experience with the HLS codebase though

@jneira
Copy link
Member

jneira commented Oct 21, 2021

Thanks for report it here and the pr offer, sounds good to me. Wonder what is the behaviour of other editors like vscode o emacs, do not they follow the spec?

I don't any experience with the HLS codebase though

Dont know much about that part of the codebase but the main entry point would be https://github.com/haskell/haskell-language-server/blob/master/ghcide/src/Development/IDE/Plugin/Completions.hs

//cc @michaelpj

@mjlbach
Copy link
Author

mjlbach commented Oct 21, 2021

My understanding is lsp-mode will also sort by filter-text, and if not fall back to sorting by label, so I think this change will also improve the ordering for lsp-mode :)

https://github.com/emacs-lsp/lsp-mode/blob/1ece3b81ad10d1b10a2c73c6617b4426e673cbc7/lsp-completion.el#L231-L243

@michaelpj
Copy link
Collaborator

As an emacs user, I guess I've never seen the glorious correct ordering of results 😅

A simple hack would be to give our completion items lexicographically increasing sortTexts just before we send them back, thus effectively forcing our own sort order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants