简体   繁体   English

VSCode 的远程扩展如何通过其内部终端在我的本地编辑器中打开文件?

[英]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

  1. Sources my usual bash profile来源我通常的 bash 配置文件
  2. Creates the directories above and copies some helper programs into them创建上面的目录并将一些帮助程序复制到其中
  3. Modifies my path to include these directories修改我的路径以包含这些目录

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.

相关问题 如何在 VScode 中从远程 session 打开本地终端? - How do i open a local terminal from a remote session in VScode? 如何通过vscode扩展名API打开一个*.ipynb文件编辑器? - How to open a *.ipynb file editor through vscode extension API? 在 VScode 上使用远程 SSH 扩展后,我可以通过在终端中使用 nano 来编辑文件,但无法通过 VS 代码编辑器进行编辑 - After using the remote SSH extension on VScode, I can edit files by using nano in the terminal but cannot edit via the VS code editor 本地 vscode 客户端如何操作远程机器中的文件? - How does the local vscode client manipulate files in the remote machine? 如何在VScode扩展中打开新的终端标签? (拆分终端) - How do I open a new terminal tab in my VScode extension? (split terminal) 如何通过终端在 vscode 中打开文件? - how to open a file in vscode through a terminal? 如何从集成终端在 vscode 中打开文件 - how to open files in vscode from integrated terminal nginx 不使用 VSCode 远程容器扩展(docker compose)打开本地主机 - nginx does not open localhost with VSCode Remote Containers Extension (docker compose) 如何使用 VSCode 的远程开发扩展在容器外的 Docker 容器中打开文件 - How to open files in a Docker container outside of container using the Remote Development extension for VSCode 如何从vscode扩展打开非集成终端window? - How to open non integrated terminal window from vscode extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM