Remote development using VSCode tip

I am currently using a HPC to work on my Julia code. I normally use VS Code and the remote development tools to SSH into the HPC, however, I have had some issues with the Julia intellisense when on a remote system.

I have managed to get this working and wanted to share the steps here in case anyone else has the same issue.

The first problem is that the julia install has to be loaded using a “module load” command. Fortunately, you can bundle all of your commands into one file (I have called mine start_julia.sh):

#!/bin/bash

module load <INSERT MODULE PATH HERE>

julia --project=<INSERT PROJECT WORKING DIR HERE> -t 2 -e "using LanguageServer, LanguageServer.SymbolServer; runserver()" &
julia "$@"

I gave this file execution permissions with “chmod +x start_julia.sh”, and set the Julia environment path in the Julia extension settings to " ${workspaceFolder}/start_julia.sh". This seemed to work and now I have intellisense while editing files during remote development. Unfortunately, the inbuilt “Start REPL” command doesn’t seem to work, but I can work fine without it.

1 Like

That first Julia invocation should be unnecessary. Also, julia.executablePath should point towards your script, not julia.environmentPath.

1 Like

My mistake, I meant to write “executable” path instead. However, the language server failed to start without explicitly starting it before. This was the only way it managed to run. This may be due to how Julia was installed on the system, but I have no control over this.

You might be able to get some more info on what’s going on by navigating to Output > Julia Language Server.

When setting the julia.executablePath to my julia executable, the julia language plugin crashes, and gives the following output:

┌ Warning: Some Julia code in the VS Code extension crashed with
│   e = InvalidStateException("Channel is closed.", :closed)
└ @ Main ~/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/error_handler.jl:5
ERROR: InvalidStateException("Channel is closed.", :closed)
Stacktrace:
 [1] try_yieldto(undo::typeof(Base.ensure_rescheduled))
   @ Base ./task.jl:705
 [2] wait
   @ ./task.jl:764 [inlined]
 [3] wait(c::Base.GenericCondition{ReentrantLock})
   @ Base ./condition.jl:106
 [4] take_buffered(c::Channel{Any})
   @ Base ./channels.jl:389
 [5] take!
   @ ./channels.jl:383 [inlined]
 [6] get_next_message(endpoint::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint})
   @ JSONRPC ~/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/packages/JSONRPC/src/core.jl:197
 [7] macro expansion
   @ ~/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/packages/LanguageServer/src/languageserverinstance.jl:263 [inlined]
 [8] (::LanguageServer.var"#98#100"{LanguageServerInstance})()
   @ LanguageServer ./task.jl:406

When removing the explicit running of the language server, as posted originally, I get a different error, with the server crashing:

[Error - 4:06:12 PM] Starting client failed
Error: Unsupported server configuration {
    "run": {
        "command": null,
        "args": [
            "--startup-file=no",
            "--history-file=no",
            "--depwarn=no",
            "--project=/gpfs01/home/user/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/environments/languageserver",
            "main.jl",
            "/gpfs01/home/user/dev/julia/HPC",
            "--debug=no",
            "/tmp/vsc-jl-cr-552dc18e-d1cf-43c9-acbe-97cd49de6433",
            "",
            "/gpfs01/home/user/.vscode-server/data/User/globalStorage/julialang.language-julia"
        ],
        "options": {
            "cwd": "/gpfs01/home/user/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/languageserver",
            "env": {
                "JULIA_DEPOT_PATH": "/gpfs01/home/user/.vscode-server/data/User/globalStorage/julialang.language-julia/lsdepot/v1",
                "JULIA_LOAD_PATH": ":",
                "HOME": "/gpfs01/home/user",
                "JULIA_LANGUAGESERVER": "1"
            }
        }
    },
    "debug": {
        "command": null,
        "args": [
            "--startup-file=no",
            "--history-file=no",
            "--depwarn=no",
            "--project=/gpfs01/home/user/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/environments/languageserver",
            "main.jl",
            "/gpfs01/home/user/dev/julia/HPC",
            "--debug=yes",
            "/tmp/vsc-jl-cr-552dc18e-d1cf-43c9-acbe-97cd49de6433",
            "",
            "/gpfs01/home/user/.vscode-server/data/User/globalStorage/julialang.language-julia"
        ],
        "options": {
            "cwd": "/gpfs01/home/user/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/languageserver",
            "env": {
                "JULIA_DEPOT_PATH": "/gpfs01/home/user/.vscode-server/data/User/globalStorage/julialang.language-julia/lsdepot/v1",
                "JULIA_LOAD_PATH": ":",
                "HOME": "/gpfs01/home/user",
                "JULIA_LANGUAGESERVER": "1"
            }
        }
    }
}
	at /gpfs01/home/user/.vscode-server/extensions/julialang.language-julia-1.1.38/dist/extension.js:7:56727

I’m having a similar problem to @jmair. I think, if I get the below to work, it would also solve their problems.

I’m trying to get the executable path for julia using asdf. Here’s my zsh script.

#! /usr/bin/zsh
source ~/.zshrc
julia_exec=`asdf env julia which julia`
echo "${@:q}" > $HOME/debug.txt
$julia_exec "${@:q}"

This script is saved as ~/Documents/preferences/julia_remote.sh and this is what I set julia.executablePath to.

And here’s the output of debug.txt (with spaces replaced with line breaks for readability) after starting a REPL.

-i 
--banner=no 
--project=/home/davidlittle/Documents/work/projects/german_track 
/home/davidlittle/.vscode-server/extensions/julialang.language-julia-1.1.38/scripts/terminalserver/terminalserver.jl 
/tmp/vsc-jl-repl-6ba95a18-2b77-470c-955e-8b24f9084815 
/tmp/vsc-jl-cr-eb8996c6-6e9c-4254-a1ff-a984db1706d1 
USE_REVISE=true 
USE_PLOTPANE=true 
USE_PROGRESS=true 
DEBUG_MODE=undefined

This almost works. The language server successfully starts, and the command to start a REPL appears to work.

However, when I try to send code to the REPL, that command appears to be completely ignored.

Can you check the Julia Language Server and Julia Language Server trace outputs? There are (at least) two possible failure modes here: Either the LS is stuck or the REPL process doesn’t connect to the pipe properly.

Odd… my problem seems to have just “disappeared”. I just tried it again to get your requested outputs and everything just “worked”.

For what it’s worth, I did check the Language server trace and output earlier, when I was having an issue. Both suggested the language server was up and running, so the issue appeared to be a problem connecting to the pipe.

I haven’t used the REPL much (I tend to use my own, separate setup for REPL-age, in part because I haven’t bothered to figure this issue around asdf out), do you have to wait for the language server to be up and running before sending things to the REPL works? If so, that was probably the issue I was having.

Yes. There’s also a bug where indexing can sometimes block other LS requests, which frequently results in issues like the one you were seeing.

Great, thanks, I think this is mostly working for me then.

@jmair Does my script help you solve your problem? I ran into issues when I used $@ or "$@" alone, because one of the arguments to julia can be an empty string, which gets missed if you don’t re-quote the arguments. In zsh you can do ${@:q} to fix the arguments: I’m not familiar with the analogous bash expansion, so I’m not sure what the equivalent would be there.