Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support VSCode API: env.onDidChangeShell #4223

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

bk1012
Copy link
Member

@bk1012 bk1012 commented Dec 12, 2024

Types

  • 🎉 New Features

Background or solution

Changelog

Summary by CodeRabbit

  • 新特性

    • 新增事件 onDidChangeShell,用于通知终端使用的默认 shell 变化。
    • 增加 createTelemetryLogger 函数,支持创建符合用户设置的遥测记录器。
    • 增强终端配置的响应能力,允许动态更新终端配置文件。
    • 新增事件 onDidChangeDefaultShell,用于监听默认 shell 配置的变化。
  • 文档

    • 更新 shell 常量的注释,以反映设置的变化。

@opensumi opensumi bot added the 🎨 feature feature required label Dec 12, 2024
@bk1012 bk1012 changed the title feat: support VSCode API: env.onDidChangeShell WIP: feat: support VSCode API: env.onDidChangeShell Dec 12, 2024
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > glob@7.2.3: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"

Walkthrough

此拉取请求引入了一系列与终端事件处理相关的更改。主要包括在 IExtHostTerminal 接口中添加了新的事件 onDidChangeShell,以通知终端使用的外壳变化。此外,createEnvApiFactory 函数的返回值也进行了修改,使其能够响应外壳变化。ExtHostTerminal 类中增加了新的事件发射器和方法,以跟踪外壳路径的变化。最后,TerminalProfileService 类整合了对用户偏好变化的监听,以动态更新终端配置。

Changes

文件路径 更改摘要
packages/extension/src/common/vscode/terminal.ts 新增事件:onDidChangeShell: Event<string> 在接口 IExtHostTerminal 中。
packages/extension/src/hosted/api/vscode/env/envApiFactory.ts 更新 createEnvApiFactory 函数的 onDidChangeShell 返回值,从 Event.None 改为 exthostTerminal.onDidChangeShell
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts 新增私有属性 shell,事件发射器 onDidChangeShellEvent,方法 get onDidChangeShell(),更新 $acceptDefaultProfile 方法以触发该事件。
packages/terminal-next/src/browser/terminal.profile.ts 新增私有方法 setupPreferenceListener(),以监听偏好变化并更新终端配置,新增发射器 onDidChangeDefaultShellEmitter
packages/types/vscode/typings/vscode.env.d.ts 新增常量 onDidChangeShell: Event<string> 和函数 createTelemetryLogger,更新 shell 常量的注释。
packages/extension/src/browser/vscode/api/main.thread.terminal.ts 新增方法 onDidChangeDefaultShell(shell: string),以处理默认外壳变化。
packages/terminal-next/tests/browser/mock.service.ts 新增方法 onDidChangeDefaultShell(),以监听默认外壳配置的变化。
packages/terminal-next/src/common/profile.ts 新增事件 onDidChangeDefaultShell: Event<string> 在接口 ITerminalProfileService 中。

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
packages/terminal-next/src/browser/terminal.profile.ts (2)

89-96: 建议添加资源清理逻辑!

