简体   繁体   中英

URL for opening vscode in file in WSL workspace

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:

    vscode://vscode-remote/wsl-${WSL_DISTRO_NAME}/path/to/dir

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:

  • It is not possible to stat a remote file path to determine if it's a directory or a file ( comment ).
  • Therefore, all paths are considered a directory unless the path ends in :linenumber[:column] ( comment )
  • You can simply append :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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM