使用远程容器时是否可以使用 DocumentLink 和 registerUriHandler?

Is it possible to use DocumentLink and registerUriHandler when using the remote containers?

我在远程容器中安装了 laravel goto config 扩展程序,每当我单击扩展程序生成的 link 并且应该跳转到另一个文件时 vscode 崩溃并重新启动

我创建了 github issue with the extension creator but author doesn't have any experience with remote extensions. In the github issue I also linked github repository,您可以使用它来重现该问题。请注意,而不是

./vendor/bin/sail up -d --build

你可以使用

docker-compose up -d --build

启动容器

容器启动后,您可以按照自述文件进行操作,也可以直接打开下面的示例 link,该示例 vscode

vscode://ctf0.laravel-goto-config/var/www/html/config/app.php?name

文件 /var/www/html/config/app.php 存在于 docker 容器中

我不太了解开发 vscode 扩展,但我设法发现该扩展在幕后使用 DocumentLinkregisterUriHandler 来生成 link 到文件并处理传入的 links。我什至下载了扩展并尝试调试问题,但我只在主机上直接使用 vscode 时才设法让调试器和断点工作。一旦我连接到远程容器,调试就不再在断点处停止,并且当我使用 vscode://... link

时 vscode 崩溃

是否可以使用 vscode://... 与远程容器一起打开文件?

编辑:

我发现了一个通过 links 打开文件的例子。在文件 .devcontainer/devcontainer.json 中,当我将鼠标悬停在 "dockerComposeFile": [...] 列表中的文件上时,我可以看到 link,当我单击它时,它将打开该文件。将鼠标悬停在 link 上显示以下值

vscode-remote://dev-container+2f55...../<absolute-path-to-file>

但这处理 link 与 vscode 而不是 registerUriHandler

我设法查明了问题所在。在分机中有一行

vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(path))

导致 vscode 重新加载,即使它是同一个文件夹。这只发生在远程容器中

将此行更改为

vscode.commands.executeCommand('vscode.open', vscode.Uri.file(path))

解决了问题。

命令 vscode.openFolder 应更改为 vscode.open

我找到了关于这些命令的更多信息in the docs