Windows, Command for VS Code

I can’t get the console to find the code executable:

C:\Users\necka>code #works as expected

C:\Users\necka>julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.3.0-rc2.0 (2019-09-12)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

shell> code
ERROR: IOError: could not spawn `code`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:99
 [2] setup_stdios(::Base.var"##558#559"{Cmd}, ::Array{Any,1}) at .\process.jl:112
 [3] _spawn at .\process.jl:111 [inlined]
 [4] #run#569(::Bool, ::typeof(run), ::Cmd) at .\process.jl:439
 [5] run at .\process.jl:438 [inlined]
 [6] repl_cmd(::Cmd, ::REPL.Terminals.TTYTerminal) at .\client.jl:77
 [7] top-level scope at none:0

As you can see it cannot find the executable for vscode. I need it to be able to enable @edit to open the editor with the correct line information. Right now line information is not passed even though vscode is opened.

Have you tried the full path to code.exe?
For me it would be:

shell> "C:\Users\Oli\AppData\Local\Programs\Microsoft VS Code\Code.exe"

 [main 2019-10-14T14:47:51.409Z] update#setState idle
julia> ENV["JULIA_EDITOR"]=replace(raw"C:\Users\necka\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd", "\\"=>"/")
"C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd"

julia> @edit println(5)
ERROR: IOError: could not spawn `C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd 'E:\Programme\Julia\bin\..\share\julia\base\coreio.jl'`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:99
 [2] setup_stdios(::Base.var"##558#559"{Cmd}, ::Array{Any,1}) at .\process.jl:112
 [3] _spawn at .\process.jl:111 [inlined]
 [4] #run#569(::Bool, ::typeof(run), ::Cmd) at .\process.jl:439
 [5] run at .\process.jl:438 [inlined]
 [6] edit(::String, ::Int32) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\InteractiveUtils\src\editless.jl:80
 [7] edit(::Function, ::Any) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\InteractiveUtils\src\editless.jl:102
 [8] top-level scope at REPL[17]:1

then I get that problem.

How about run(`code`)? (Or the corresponding full-path invocation.) If I remember rightly, spawning commands from the “shell” mode on Windows has a spotty record.

Indeed works, but how do I get the @edit macro to execute that code?

julia> run(`"C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd" -g 'E:\Programme\Julia\bin\..\share\julia\base\coreio.jl:29'`)
Process(`'C:/Users/necka/AppData/Local/Programs/Microsoft VS Code/bin/code.cmd' -g 'E:\Programme\Julia\bin\..\share\julia\base\coreio.jl:29'`, ProcessExited(0))

Perhaps the function? From the manual:

InteractiveUtils.edit — Method.

edit(path::AbstractString, line::Integer=0)

Edit a file or directory optionally providing a line number to edit the file at. Return to the julia prompt when you quit the editor. The editor can be changed by setting JULIA_EDITOR , VISUAL or EDITOR as an environment variable.

You need some more escapes:

julia> ENV["JULIA_EDITOR"]=raw"C:\\Users\\Oli\\AppData\\Local\\Programs\\Microsoft\ VS\ Code\\Code.exe"

Now

julia> edit("test.jl")

open vscode for me.

2 Likes

This solves it! Thanks :slight_smile:
Though I hate that the Windows path variable is not considered when looking up executables… Thus I have to precisely say where each executable is that I might need and cannot just depend upon the executables available (on other systems where I have no control over the place).

The following is probably the better solution:

julia> ENV["JULIA_EDITOR"]="code.cmd"

this works here under Windows 10 and assumes that the path to VSCode is added to the PATH environment. This is an option during installation of VSCode and there is a note that you have to restart the PC.

julia> ENV["PATH"]
"...snippped...;C:\\Users\\oheil\\AppData\\Local\\Programs\\Microsoft VS Code\\bin"

In this path there are two files:

code
code.cmd

where only code.cmd can be started from within julia. If you try code in a windows cmd shell, the extenstions .exe, .cmd and .bat are automatically tested, and as there is code.cmd, this one is executed. Looking into code it is a unix/linux like shell script.

Though I hate that the Windows path variable is not considered when looking up executables… Thus I have to precisely say where each executable is that I might need and cannot just depend upon the executables available (on other systems where I have no control over the place).

So the path variable is actually considered, but my first attempt with code.exe, which is not in the bin folder, created the impression that it is not.
@rapus95 can you cross check and change the solution for future solution seekers?

3 Likes

Indeed that works. Thanks & nice to know!

1 Like

Though, at the very end the error I got is plain misleading as it states that code is not found rather than not being executable.