简体   繁体   English

URL 用于在 WSL 工作区的文件中打开 vscode

[英]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.我想在我的 web 应用程序的异常处理程序中生成可点击的链接,在 vscode 中打开相应的源代码。

Visual Studio Code provides the vscode://file/ schema handler for this as documented under command line docs . Visual Studio Code 为此提供了vscode://file/架构处理程序,如命令行文档中所述。

Unfortunately, this does not understand file links which are inside the Windows Subsystem for Linux.不幸的是,这不理解 Linux 的 Windows 子系统内的文件链接。

Any idea how to generate links which open the code editor on a particular file (+ line)?知道如何生成在特定文件(+ 行)上打开code编辑器的链接吗?


Edit: It seems it doesn't currently work and it did not make the backlog:编辑:它似乎目前不起作用,也没有积压:

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


Edit 2:编辑2:

  • What works is using the command line/bash to open the file:有效的是使用命令行/bash打开文件:

    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 https://github.com/microsoft/vscode/issues/108257

The OP was pretty much there, but I wanted to give a full rundown: OP 几乎就在那里,但我想给出一个完整的纲要:

  • It is not possible to stat a remote file path to determine if it's a directory or a file ( comment ).无法stat远程文件路径以确定它是目录还是文件( 注释)。
  • Therefore, all paths are considered a directory unless the path ends in :linenumber[:column] ( comment )因此,除非路径以:linenumber[:column]注释)结尾,否则所有路径都被视为目录
  • You can simply append :1 to the path to make sure it's treated as a file.您可以简单地 append :1到路径以确保将其视为文件。

Here are some examples of urls which worked:以下是一些有效的 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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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