探索基于VSCode的远程开发插件,进行远程指令和本地指令的运行

news2024/9/21 20:36:33

需求

最近在研究VSCode的插件的时候,使用了VSCode的远程开发套件,Remote - SSH可以在本地的VSCode上登录远程机器,打开远程机器的某个文件夹进行开发。并且在开发过程中,能够使用几乎所有的VSCode插件。
当你使用这个插件链接到远程机器,并打开一个工作目录时,那么终端的命令是默认在当前的工作目录,
需求是,当是远程工作目录时,也能够够创建一个终端,而这个终端的工作目录是本地工作目录。
这样当用户连接到远程工作目录时,就能够随意地在本地或者远程执行命令。

探索

其实这个需求很简单,但是涉及到上下文,两个终端的工作空间,需要深入地调研VSCode是否在支持。
在使用Remote - SSH连接远程时,会刷新一下当前窗口,我猜测是刷新当前的工作目录,以及一些上下文,和变量,环境变量,而且在打开终端时,默认就是当前的远程工作目录,使用cd命令无法进入本地机器目录。

在VSCode插件中,创建重点使用vscode.window.createTerminal() 来创建终端,
传入的参数类型如下:

/**
 * Value-object describing what options a terminal should use.
 */
export interface TerminalOptions {
    /**
     * A human-readable string which will be used to represent the terminal in the UI.
     */
    name?: string;

    /**
     * A path to a custom shell executable to be used in the terminal.
     */
    shellPath?: string;

    /**
     * Args for the custom shell executable. A string can be used on Windows only which allows
     * specifying shell args in [command-line format](https://msdn.microsoft.com/en-au/08dfcab2-eb6e-49a4-80eb-87d4076c98c6).
     */
    shellArgs?: string[] | string;

    /**
     * A path or Uri for the current working directory to be used for the terminal.
     */
    cwd?: string | Uri;

    /**
     * Object with environment variables that will be added to the editor process.
     */
    env?: { [key: string]: string | null | undefined };

    /**
     * Whether the terminal process environment should be exactly as provided in
     * `TerminalOptions.env`. When this is false (default), the environment will be based on the
     * window's environment and also apply configured platform settings like
     * `terminal.integrated.windows.env` on top. When this is true, the complete environment
     * must be provided as nothing will be inherited from the process or any configuration.
     */
    strictEnv?: boolean;

    /**
     * When enabled the terminal will run the process as normal but not be surfaced to the user
     * until `Terminal.show` is called. The typical usage for this is when you need to run
     * something that may need interactivity but only want to tell the user about it when
     * interaction is needed. Note that the terminals will still be exposed to all extensions
     * as normal.
     */
    hideFromUser?: boolean;

    /**
     * A message to write to the terminal on first launch, note that this is not sent to the
     * process but, rather written directly to the terminal. This supports escape sequences such
     * a setting text style.
     */
    message?: string;

    /**
     * The icon path or {@link ThemeIcon} for the terminal.
     */
    iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;

    /**
     * The icon {@link ThemeColor} for the terminal.
     * The `terminal.ansi*` theme keys are
     * recommended for the best contrast and consistency across themes.
     */
    color?: ThemeColor;

    /**
    * The {@link TerminalLocation} or {@link TerminalEditorLocationOptions} or {@link TerminalSplitLocationOptions} for the terminal.
    */
    location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions;

    /**
     * Opt-out of the default terminal persistence on restart and reload.
     * This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled.
     */
    isTransient?: boolean;
}

该参数可以设置终端的名称,自定义的shell执行器的路径,执行shell的参数,工作目录,环境变量。
最令人在意的就是cwd这个参数,工作目录。经过测试,该参数默认就是当前的工作目录。
但你可以设置工作目录为当前工作目录的上级,或下级。比如你的工作目录是windows下的/d/Person/5000目录。你可以这样创建终端,将工作目录中的子级当做终端的工作目录。

const terminal = vscode.window.createTerminal({
  name: 'pmc',
  cwd: 'd:/\/Person/\/5000/\/icon/\/h3c',
});
terminal.sendText('node -v');
terminal.show();

也可以这样使用当前工作目录的上级当做终端的工作目录,

const terminal = vscode.window.createTerminal({
  name: 'Fizz',
  cwd: 'd:/\/download',
});
terminal.sendText('node -v');
terminal.show();

以上都是能够正常执行的。

在这里插入图片描述

在这里插入图片描述

