首页 > 解决方案 > 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:


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 Bette Error Gem to open in VSCode.

Note: If the file does not exist then a new workspace is opened unfortunately.

标签: visual-studio-codewindows-subsystem-for-linux

解决方案


我发现此线程对于查找准确信息最有帮助:

https://github.com/microsoft/vscode/issues/108257

OP 几乎就在那里,但我想给出一个完整的纲要:

  • 无法通过stat远程文件路径来确定它是目录还是文件(注释)。
  • 因此,除非路径以:linenumber[:column](注释)结尾,否则所有路径都被视为目录
  • 您可以简单地附加:1到路径以确保将其视为文件。

以下是一些有效的 url 示例:

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/

推荐阅读