purescript-language-server
purescript-language-server copied to clipboard
[RFE] Suggest the most relevant typename first
Related to this compiler issue.
Frequently, when typing the name of a function or a type, and there are multiple candidates (I think, the most common function is singleton, which exists basically in every container: Map, HashMap, String…), the candidates that go first are the wrong ones.
I think it would be useful to check what types are used by the current source file, and then suggest those types first, and others second.
Steps to reproduce
- Create a new project with
spago init - Put the following code to
src/Main.purs:module Main where import Prelude import Effect (Effect) import Parsing (Parser) import Parsing.Combinators (manyTill) import Parsing.String (anyChar, char) parseOption :: Parser String (List Char) parseOption = manyTill anyChar (char '=') main :: Effect Unit main = pure unit - Install deps with
spago install parsing lists - Turn on the lsp server in an editor of your choice, put caret over
Listtext, removetand typetmanually. Completion would pop up.
Expected
In the completion, the first List candidate will be the "non-lazy" version.
Actual
In the completion, the first List candidate is the lazy one.
Version
0.18.0
This would go to compiler's ide part (purs ide), LS does not analyze types by itself but gets completions by querying purs ide.
Oh, I see, I'll move this to https://github.com/purescript/purescript then
Although, I'm not sure how to convert this issue to the purs ide syntax to re-create the report over there…
Although, I'm not sure how to convert this issue to the
purs idesyntax to re-create the report over there…
It's something like context-wise completions, this is not a trivial though.
Certainly @wclr is right that there is some level where this requires compiler support (and at some point mind reading) but I would not discard this issue here, it has been suggested before and there is some improvement that can be made already.
Currently qualified module completions are ranked and no other completions are ranked (see also this issue https://github.com/nwolverson/purescript-language-server/issues/32).
There's no reason that completions from already imported modules can't be ranked higher, and similarly for things like Data.List and Data.List.Lazy there might be some rules or overrides to set up.
Frequently, when typing the name of a function or a type, and there are multiple candidates (I think, the most common function is singleton, which exists basically in every container: Map, HashMap, String…), the candidates that go first are the wrong ones.
Here if you use qualified imports you see already the ordering, if you write Map.singleton probably Data.Map comes up as the suggested one (though if you type List there are far too many bad suggestions).
Here if you use qualified imports you see already the ordering, if you write
Map.singletonprobablyData.Mapcomes up as the suggested one
While in actual code I am indeed qualifying singleton and thus always get just one candidate, but for the purpose of the report I am assuming typing out an unqualified singleton. This serves no other purpose besides being another easy reproducer 😊