preference 监听器的实现逻辑正确,但建议在服务销毁时清理监听器以防止内存泄漏。

 private setupPreferenceListener() {
-  this.preferenceService.onPreferenceChanged((event: PreferenceChange) => {
+  const disposable = this.preferenceService.onPreferenceChanged((event: PreferenceChange) => {
     if (event.preferenceName === TerminalSettingsId.Type) {
       this.refreshAvailableProfiles();
     }
   });
+  this.addDispose(disposable);
 }

90-93: 建议添加错误处理!

在刷新配置文件过程中可能发生错误,建议添加错误处理逻辑。

 this.preferenceService.onPreferenceChanged((event: PreferenceChange) => {
   if (event.preferenceName === TerminalSettingsId.Type) {
-    this.refreshAvailableProfiles();
+    try {
+      this.refreshAvailableProfiles();
+    } catch (error) {
+      this.logger.error('刷新终端配置文件失败:', error);
+    }
   }
 });
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (1)

375-382: 配置文件更新处理逻辑完善!

实现了以下功能:

  • 正确比较新旧配置文件路径
  • 仅在路径实际变化时触发事件
  • 通过避免不必要的事件触发优化了性能

建议为 automation 相关的注释添加英文翻译。

-    // 还不知道这个 automation 有啥用
+    // TODO: Need to investigate the purpose of automation profile
+    // 还不知道这个 automation 有啥用
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99ba1a3 and 4264951.

📒 Files selected for processing (5)
  • packages/extension/src/common/vscode/terminal.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/env/envApiFactory.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (3 hunks)
  • packages/terminal-next/src/browser/terminal.profile.ts (4 hunks)
  • packages/types/vscode/typings/vscode.env.d.ts (2 hunks)
🔇 Additional comments (6)
packages/extension/src/hosted/api/vscode/env/envApiFactory.ts (1)

118-118: 实现正确且符合 VSCode API 规范!

该实现正确地将终端 shell 变更事件转发到环境 API 中。

packages/extension/src/common/vscode/terminal.ts (1)

66-67: 接口定义清晰且类型准确!

在 IExtHostTerminal 接口中添加 onDidChangeShell 事件定义,类型声明准确,位置合理。

packages/types/vscode/typings/vscode.env.d.ts (2)

72-76: 事件声明正确且文档完整!

事件声明和文档注释符合 VSCode API 规范。


78-85: 遥测日志器创建函数实现完整!

函数声明和参数文档符合 VSCode API 规范。

packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (2)

58-58: 事件发射器声明正确!

使用了标准的事件发射器模式,并正确设置为私有成员。


176-178: 事件访问器实现正确!

遵循标准的事件访问器模式,提供对私有事件的公共访问。

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 52.17391% with 11 lines in your changes missing coverage. Please review.

Project coverage is 53.99%. Comparing base (99ba1a3) to head (b2c5696).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...tension/src/hosted/api/vscode/ext.host.terminal.ts 40.00% 5 Missing and 1 partial ⚠️
...ion/src/browser/vscode/api/main.thread.terminal.ts 33.33% 2 Missing ⚠️
...ages/terminal-next/src/browser/terminal.profile.ts 77.77% 1 Missing and 1 partial ⚠️
...tension/src/hosted/api/vscode/env/envApiFactory.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4223   +/-   ##
=======================================
  Coverage   53.99%   53.99%           
=======================================
  Files        1616     1616           
  Lines       98108    98129   +21     
  Branches    20077    20088   +11     
=======================================
+ Hits        52972    52987   +15     
- Misses      37498    37502    +4     
- Partials     7638     7640    +2     
Flag Coverage Δ
jsdom 49.58% <52.17%> (+<0.01%) ⬆️
node 15.54% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bk1012 bk1012 force-pushed the feat/support-env.onDidChangeShell branch from 4264951 to a082563 Compare December 12, 2024 09:40
@bk1012 bk1012 changed the title WIP: feat: support VSCode API: env.onDidChangeShell feat: support VSCode API: env.onDidChangeShell Dec 12, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
packages/extension/src/common/vscode/terminal.ts (1)

66-69: 接口更改符合预期!

新增的 onDidChangeShell 事件和 $setShell 方法完全符合 VSCode API 的设计模式。建议为这两个新增的接口成员添加 JSDoc 注释,以便更好地说明其用途和参数类型。

建议添加如下文档注释:

+  /**
+   * 当终端的 shell 发生变化时触发的事件
+   */
  onDidChangeShell: Event<string>;

+  /**
+   * 设置终端的 shell
+   * @param shell 新的 shell 路径
+   */
  $setShell(shell: string);
packages/terminal-next/src/common/profile.ts (1)

24-24: 接口添加合理!

ITerminalProfileService 中添加 onDidChangeDefaultShell 事件是合适的,这与服务的职责相符。建议添加文档注释以说明事件的触发时机和参数含义。

建议添加如下文档注释:

+  /**
+   * 当默认 shell 配置发生变化时触发的事件
+   * @event
+   */
  onDidChangeDefaultShell: Event<string>;
packages/terminal-next/__tests__/browser/mock.service.ts (1)

420-422: 建议增强模拟实现!

当前的模拟实现过于简单。为了更好地支持测试场景,建议实现一个完整的事件发射器。

建议修改实现如下:

+  private readonly _onDidChangeDefaultShell = new Emitter<string>();
+
-  onDidChangeDefaultShell() {
-    return new Disposable();
-  }
+  onDidChangeDefaultShell = this._onDidChangeDefaultShell.event;

这样的实现将允许测试用例触发 shell 变更事件并验证相关行为。

packages/extension/src/browser/vscode/api/main.thread.terminal.ts (1)

129-133: 代码实现正确,建议增加错误处理

事件订阅的实现逻辑正确,但建议考虑在调用 proxy.$setShell 时添加错误处理。

建议修改为:

 this.disposable.addDispose(
   this.profileService.onDidChangeDefaultShell((shell: string) => {
+    try {
       this.proxy.$setShell(shell);
+    } catch (error) {
+      this.logger.error('Failed to set shell', error);
+    }
   }),
 );
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (2)

189-194: 建议增加空值处理

当前实现正确,但建议增加对 shell 参数的空值检查。

建议修改为:

 $setShell(shell: string) {
+  if (!shell) {
+    return;
+  }
   if (this.shell !== shell) {
     this.shell = shell;
     this.onDidChangeShellEvent.fire(shell);
   }
 }

383-390: 建议完善实现和文档

  1. 建议将英文注释翻译为中文
  2. 建议增加对 profile 参数的空值检查

建议修改为:

 public $acceptDefaultProfile(profile: ITerminalProfile, automationProfile?: ITerminalProfile): void {
   const oldProfile = this._defaultProfile;
   this._defaultProfile = profile;
-  // 还不知道这个 automation 有啥用
+  // TODO: automation profile 的具体用途待确认
   this._defaultAutomationProfile = automationProfile;

+  if (!profile?.path) {
+    return;
+  }
   if (oldProfile?.path !== profile.path) {
     this.onDidChangeShellEvent.fire(profile.path);
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4264951 and b2c5696.

📒 Files selected for processing (7)
  • packages/extension/src/browser/vscode/api/main.thread.terminal.ts (1 hunks)
  • packages/extension/src/common/vscode/terminal.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/env/envApiFactory.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (4 hunks)
  • packages/terminal-next/__tests__/browser/mock.service.ts (1 hunks)
  • packages/terminal-next/src/browser/terminal.profile.ts (6 hunks)
  • packages/terminal-next/src/common/profile.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/extension/src/hosted/api/vscode/env/envApiFactory.ts
  • packages/terminal-next/src/browser/terminal.profile.ts
🔇 Additional comments (2)
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (2)

53-53: 属性声明正确且符合最佳实践

shellonDidChangeShellEvent 的声明遵循了正确的访问修饰符和命名规范。

Also applies to: 59-59


177-179: 事件访问器实现正确

onDidChangeShell 的实现遵循了 VSCode API 的标准模式,与其他事件访问器保持一致。

@bk1012 bk1012 requested a review from winjo December 12, 2024 12:02
@bk1012 bk1012 merged commit 54618a4 into main Dec 12, 2024
12 checks passed
@bk1012 bk1012 deleted the feat/support-env.onDidChangeShell branch December 12, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants