Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

wangxiaojuan
Copy link
Contributor

@wangxiaojuan wangxiaojuan commented Mar 31, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background or solution

Changelog

feat: statusBarService支持复写addElement

Summary by CodeRabbit

  • 新特性

    • 更新了状态栏条目接口的 text 属性类型,允许其接受更灵活的内容类型(string | React.ReactNode),增强了状态栏元素的视觉表现。
    • 修改了 StatusBarItem 组件中 text 属性的处理逻辑,允许直接渲染非字符串值,提升了灵活性。
  • 重构

    • 优化了部分服务接口的访问级别,将原先私有的方法和属性改为公开,使得其他模块能够更方便地集成和调用,同时保持现有业务逻辑和系统稳定性。

@opensumi opensumi bot added the 🎨 feature feature required label Mar 31, 2025
@wangxiaojuan
Copy link
Contributor Author

/next

Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

Walkthrough

此次 PR 的修改集中在 StatusBarService 类中,将三个成员的访问权限由私有(private)变更为公有(public)。具体来说,entriesObservable 属性、getEntriesById 方法以及 getStorageState 方法的可访问性均被调整,使得外部组件可直接访问和调用这些成员。逻辑行为未作修改,仅改变了访问级别。同时,StatusBarEntry 接口中的 text 属性类型从 string 更新为 string | React.ReactNode,允许更灵活的内容类型。此外,StatusBarItem 组件中对 text 属性的处理进行了改进,增加了类型检查以支持非字符串值的渲染。

Changes

