nwolverson / vscode-ide-purescript

PureScript IDE support for VS Code
https://marketplace.visualstudio.com/items/nwolverson.ide-purescript
MIT License
188 stars 34 forks source link

Custom paths for `purs` and `spago` are not respected #159

Open bela53 opened 3 years ago

bela53 commented 3 years ago

Providing a custom path to purs and spago executables makes the extension not work properly anymore (e.g. Go to definition in a .purs file).

settings.json:

{
  "purescript.pursExe": "/home/bela/.nvm/versions/node/v14.13.0/bin/purs",
  "purescript.buildCommand": "/home/bela/.nvm/versions/node/v14.13.0/bin/spago build --purs-args --json-errors",
}

Output panel -> PureScript IDE log, when navigated to first .purs file:

[Info  - 7:08:19 AM] Resolved IDE server paths (npm-bin: false) from PATH <... paths omitted here ...> (1st is used):
[Info  - 7:08:19 AM] /home/bela/.nvm/versions/node/v14.13.0/bin/purs: 0.13.8

[Info  - 7:08:19 AM] Starting IDE server on port 15091 with cwd /home/bela/git/purescript-book/exercises/chapter2
Started IDE server (port 15091)
[Info  - 7:08:20 AM] [Info] cachedb was changed from: Nothing, to: Just 2020-10-17 16:06:17.151016188 UTC @(main:Command.Ide app/Command/Ide.hs:205:25)

I also tried spago build via CLI followed by PureScript: Restart/Reconnect purs IDE Server, which now has no effect. Triggering PureScript: Build directly from IDE emits following error:

[Info  - 7:15:49 AM] Resolved build command (1st is used): 
[Info  - 7:15:49 AM] /home/bela/.nvm/versions/node/v14.13.0/bin/spago: 0.16.0
[Info  - 7:15:49 AM] Running build command: /home/bela/.nvm/versions/node/v14.13.0/bin/spago build --purs-args --json-errors
[Info  - 7:15:49 AM] [error] Executable was not found in path: "purs"
[Error - 7:15:49 AM] Problem running build: didn't find JSON output

The next-to-last line hints, that the custom purescript.pursExe path is not respected and searches purs in PATH.

PS: Hopefully, my interpretation of above settings to set custom purs/spago paths is correct so far.

Original discourse post

nwolverson commented 3 years ago

The pursExe config is only used for the extension itself. If your build command is spago, then spago also uses the purs in its path to build - you should ensure that spago is getting the correct PATH to build there.

I don't think your build outside of the IDE is related to purs version etc - but there is no info here to determine otherwise. Possibly the versions are not matching and you're getting an externs version issue though

bela53 commented 3 years ago

I see. What about telling purescript.buildCommand, if purescript.pursExe executable is set explicitly? Like prepending the pursExe directory to PATH, when spago is invoked via extension:

PATH="${<parent dir of 'purescript.pursExe'>}:$PATH" /path/to/spago build --purs-args --json-errors

Alternative: The purescript.buildCommand string might be parsed for any prefixed command environment variables.

IMO that would make sense, as the user already requested to use a custom purs version.

nwolverson commented 3 years ago

Not sure how I feel about that, it's a bit of a niche case and I'd find that behaviour surprising - but hard to imagine a situation where it would go far wrong either.

(at least for now) I'd recommend either launching vscode with the correct PATH, or extracting the build command to a shell script or makefile if it starts becoming problematic - just make sure the json errors are passed through.