[英]How does VSCode's Remote Extension open files in my local editor through its internal terminal?
I use VSCode's remote development extension fairly regularly.我经常使用 VSCode 的远程开发扩展。 I can use the terminal in VS Code as if it were on my own machine, and even the code
command works correctly.我可以在 VS Code 中使用终端,就好像它在我自己的机器上一样,甚至code
命令也可以正常工作。 That is, when I'm in a remote VSCode session, I can type code path/to/some/file
and it will open another editor tab with that file.也就是说,当我在远程 VSCode session 中时,我可以键入code path/to/some/file
,它将打开另一个包含该文件的编辑器选项卡。 The terminal session and the file being opened are on the remote machine to which I've connected.终端 session 和正在打开的文件位于我连接的远程计算机上。
I have VSCode installed on the remote machine, and the code
executable is in my PATH
.我在远程机器上安装了 VSCode,可执行code
在我的PATH
中。 So my question is, how is this functionality implemented behind the scenes?所以我的问题是,这个功能是如何在幕后实现的? That is, how does VSCode know that when I type code path/to/some/file
it should open that file into another editor tab on my machine instead of trying to fire up VSCode on the remote machine?也就是说,VSCode 怎么知道当我键入code path/to/some/file
时,它应该将该文件打开到我机器上的另一个编辑器选项卡中,而不是尝试在远程机器上启动 VSCode?
Literally seconds after I wrote the question I found the answer.在我写完问题几秒钟后,我找到了答案。
If I run which code
in the terminal, it doesn't resolve to the usual VSCode executable, but instead it resolves to one located at $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin/code
.如果我在终端中运行which code
,它不会解析为通常的 VSCode 可执行文件,而是解析为位于$HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin/code
的代码。
If I echo $PATH
I can see that $HOME/.config/bin
and $HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin
has been appended to the beginning of the PATH
env var that my bash profile generates.如果我echo $PATH
,我可以看到$HOME/.config/bin
和$HOME/.vscode-server/bin/a5d1cc28bb5da32ec67e86cc50f84c67cc690321/bin
已附加到我的 bash 配置文件生成的PATH
环境变量的开头。
I assume this means that VSCode is executing bash with a different profile script that我假设这意味着 VSCode 正在使用不同的配置文件脚本执行 bash
I also assume that the injected code
executable is communicating with my local instance of VSCode in some way, instructing it to open the file in its editor.我还假设注入的code
可执行文件以某种方式与我的本地 VSCode 实例通信,指示它在其编辑器中打开文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.