Replies: 3 comments 1 reply
-
|
这个功能是不是还需要UI做适配? |
Beta Was this translation helpful? Give feedback.
1 reply
-
目前有一批 icon 在 https://opensumi.github.io/core/ , 可能需要进一步归类一下,之前有建过一个 Issue #216
这个看了一下我们界面可以在 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
#92 带来的变更: feat: breaking change: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
相关 PR: #92
相关 Issue: #34
摘要
本文主要会讲一下现在的 Terminal 启动设计,以及变更后的启动设计,其中会讲述变更关键点,变更原因。
本次变更属于 Breaking Change,会影响终端启动流程,启动终端的方法/参数,从同步启动变更为异步启动等的变更。
理由
这是 VS Code 插件 API 1.60.0 迭代 的其中一项任务。
新增 VSCode Contributions(点击展开)
新增 VSCode API 接口声明(点击展开)
该 API 的主要功能是:插件可以向 VSCode 注册一个 Terminal Profile,用户可以在 启动终端时的下拉框 中选择要启动的配置。

同时 VSCode 内部也将各种启动终端的逻辑收敛到了 Terminal Profile 内,比如说启动终端前检测用户本地可用的 Profiles 并保存下来:
目前 VSCode 还没有把所有启动流程迁往 Terminal Profile,如果用户在设置中什么都没设置的话,VSCode 会读取用户的旧配置或者自动检测可用 Shell 然后生成一个 Generated Profile 并启动它。
整体调用流程
插件注册 TerminalProfile 流程
贡献点
terminal首先插件需要在自己的

contributions里声明terminal.profiles:这里只是对启动的 Terminal 的一些描述(标题,icon)和 ID,还不需要填写要启动的 Shell 的路径等。
这里的 ID 需要全局唯一,之后需要通过插件 API 注册该 ID 要使用的 Profile(后文会详细描述 API)。
VSCode 将该贡献点保存到
TerminalContributionService中,会在TerminalProfileService._updateContributedProfiles时保存这些贡献进来的 Terminal Profile 描述,然后其他类可以通过TerminalProfileService.contributedProfiles拿到贡献进来的 Terminal Profile 描述列表用以展示。API
API 为
vscode.window.registerTerminalProfileProvider。参数1 为 Provider 的 id,要全局唯一,对应在
contributions.terminal.profiles中声明的 ID。参数2 为 该 Provider 模式的 interface 声明,要实现一个
provideTerminalProfile方法,该方法返回一个启动 Terminal 的配置。其中TerminalProfile是一个从内部暴露的 Class,入参是 TerminalOptions,用以声明 shellPath, args, env 等启动终端所需的信息。然后 VSCode 会将这个 Provider 保存下来,一路保存的调用路径为:
extHostTerminalService.ts#L658 -> mainThreadTerminalService.ts#L231 -> terminalProfileService.ts#L166
注意,这里的 Provider 不会被立刻调用获取里面的所有值。
当我们想启动一个由插件贡献的终端时,比如执行命令:

workbench.action.terminal.newWithProfile时:此时会调用
terminalService.showProfileQuickPick,然后在内部通过TerminalProfileQuickpick._createAndShow获取TerminalProfileService.availableProfiles和TerminalProfileService.contributedProfiles并展示,当我们选中某一项的时候,如果这一项为 Contributed Terminal,则调用TerminalService.createContributedTerminalProfile,同时会发出一个插件激活事件:onTerminalProfile:${id}。该函数中查询该 ID 注册的provideTerminalProfile回调函数,调用后拿到 Terminal Profile,然后启动。主要变更点
在前面的一些 PR 中,我们已经将内部启动 Terminal 的配置都收敛到了 IShellLaunchConfig 中,所以现在内部的启动流程如下:
用户按下终端 Tab,最后会通过
TerminalController._createClient来启动,在这里我们引入了一个新的ITerminalClientFactory2:主要变更点1为同步函数转为异步函数。
主要变更点2为
options参数,ITerminalClientFactory2中需要传入一个ICreateTerminalOptions,类型定义如下:该 options 描述了创建终端需要的信息,所有参数都为可选,如果 object 为空,则在之后的逻辑会自动获取默认 Profile。
然后通过 TerminalClientFactory.createClient2 创建终端,在 TerminalClient.init2 中获取:
然后通过
const launchConfig = this.convertProfileToLaunchConfig(options.config, this._workspacePath);将 Profile 转换为 LaunchConfig,随后启动。// 待补充
由主要变更引起的其他变更请看代码。
主要变更时间
某些 Deprecated 的时间:
暂定 2.17.0 后
尚未实现的点
需要我们自己绘制一些常用终端的图标。
Beta Was this translation helpful? Give feedback.
All reactions