但是当vscode链接到远程工作目录后,该方法就不能正常执行了。
在这里插入图片描述
在这里插入图片描述

这里我存在两个问题,

  • 创建中的cwd参数到底支不支持本地机器的路径?
  • 如何支持,那路径应该如何写?

目前还没找到答案,我想最终答案肯定是不支持的,如果支持这样重要的特性,官方一定会在文档中注明的。但我翻了很多文档却没找到。

在查询文档时也看到了很多额外的东西,不管有没有用,都记录一下吧。

远程与本地的文件同步

Mount the remote filesystem using SSHFS.

Sync files to/from the remote host to your local machine using rsync.

使用UI插件来运行本地指令的文档链接
https://code.visualstudio.com/api/advanced-topics/remote-extensions#known-issues
但我没有实验成功

相关链接

https://code.visualstudio.com/api/advanced-topics/remote-extensions#known-issues
在这里插入图片描述

https://code.visualstudio.com/api/advanced-topics/extension-host

https://code.visualstudio.com/docs/remote/ssh#_working-with-local-tools

Working with local tools

The Remote - SSH extension does not provide direct support for sync’ing source code or using local tools with content on a remote host. However, there are two ways to do this using common tools that will work with most Linux hosts. Specifically, you can:

Mount the remote filesystem using SSHFS.
Sync files to/from the remote host to your local machine using rsync.
SSHFS is the most convenient option and does not require any file sync’ing. However, performance will be significantly slower than working through VS Code, so it is best used for single file edits and uploading/downloading content. If you need to use an application that bulk reads/write to many files at once (like a local source control tool), rsync is a better choice.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/740222.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Python(三):Python开发环境搭建

❤️ 专栏简介:本专栏记录了我个人从零开始学习Python编程的过程。在这个专栏中,我将分享我在学习Python的过程中的学习笔记、学习路线以及各个知识点。 ☀️ 专栏适用人群 :本专栏适用于希望学习Python编程的初学者和有一定编程基础的人。无…

mybatis 注解方式操作 sql

前言:注解的方式在某些查询的时候还是比较方便的 mybatis注解配置 mapUnderscoreToCamelCase 配置Select 注解Insert 注解Delete 注解 和 Update 注解Provider 注解 mapUnderscoreToCamelCase 配置 别名设置,mapUnderscoreToCamelCase 配置 配置可以将 带下划线 sq…

python车牌识别

识别结果 蓝牌 绿牌 黄牌 环境 python:3.9\opencv:4.5.1 环境安装 pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple pip3 install hyperlpr -i https://pypi.tuna.tsinghua.edu.cn/simple 修改 cd /Library/Frameworks/Python.framework/Versi…

巧用word 邮件合并批量输出报告

在实际调查中,往往遇到很多统计信息要单独生成调查报告。word 邮件合并就能很好的帮助我们快速实现批量产出报告。 具体案例如下: 目前入河排污口调查正在如火如荼开展,我们排查收集了大量信息,整理为表格。 要将这些表格输出为…

算法训练营第三十四天||1005.K次取反后最大化的数组和 ● 134. 加油站● 135. 分发糖果

1005.K次取反后最大化的数组和 自己思路:自己想的就是把数组按从小到大排序,然后把前k小的数字都取反,然后相加起来,这个思路没有考虑到前k个小的数字中不全是负数的情况,比如这个数组全大于0的数,这种情况…

Redis熟悉到精通:开篇

文章目录 要点使用缓存技术的目的需要缓存机制的数据种类Redis学习资料 要点 掌握数据结构和缓存的基本使用方法; 掌握支撑Redis实现高可靠、高性能的技术; 高可靠 Redis之所以可以实现高可靠、高性能,和它的持久化机制、主从复制机制、哨兵、故障自动恢复、切片集…

模拟对讲机会被数字对讲机取代吗?

经常在网上看到有网友讨论,模拟对讲机是不是快被淘汰了,要被数字对讲机取代了。其实不管是模拟还是数字对讲机,都有其各自的优势,数字对讲要想全面取代模拟对讲,还是有些为时尚早。 传统的模拟对讲机主要是将语音、信…

用Python监控并分析城市空气质量

大家好,同为发展中国家,印度也受到空气质量问题的困扰,本文就以印度的城市为例进行数据分析。使用简单的Python代码,分析城市空气质量及其每天在全国范围内(即印度水平)的排名。 在开始之前,先介…

