How to configure VS Code extension with global `purs` and `spago` packages (via nvm)?

What is the recommended way to use the VS Code extension with global purs and spago packages, using nvm?

spago build, test etc. work all fine via CLI. With VS Code extension, a locally installed purs/spago package also works for me by adding the "purescript.addNpmPath": true settings.json entry.

With a global installation, let’s assume a path /home/bela/.nvm/versions/node/v14.13.0/bin to the binaries. Then error output from VS Code "Output -> IDE PureScript" shows, that the extension is missing above binary entry in PATH environment:

Starting IDE server
Using sources from psc-package/spago packages (PURS_IDE_SOURCES not set)
Couldn't find IDE server, check PATH. Looked for: purs in PATH: <paths omitted here>
PureScript Language Server started

.bashrc contains the usual lines to initialize nvm (also tried .profile):

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

My second attempt has been to give an explicit path to spago and purs binary:

"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",

At first the output seems promising:

PureScript Language Server started
[Info  - 6:57:33 PM] Resolved IDE server paths (npm-bin: false) from PATH of <...omitted again...> (1st is used):
[Info  - 6:57:33 PM] /home/bela/.nvm/versions/node/v14.13.0/bin/purs: 0.13.8

[Info  - 6:57:33 PM] Starting IDE server on port 15619 with cwd /home/bela/git/purescript-book/exercises/chapter2
Started IDE server (port 15619)
[Info  - 6:57:34 PM] [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)

Though the language server still does not work properly - things like “Go to definition” don’t work. The “PureScript: Build” command now emits an error. Output panel:

[Info  - 7:04:28 PM] Resolved build command (1st is used): 
[Info  - 7:04:28 PM] /home/bela/.nvm/versions/node/v14.13.0/bin/spago: 0.16.0

[Info  - 7:04:28 PM] Running build command: /home/bela/.nvm/versions/node/v14.13.0/bin/spago build --purs-args --json-errors
[Info  - 7:04:28 PM] e[31m[error] e[0mExecutable was not found in path: "purs"e[0m

[Error - 7:04:28 PM] Problem running build: didn't find JSON output

The line Executable was not found in path: "purs" might hint a bug in the extension. I would expect here the full explicit purs path, not the default one.

Has anyone experienced similar issues? Thanks in advance!

A workaround for nvm is to create symbolic links inside a directory already contained in PATH. E.g.:

cd ~/bin # assumed to be in PATH
ln -s /home/bela/.nvm/versions/node/v14.13.0/bin/purs .
# same for spago, purty

Though it would be nice, if the VS Code extension would respect explicit paths for purs and spago given in settings.json.

1 Like

Here’s a video walkthrough of setting up tooling (including nvm+vscode) on a fresh Ubuntu install.

1 Like

Thanks! Will gonna look through it.

Update 1:
@milesfrain your video actually helped to solve the issue, well done :+1: Weirdly, something seemed to be messed up with my VS Code configuration. A separate clean installation did get the job done, after which the main installation also decided to work again… sometimes it is better to not question things :wink:

Update 2:
It seems to make a difference, if a portable or system (like with snap) Code installation exists. snap also works for me on a vanilla Ubuntu distro out of the box, as shown in the video. On my main system, I got a portable installation, which messes up the PS IDE extension.

In summary: Above workaround might be helpful with a portable installation. Manually set purs and spago executable paths in settings.json resulted in extension errors (bug?).

Update 3:
OK, got this cleared now. If you have a portable installation, make sure that Exec in your Code .desktop file points to VSCode-linux-x64/code (not VSCode-linux-x64/bin/code). Alternatively, adjust the bin/code script to source ~/.nvm/nvm.sh, so environment variables get set.