文件路径 修改摘要
packages/status-bar/.../status-bar.service.ts entriesObservable 属性以及 getEntriesByIdgetStorageState 方法从 private 改为 public。
packages/core-browser/.../status-bar-service.ts StatusBarEntry 接口中的 text 属性类型从 string 改为 `string
packages/status-bar/.../status-bar-item.view.tsx 修改 StatusBarItem 组件中 text 属性的处理,增加类型检查以支持直接渲染非字符串值。

Suggested reviewers

  • hacke2
  • Ricbet

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.

yarn install v1.22.22
[1/4] Resolving packages...
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: 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 > [email protected]: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

🧹 Nitpick comments (4)
packages/status-bar/src/browser/status-bar.service.ts (4)

30-30: 将 entriesObservable 更改为公共属性是支持扩展的好方法

将 entriesObservable 的可见性从私有改为公共可以让外部组件直接访问和修改状态栏条目集合,这对于扩展 addElement 功能是必要的。不过,直接暴露这个内部状态可能会在未来的重构中导致兼容性问题。

建议添加适当的 JSDoc 文档注释,明确说明这个属性的用途和预期使用场景。


104-106: 将 getEntriesById 改为公共方法有助于重写 addElement

将这个方法的访问权限修改为公共是合理的,因为它在扩展 addElement 功能时可能需要被外部调用。这个方法用于根据 ID 查找状态栏条目,对于自定义实现非常有用。

建议添加更详细的文档注释,特别是说明返回值的类型和用途。


111-113: 将 getStorageState 改为公共方法支持状态持久化扩展

这个更改使外部实现可以访问状态栏条目的存储状态,对于扩展 addElement 功能时保持状态一致性非常重要。此方法从 storage 中读取状态栏元素的状态信息。

建议添加更完整的文档注释,包括返回值类型和可能的使用场景。


30-113: 整体扩展性改进评估

这些更改(将 entriesObservable、getEntriesById 和 getStorageState 改为公共)共同为 StatusBarService 类提供了很好的扩展性,特别是对 addElement 方法的重写支持。这种方法允许外部组件访问必要的内部状态和功能,而不必完全重新实现 addElement 的逻辑。

不过,需要注意的是,暴露这些内部实现细节会降低封装性,可能会在未来的重构中引入兼容性问题。建议考虑以下改进:

  1. 为新公开的成员添加全面的文档注释
  2. 考虑添加一个简单的示例,说明如何利用这些变更来扩展 addElement 功能
  3. 在 README 或相关文档中说明这些 API 的预期使用方式
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 91eaefa and ed5280b.

📒 Files selected for processing (1)
  • packages/status-bar/src/browser/status-bar.service.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build-windows
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: build (macos-latest, 20.x)

@opensumi
Copy link
Contributor

opensumi bot commented Mar 31, 2025

🎉 PR Next publish successful!

3.8.3-next-1743422663.0

Copy link

codecov bot commented Mar 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.13%. Comparing base (91eaefa) to head (9cef832).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4503   +/-   ##
=======================================
  Coverage   53.12%   53.13%           
=======================================
  Files        1665     1665           
  Lines      102648   102648           
  Branches    22216    22224    +8     
=======================================
+ Hits        54535    54542    +7     
+ Misses      40026    40020    -6     
+ Partials     8087     8086    -1     
Flag Coverage Δ
jsdom 48.62% <100.00%> (+<0.01%) ⬆️
node 12.12% <0.00%> (ø)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangxiaojuan
Copy link
Contributor Author

/next

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

🧹 Nitpick comments (2)
packages/core-browser/src/services/status-bar-service.ts (1)

50-54: 建议更新文档注释以反映新的类型

当前的注释只描述了如何通过特定语法 $(iconClassName) :text 在字符串中设置图标,但没有提及当 text 是 React 组件时应如何处理图标。

建议更新注释以反映新的类型:

 /**
  * 状态栏显示文案
  * 可以通过 text 设置图标
  * $(iconClassName) :text
+ * 也可以直接使用 React 组件
  */
 text?: string | React.ReactNode;
packages/status-bar/src/browser/status-bar-item.view.tsx (1)

140-156: 建议保持样式和可访问性属性的一致性

text 是字符串时,它被包装在一个设置了特定样式、aria-label 和 role 属性的 span 中。但当 text 是 React 组件时,这些样式和属性没有被应用,可能导致展示和可访问性的不一致。

建议将 React 组件也包装在具有相同样式和属性的 span 中:

  {typeof text === 'string'
    ? transformLabelWithCodicon(
        text,
        {},
        iconService.fromString.bind(iconService),
        (text: string, index: number) => (
          <span
            key={`${text}-${index}`}
            style={{ height: '22px', lineHeight: '22px' }}
            aria-label={ariaLabel}
            role={role}
          >
            {replaceLocalizePlaceholder(text)}
          </span>
        ),
      )
-   : text}
+   : <span
+       style={{ height: '22px', lineHeight: '22px' }}
+       aria-label={ariaLabel}
+       role={role}
+     >
+       {text}
+     </span>}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed5280b and 9cef832.

📒 Files selected for processing (2)
  • packages/core-browser/src/services/status-bar-service.ts (1 hunks)
  • packages/status-bar/src/browser/status-bar-item.view.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
🔇 Additional comments (3)
packages/core-browser/src/services/status-bar-service.ts (1)

54-54: 更新了 text 类型以支持 React 组件

text 类型从 string 扩展为 string | React.ReactNode 提高了状态栏内容的灵活性,允许直接使用 React 组件而不仅限于字符串。这是一个良好的改进,可以支持更丰富的状态栏展示内容。

packages/status-bar/src/browser/status-bar-item.view.tsx (2)

140-156: 正确处理了 text 类型的变更

代码对 text 进行了类型检查,针对不同类型采取了不同的处理方式:

  • text 是字符串时,使用 transformLabelWithCodicon 进行处理
  • text 是 React 组件时,直接渲染

这个实现正确地适配了 StatusBarEntry 接口中 text 类型的变更。


140-156: 考虑 React 组件的国际化处理

text 是字符串时,通过 replaceLocalizePlaceholder 进行了国际化处理,但当 text 是 React 组件时,没有进行此处理。如果 React 组件中也需要国际化,应确保在组件内部处理。

请确认 React 组件的国际化是否已在组件内部处理,或是否需要额外的国际化支持。

@opensumi
Copy link
Contributor

opensumi bot commented Apr 1, 2025

🎉 PR Next publish successful!

3.8.3-next-1743485759.0

@wangxiaojuan wangxiaojuan requested a review from Ricbet April 1, 2025 07:03
@wangxiaojuan wangxiaojuan merged commit 58f75a1 into main Apr 1, 2025
13 checks passed
@wangxiaojuan wangxiaojuan deleted the fix/update_statusbar branch April 1, 2025 07:38
@erha19 erha19 mentioned this pull request May 20, 2025
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