VSCode setting for setting editor (for use with @edit)

I wanted julia to automatically figure out and set the editor for use with @edit depending on if I was in a terminal (use vim) or if I was in vscode julia repl (use vscode).

I saw that in julia vscode settings there is a part about

Julia: Editor
Command to open files from the REPL (via setting the JULIA_EDITOR environment variable). Defaults to code / code-insiders if unset.

so I added the line "julia.editor": "code" to my settings.json while having ENV["JULIA_EDITOR"]="vim" in my startup.jl and expected this to mean that in a standalone terminal I would get vim while in vscode julia repl it would overwrite this and set it to code. But it seems like both are just opening in vim still, and checking ENV["JULIA_EDITOR"] in the vscode repl it shows vim, so I guess I misunderstood how this works?

I came up with some simple workaround using my startup.jl which just checks if there are any vscode related env vars and if so we set editor to vscode, otherwise it is vim.

if isempty(filter(contains("VSCODE"), keys(ENV)))
    ENV["JULIA_EDITOR"] = "vim"
else
    ENV["JULIA_EDITOR"] = "code"
end

This seems to work fine locally, but I also work on remote instances quite a bit where my startup.jl isn’t always present.

On remote instances it seems like it is not working at all even if it seems to set the editor to some default value that seems reasonable, but ignoring my setting "julia.editor": "code" (which might have been wrong here, but still it is ignored?).

julia> @edit 1+1

julia> /opt/julia-1.6.5/share/julia/base/int.jl:1
# This file is a part of Julia. License is MIT: https://julialang.org/license
^

SyntaxError: Invalid or unexpected token
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

julia> ENV["JULIA_EDITOR"]
"\"/home/ubuntu/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/node\""

I assume that has to do with it not being a “real” installation or something, just some remote node, but if it was possible to make this work it would be convenient.

Have I gotten the wrong setting, is it called something else than julia.editor? How am I supposed to figure out the exact name in general, the text doesn’t mention what the name is?

I am using Windows Subsystem for Linux 1 (WSL1) and VSCode. I was getting the same error you show above any time I tried to use @edit in the REPL started from the integrated terminal. Also, when I was trying to right-click on the flame graph output of ProfileView. I just added "julia.editor": "code" to my settings.json and now it is working.

Realised that the "julia.editor": "code" setting was run before the startup.jl script, which I guess makes sense. This meant that ENV["JULIA_EDITOR"] was set to code first, but then startup.jl overwrote it with vim.

I instead set my system editor (EDITOR and VISUAL in linux) to be vim, and didn’t set anything in startup.jl or VSCode. This seem to result in the same behaviour as the manual if ... else ... in the startup.jl, but feels cleaner.

I also realised that the problem on ssh remotes was a known bug, so just have to hope it gets fixed :slight_smile: