nwolverson / purescript-language-server

MIT License
183 stars 41 forks source link

Automatically add imports when adding type signature #173

Open i-am-the-slime opened 2 years ago

i-am-the-slime commented 2 years ago

This is one of the most robotic things I do everyday. I let the IDE add a signature for me but then the types in this signature can't be found. It would be nice if I could apply this signature and add any missing imports in one step.

nwolverson commented 2 years ago

This is a compiler issue. Both type information returned via the purs ide protocol and type warnings/errors from the compiler (and the fixes it suggests in the json output) are textual representions of types assuming appropriate imports, leading eg to the classic "expected Type but found Type" error pattern.

But I agree, I think that separate things to do there are

  1. Compiler warnings suggest imports as required (at least in JSON form, with multiple edit suggestion)
  2. Compiler warnings qualify to avoid ambiguity (not entirely relevant to this but probably linked where there are identifiers that must be imported qualified)
  3. Separately, purs ide outputting types as structured (hence qualified) objects instead of textual representations

We could add any unambiguous imports - in fact similarly could have a "add all imports" command for unambigous imports, eg for copy-pasted code but I don't have a great feeling how useful that is