(转载)极限学习机(extreme learning machine, ELM)的回归拟合及分类(matlab实现)

单隐含层前馈神经网络(single-hidden layer feedforward neural network,SLFN)以其良好的学习能力在许多领域中得到了广泛的应用。然而,传统的学习算法(如BP算法等)固有的一些缺点,成为制约其发展的主要瓶颈。前馈神经网络大多采用梯度下降方法&#xff…

阿里云服务器安装mysql并用idea连接

文章目录 前言一.购置阿里云服务器——不定时二.在服务器安装mysql——用时5分钟三.打开服务器mysql的端口——用时2分钟1.找到安全组2.打开默认mysql的3306端口 三.打开idea连接数据库——5分钟四.总用时大约20分钟 前言 记录第一次通过idea连接安装在服务器上的数据库——排错…

在vite创建的vue3项目中加载Cesium世界街道地图的底图

在vite创建的vue3项目中加载Cesium世界街道地图的底图 使用vite创建vue3项目 npm create vitelatestcd到创建的项目文件夹中 npm install安装Cesium npm i cesium vite-plugin-cesium vite -D配置 vite.config.js文件 import { defineConfig } from vite import vue from vitej…

ETHERCAT转PROFINET协议网关连接ethercat网线接口定义

大家好,今天我要给大家介绍一款神奇的产品,YC-PN-ECT,它是一款 PROFINET 从站功能的通讯网关,可以将 PROFINET 网络和 ETHERCAT 网络连接起来,让不同厂家的 PLC 能够互相通信,真是太酷了! PEO…

T100新增栏位,配置ACC作业并提供开窗作业维护

需求分析:将xxxx作业中的一个界面新增一个栏位,并提供开窗功能进行资料的维护。 一、ACC自适应配置文档开发 1.1 azzi650 注册应用分类码【ACC】 新增一个资料 应用分类码【数字】说明 填写文字说明作业编号:这个时候是空的作业名称:也是空的1.2 azzi910 作业基本维护 这个…

做爬虫如何选择Python和C语言

目录 优劣势分析 Python 进行爬虫的优势: Python 进行爬虫的劣势: C进行爬虫的优势: C进行爬虫的劣势: 示例代码说明 Python 示例代码: C语言 示例代码: 怎么选择 优劣势分析 Python 进行爬虫的优…

Java设计模式之创建型-原型模式(UML类图+案例分析)

一、基础概念 通过复制已有对象作为原型,通过复制该原型来返回一个新对象,而不是新建对象,说白了就是不断复制相同的对象罢了。 二、UML类图 三、角色分析 角色描述抽象原型类规定了具体的原型对象必须实现的clone()方法具体原型类实现抽象…

倒计时1天!LeaTech全球CTO领导力峰会TVP四周年庆典即将开幕

引言 3 月 4 日,上海扬子江丽笙精选酒店,LeaTech 全球 CTO 领导力峰会暨腾讯云 TVP 四周年、CTO 训练营校友联合庆典即将开幕。本次 LeaTech 全球 CTO 领导力峰会以“寻光之旅”为主题,腾讯云 TVP 携手 51CTO,联合邀请业内资深领袖…

C# winform界面显示3D点云图像(halcon+VTK)

前一段时间研究了下halcon里的3d算法,想着把3d图像显示在C#编写的软件界面上,试了下halcon的控件,没成功。后来学习了一点VTK的知识,实现了3d图像的显示,可旋转,平移,缩放观察,当然也…

为什么国内做不出好的3A游戏?

个人觉得原因如下: 主要原因: 市场需求和消费观念:国内游戏市场对游戏类型和风格有着自身的特点和需求。一些热门游戏类型,如多人在线游戏、手机游戏等,相对于传统的3A游戏更受国内玩家欢迎。这可能导致国内游戏公司…

QInputDialog 不显示ok或cancel按钮bug

今天遇到一个奇怪问题,就是调用 QInputDialog::getText去获取输入文本,但是无法显示系统ok和cancel按钮,我记得之前是可以的,于是我回退上一个版本是正常,于是对比两个版本代码,发现,自己重写 Q…

【人工智能】贝叶斯网络、概率图模型、全局语义、因果链、朴素贝叶斯模型、枚举推理、变量消元

文章目录 频率学派 vs. 贝叶斯学派贝叶斯学派Probability(概率):独立性/条件独立性:Probability Theory(概率论):Graphical models (概率图模型)什么是图模型(Graphical Models&…