Emacs, psc-ide mode not adding imports

Since someone here mentioned that psc-ide mode (I’m using Emacs) is supposed to add specified imports, I realized it doesn’t seem to be working for me.

Let’s say I want to use ‘traverse’ from Data.Traversable. Let’s say I haven’t yet put “import Data.Traversable” there.

So I start to type “traverse” and it doesn’t offer to auto complete, which I figure is because I hadn’t added the import. So then I erase “traverse” and go to type “import Data.Traverable”. Then I start typing “traverse” again, and after I type “trav” it offers to complete it. So I accept the completion (“traverse”). At that point, psc-ide does some stuff to my imports, in particular putting them in alphabetical order, but it doesn’t add a specification of “traverse”.

I looked over the “customize” settings for psc-ide, and the following are all on:

  • Psc Ide Add Import On Completion
  • Psc Ide Add Qualification On Completion

and most other options seem to be either irrelevant or have the appropriate setting (say, “on” for most of them).

The Emacs plugin won’t show you completions for modules you don’t have imported yet unless you trigger the completion popup manually (using company-complete). I’ve bound that command to C-SPC, but you can bind it to whatever you want.

Also check out the documentation at https://github.com/epost/psc-ide-emacs which describes this behaviour as well as a few other things you might run into.

EDIT:

If you’ve already typed out the identifier you don’t need to go back and make the plugin autocomplete it. You can run the psc-ide-add-import command (bound to C-c C-i by default) instead. This also works for qualified identifiers! For example typing Map.insert and then running the add-import command with the cursor on insert will add a import Data.Map as Map to your file.

1 Like

It sounds like you’re describing how it is supposed to work, but it’s not doing that for me for the most part.

Triggering company-complete does not offer completions for modules I haven’t imported yet.

Under no circumstances does it add a specifier for the import. That’s what I’m really interested in, as I need that to avoid warnings from purs.

psc-ide-add-import doesn’t seem to work: it asks me to type a module name, but always rejects whatever module I type with a quickly displayed error message (displayed too fast for me to read).

If you added import Data.Traversable to your file the plugin will no longer add a import Data.Traversable (traverse) as that would lead to warnings. If we’re going to debug this I’ll need some more information, so (setq psc-ide-debug t) and then do:

  1. Make sure you built your project succesfully at least once (pulp build)
  2. Run psc-ide-server-start and select the root of your project as the startup directory (the one which contains the output/ directory after you built
  3. Wait until you get the message about how many source files and modules have been loaded and let me know how many
  4. In a source file:
module Main where

import Prelude

import Effect (Effect)
import Effect.Console (log)
import Data.Traversable ()

main :: Effect Unit
main = pure unit

Try typing trav and get a completion for traverse

  1. Copy the content of the *psc-ide-server* buffer and paste it in your response
  2. Delete the import for Data.Traversable and try typing trav again this time completing by manually triggering completion
  3. Also give me the output for that

I think I see the misunderstanding.

Adding “import Data.Traversable ()” works; subsequent completions do add the specified import. I was under the mistaken impression that I first should add “import Data.Traversable” (without the empty parentheses).

And I thought I was testing manual completion of words like “trav”, but I guess I was using the wrong command for completion. Using “M-x company-complete” works for that as well.

Apologies. I’m getting back into programming after many years away—in the past we didn’t have IDE-like features in Emacs and I had a small range of tasks I ever had to do anyway, so I guess I need to familiarize myself more with how things are done these days. I appreciate the support as always.

1 Like

No worries, glad it all worked out!