Reputation: 26313
I would like to generate clickable links in the exception handler of my web application that open the corresponding source code in vscode.
Visual Studio Code provides the vscode://file/
schema handler for this as documented under command line docs.
Unfortunately, this does not understand file links which are inside the Windows Subsystem for Linux.
Any idea how to generate links which open the code
editor on a particular file (+ line)?
Edit: It seems it doesn't currently work and it did not make the backlog:
https://github.com/microsoft/vscode/issues/111188
Edit 2:
What works is using the command line/bash to open the file:
code -g -r /path/to/file
There is way to build links that opens a remote workspace or folder:
vscode://vscode-remote/wsl+${WSL_DISTRO_NAME}/path/to/dir
Edit 3: Yeah! As mentioned in Ryan's answer there is now a way to open files by appending line numbers to the URL:
`vscode://vscode-remote/wsl+${WSL_DISTRO_NAME}/path/to/file.ext:1`
With this I can finally click links in the Better Error Gem to open in VSCode.
Note: If the file does not exist then a new workspace is opened unfortunately.
Upvotes: 4
Views: 1693
Reputation: 28380
I found this thread to be the most helpful for finding accurate information:
https://github.com/microsoft/vscode/issues/108257
The OP was pretty much there, but I wanted to give a full rundown:
stat
a remote file path to determine if it's a directory or a file (comment).:linenumber[:column]
(comment):1
to the path to make sure it's treated as a file.Here are some examples of urls which worked:
vscode://vscode-remote/wsl+Ubuntu-18.04/home/me/src/myexpressapp/app.js:1
vscode://vscode-remote/wsl+Ubuntu-18.04/home/me/src/myexpressapp/app.js:1:20
vscode://vscode-remote/wsl+Ubuntu-18.04/home/me/src/myexpressapp/app.js:20:1
vscode://vscode-remote/wsl+Ubuntu-18.04/home/me/src/myexpressapp/
Upvotes: 2