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 MessageOptions.detail #4135

Merged
merged 5 commits into from
Nov 4, 2024
Merged

Conversation

bk1012
Copy link
Member

@bk1012 bk1012 commented Oct 30, 2024

Types

  • 🎉 New Features

Background or solution

Support VSCode API: MessageOptions.detail

image

Changelog

Summary by CodeRabbit

  • 新特性

    • 在对话框中新增可选属性detail,允许显示附加信息。
    • 更新对话框内容组件,确保标题和消息的处理方式更为清晰。
    • 对话服务增强,支持更灵活的消息配置。
    • 增加getDetail方法,提供对话框详细信息的访问。
  • 样式

    • 更新对话框标题的字体大小,从14px增至15px。
  • 文档

    • 更新MessageOptions接口,新增detail属性以支持更详细的消息显示。

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

此拉取请求引入了一系列对对话框和消息服务的更改,主要包括在IDialogProps接口中添加了可选的detail属性,以支持更详细的消息内容。对话框组件的titlemessage现在被明确区分,并且在多个服务和组件中更新了方法签名,以接受新的options参数。这些更改旨在增强对话框和消息的显示能力,并提高用户交互的灵活性。

Changes

文件路径 更改摘要
packages/components/src/dialog/index.tsx 添加属性 detail?: string;IDialogProps 接口。更新 DialogContentDialog 组件以使用新的属性。
packages/components/src/dialog/styles.less 更新类 .@{prefix}-dialog-content_title 的字体大小,从 14px 更改为 15px
packages/extension/src/browser/vscode/api/main.thread.message.ts 更新 $showMessage 方法,改为使用对象参数调用 dialogService.openmessageService.open
packages/extension/src/hosted/api/vscode/ext.host.message.ts showMessage 方法中添加条件块,以检查 detail 属性并将其分配给 options 对象。
packages/file-tree-next/src/browser/dialog/window-dialog.service.tsx showOpenDialogshowSaveDialog 方法中,向 this.dialogService.open 方法调用添加对象参数。
packages/overlay/src/browser/dialog.service.ts 添加 `protected detail: string
packages/overlay/src/browser/dialog.view.tsx 添加变量 detail,并将其作为 prop 传递给 DialogView 组件。
packages/overlay/src/browser/message.service.tsx 更新 open 方法签名以使用对象参数。
packages/overlay/src/common/index.ts 更新 IMessageService 接口的 open 方法以接受 OpenMessageOptions 类型的对象参数,添加 getDetail 方法到 IDialogService 接口。
packages/types/vscode/typings/vscode.message.d.ts MessageOptions 接口中添加 detail 属性。
packages/editor/src/browser/fs-resource/fs-resource.ts 更新 close 方法以使用对象作为参数调用 dialogService.open
packages/editor/src/browser/untitled-resource.ts 更新 shouldCloseResource 方法以使用对象作为参数调用 dialogService.open
packages/editor/src/browser/workbench-editor.service.ts 更新 closeAllOnlyConfirmOnce 方法以使用对象作为参数调用 dialogService.open
packages/extension/src/browser/vscode/api/main.thread.file-system-event.ts 更新 fileOperationParticipant 方法中的 dialogService.open 调用以使用对象参数。
packages/search/src/browser/replace.ts 更新 replaceAll 函数以使用对象作为参数调用 dialogService.open
packages/search/src/browser/search.contribution.ts 更新 MENU_REPLACE_ALL 命令中的 dialogService.open 调用以使用对象参数。
packages/workspace-edit/src/browser/refactor-preview.service.tsx 更新 previewEdits 方法以使用对象作为参数调用 dialogService.open

Possibly related PRs

Suggested reviewers

  • Ricbet

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7654176 and 8cf2cae.

📒 Files selected for processing (1)
  • packages/components/src/dialog/styles.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/components/src/dialog/styles.less

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 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: 5

🧹 Outside diff range and nitpick comments (7)
packages/components/src/dialog/styles.less (1)

39-39: 建议调整行高以提高可读性

当前行高(line-height)为22px,对于18px的字体来说可能偏小。建议适当增加行高以获得更好的可读性。

建议如下修改:

.@{prefix}-dialog-content_title {
-  line-height: 22px;
+  line-height: 26px;
  font-size: 18px;
  margin: 0px 0px 8px 0px;
}
packages/extension/src/hosted/api/vscode/ext.host.message.ts (1)

46-49: 实现正确,建议增加类型检查

代码实现符合预期,但建议添加类型检查以提高代码的健壮性。

建议修改如下:

  if ('modal' in optionsOrFirstItem) {
    options.modal = optionsOrFirstItem.modal;

-   if ('detail' in optionsOrFirstItem) {
-     options.detail = optionsOrFirstItem.detail;
-   }
+   if ('detail' in optionsOrFirstItem && typeof optionsOrFirstItem.detail === 'string') {
+     options.detail = optionsOrFirstItem.detail;
+   }
  }
packages/overlay/src/browser/message.service.tsx (1)

Let me analyze the search results. I can see that:

  1. The MessageOptions interface is defined in packages/types/vscode/typings/vscode.message.d.ts with detail property
  2. The duplicate message check in MessageService only compares string messages
  3. The options.detail is not considered in the duplicate check logic

Let me generate the final response:

建议将 options.detail 纳入重复消息判断逻辑

当前的重复消息判断仅比较了消息字符串,但未考虑 options.detail 的内容。建议:

  • MessageService 中,当 options?.detail 存在时,将其纳入重复消息的判断逻辑中,避免具有不同详细信息的消息被误判为重复
  • 可以考虑将 preMessage 的类型从字符串改为对象,同时存储消息内容和详细信息
🔗 Analysis chain

Line range hint 46-73: 建议验证消息处理逻辑

当前的实现中存在重复消息的处理逻辑,需要确认新增的 options.detail 是否也应该参与重复消息的判断。

运行以下脚本来查找相关的消息处理逻辑:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:查找相关的消息处理实现
# 预期:找到其他使用 MessageOptions 的地方,以确保一致性

# 测试:搜索 MessageOptions 的使用
rg "MessageOptions" -A 5

# 测试:搜索消息重复判断的相关实现
rg "SAME_MESSAGE_DURATION_MS" -A 5

Length of output: 11585

packages/overlay/src/browser/dialog.service.ts (2)

55-55: 建议增加空值处理

虽然使用可选链操作符是个好做法,但建议添加空字符串处理逻辑,以确保 detail 始终是有效的字符串或 undefined。

建议修改为:

-    this.detail = options?.detail;
+    this.detail = options?.detail?.trim() || undefined;

84-86: 建议添加方法文档

getDetail 方法的实现正确,但建议添加 JSDoc 文档说明其用途和返回值。

建议添加:

+  /**
+   * 获取对话框的详细信息
+   * @returns 详细信息文本,如果未设置则返回 undefined
+   */
   getDetail(): string | undefined {
     return this.detail;
   }
packages/components/src/dialog/index.tsx (2)

27-27: 接口变更符合预期

建议为新增的 detail 属性添加 JSDoc 注释,说明其用途和与 VSCode API 的对应关系。

建议添加如下注释:

+ /** 详细信息,对应 VSCode API 中的 MessageOptions.detail */
  detail?: string;

73-74: 渲染逻辑优化合理

  1. 使用语义化的 HTML 标签(<p>)来渲染标题提升了可访问性
  2. 消息内容的条件渲染避免了不必要的空元素

建议考虑为标题和消息添加适当的 ARIA 属性,进一步增强可访问性。

- <p className={'kt-dialog-content_title'}>{title}</p>
+ <p className={'kt-dialog-content_title'} role="heading" aria-level="2">{title}</p>
- {message && <span className={'kt-dialog-message'}>{message}</span>}
+ {message && <span className={'kt-dialog-message'} aria-label="详细信息">{message}</span>}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 76fb679 and 4045d31.

📒 Files selected for processing (10)
  • packages/components/src/dialog/index.tsx (4 hunks)
  • packages/components/src/dialog/styles.less (1 hunks)
  • packages/extension/src/browser/vscode/api/main.thread.message.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/ext.host.message.ts (1 hunks)
  • packages/file-tree-next/src/browser/dialog/window-dialog.service.tsx (2 hunks)
  • packages/overlay/src/browser/dialog.service.ts (4 hunks)
  • packages/overlay/src/browser/dialog.view.tsx (2 hunks)
  • packages/overlay/src/browser/message.service.tsx (2 hunks)
  • packages/overlay/src/common/index.ts (6 hunks)
  • packages/types/vscode/typings/vscode.message.d.ts (1 hunks)
🔇 Additional comments (14)
packages/extension/src/browser/vscode/api/main.thread.message.ts (1)

34-35: 代码实现符合预期!

实现正确地处理了 MessageOptions,通过 modal 选项来决定使用对话框服务还是消息服务。新增的 options 参数传递确保了 detail 属性可以被正确处理。

建议验证这些更改在所有使用场景中的行为是否符合预期。

✅ Verification successful

Let me gather more information about the implementation details of these services to ensure the changes are properly integrated.


Let me check one more detail about the services to ensure the parameter handling is consistent.


代码修改验证完成,实现正确!

通过代码分析,我们可以确认:

  • $showMessage 方法在所有调用点都保持了一致的参数传递
  • DialogServiceMessageService 都正确继承自 AbstractMessageService
  • MessageOptions 接口定义清晰,包含了 modal 选项
  • 服务实现的参数处理符合预期,能够正确处理新增的 options 参数

代码变更符合设计意图,保持了良好的一致性和兼容性。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 $showMessage 的调用方式
# 预期结果:找到所有调用点,确保它们都提供了正确的参数

# 搜索所有调用 $showMessage 的地方
rg -A 3 '\$showMessage\(' 

Length of output: 1097


Script:

#!/bin/bash
# Check the implementation of dialogService and messageService
ast-grep --pattern 'class DialogService {
  $$$
  open($$$) {
    $$$
  }
  $$$
}'

ast-grep --pattern 'class MessageService {
  $$$
  open($$$) {
    $$$
  }
  $$$
}'

# Check the MessageOptions interface definition
rg -A 5 'interface MessageOptions'

Length of output: 627


Script:

#!/bin/bash
# Search for service implementations and their usage
rg -A 10 'class (Dialog|Message)Service.*implements' 

# Check if there are any other places using these services
rg -A 3 '(Dialog|Message)Service.*open\('

Length of output: 1784

packages/components/src/dialog/styles.less (1)

39-39: 字体大小的调整改善了视觉层次结构

将标题字体从14px增加到18px的修改是合理的,这样可以更好地区分标题和详细信息。

packages/extension/src/hosted/api/vscode/ext.host.message.ts (1)

46-49: 验证实现是否符合 VSCode API 规范

需要确保当前实现与 VSCode API 的 MessageOptions.detail 特性完全一致。

✅ Verification successful

Let me search for more details about the MessageOptions interface to verify the detail property.


detail 属性的实现符合 VSCode API 规范

根据 VSCode API 的类型定义,MessageOptions 接口中的 detail 属性是一个可选的字符串类型属性,用于显示次要的人类可读详细信息。当前代码中对 detail 属性的处理方式与 API 规范完全一致。

需要注意的是:

  • detail 属性仅在 modal: true 的消息中才会显示
  • 当前实现正确地处理了属性的存在性检查
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索 VSCode API 中 MessageOptions 接口的定义和使用方式
rg -A 5 "interface MessageOptions" 

Length of output: 456


Script:

#!/bin/bash
# Search for MessageOptions interface definition with more context lines
rg -A 15 "interface MessageOptions"

# Also search for any usage of detail property in message related files
rg "detail.*MessageOptions" 
rg "MessageOptions.*detail"

Length of output: 1112

packages/overlay/src/browser/dialog.view.tsx (2)

12-12: 代码实现正确且符合现有模式

新增的 getDetail() 调用与其他 getter 方法保持一致,代码结构清晰。


52-52: 建议验证 detail 属性在对话框中的渲染效果

detail 属性的添加符合接口定义,但建议验证在不同场景下的显示效果。

✅ Verification successful

Let me gather more information about the DialogView component and its usage of the detail prop.


让我再搜索一下 IDE 组件库中 Dialog 组件的实现,以确认 detail 属性的渲染逻辑。


detail 属性的渲染已得到正确处理

根据代码分析,Dialog 组件已正确实现了 detail 属性的渲染逻辑:

  • detail 作为 message 属性传递给 DialogContent 组件
  • DialogContent 组件使用 kt-dialog-message 类渲染消息内容
  • 样式支持自动换行(white-space: pre-wrap)和文本选择(user-select: text)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证 DialogView 组件是否正确处理 detail 属性的渲染

# 搜索 DialogView 组件的实现以确认 detail 属性的处理逻辑
ast-grep --pattern 'export const DialogView = $$$'

# 搜索相关的样式定义
rg -g '*.less' -g '*.css' 'detail'

Length of output: 1632


Script:

#!/bin/bash
# Search for DialogView component implementation
ast-grep --pattern 'interface DialogViewProps {
  $$$
}'

# Search for DialogView component usage
rg "DialogView.*detail" -A 2 -B 2

# Search for Dialog component in overlay package
fd "dialog" packages/overlay/src -x cat {}

Length of output: 7067


Script:

#!/bin/bash
# 搜索 IDE 组件库中的 Dialog 组件实现
fd "dialog" packages/components/src -x cat {}

# 搜索组件库中 Dialog 相关的样式
rg -g '*.less' -g '*.css' 'dialog.*detail' -A 2 -B 2

Length of output: 154


Script:

#!/bin/bash
# 搜索 IDE 组件库中的 Dialog 组件实现,修正路径
find packages/components/src/dialog -type f -exec cat {} \;

# 搜索组件库中 Dialog 的类型定义
ast-grep --pattern 'interface DialogProps {
  $$$
}'

Length of output: 5344

packages/overlay/src/browser/message.service.tsx (1)

11-12: 导入语句正确添加

类型导入正确地使用了 type-only 导入语法。

packages/overlay/src/browser/dialog.service.ts (4)

8-8: 导入声明符合预期

类型导入的添加正确支持了 VSCode API 的类型系统集成。


23-23: 属性声明合理

detail 属性的保护级别和类型声明与类的设计模式保持一致。


47-47: 方法签名更新恰当

open 方法新增的可选参数 options 保持了向后兼容性,同时支持了新功能。


Line range hint 23-86: 验证功能集成

需要确保新增的 detail 功能在整个对话框系统中得到正确集成。

✅ Verification successful

Let me gather more information about the dialog view component to verify the integration.


detail 功能已正确集成到对话框系统中

通过代码验证,detail 功能已经完整地集成到对话框系统中:

  • DialogService 中正确实现了 detail 属性的存储和获取
  • DialogView 组件正确调用 getDetail() 方法获取 detail 内容
  • detail 属性被正确传递给底层的 DialogView 组件进行渲染
  • 整个实现遵循了既有的对话框系统架构,保持了代码的一致性
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查相关组件是否正确使用了 detail 属性
echo "检查 DialogView 组件是否使用了 detail 属性:"
rg "detail.*props" --type ts

echo "检查是否有其他服务使用了 getDetail 方法:"
rg "getDetail\(\)" --type ts

Length of output: 1166


Script:

#!/bin/bash
# Check DialogView component implementation
echo "检查 DialogView 组件的实现:"
rg -A 5 "const detail = dialogService.getDetail\(\)" --type ts

# Check if detail is rendered in the view
echo "检查 detail 在视图中的渲染:"
ast-grep --pattern 'const detail = dialogService.getDetail();
  $$$
  return (
    $$$
    {detail && $$$}
    $$$
  )'

Length of output: 751


Script:

#!/bin/bash
# 检查 DialogView 组件中 detail 的具体渲染实现
echo "检查 DialogView 中的渲染代码:"
rg -A 20 "const detail = dialogService.getDetail\(\)" packages/overlay/src/browser/dialog.view.tsx

# 检查 detail 相关的测试用例
echo "检查 dialog 相关的测试用例:"
rg "detail" --type ts packages/overlay/__tests__/

Length of output: 833


Script:

#!/bin/bash
# 检查 DialogView 组件的完整实现,特别是渲染部分
echo "检查完整的 DialogView 组件实现:"
cat packages/overlay/src/browser/dialog.view.tsx

# 检查 dialog 组件的样式文件
echo "检查 dialog 相关的样式文件:"
fd -e less -e css "dialog" packages/overlay/src/browser/

Length of output: 2351

packages/overlay/src/common/index.ts (2)

5-5: 类型导入使用正确!

使用 type 关键字导入 vscode 类型是符合最佳实践的,因为这里只需要类型定义而不需要运行时代码。


32-34: 请验证接口更改的兼容性

接口的更改包含了新的可选参数和方法:

  1. open 方法新增了 options 参数
  2. IDialogService 新增了 getDetail 方法

这些更改可能会影响现有的实现类。

Also applies to: 53-53

✅ Verification successful

接口更改是安全的

IMessageServiceIDialogService 的实现类都继承自 AbstractMessageService,该抽象类已经包含了新增的可选参数。现有实现类只是在基类基础上添加了特定功能,不会受到接口变更的影响。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索所有实现了 IMessageService 和 IDialogService 的类
ast-grep --pattern 'class $_ implements $$$IMessageService$$$'
ast-grep --pattern 'class $_ implements $$$IDialogService$$$'

Length of output: 128


Script:

#!/bin/bash
# 使用 ripgrep 搜索实现类和接口使用
rg "implements.*IMessageService" -l
rg "implements.*IDialogService" -l
rg "class.*implements" -A 2

Length of output: 275520


Script:

#!/bin/bash
# 搜索 IMessageService 和 IDialogService 的实现类的具体代码
rg "class.*implements.*IMessageService" -A 5
rg "class.*implements.*IDialogService" -A 5

Length of output: 1524

packages/file-tree-next/src/browser/dialog/window-dialog.service.tsx (1)

Line range hint 137-188: 验证消息选项的实现

需要确保DialogService和相关组件正确处理了新增的detail选项。

运行以下脚本来验证实现:

✅ Verification successful

DialogService和相关组件已正确实现了detail选项

DialogService和对话框组件已经完整支持了detail属性:

  • packages/components/src/dialog/index.tsx 中定义了 detail?: string 接口
  • packages/overlay/src/browser/dialog.service.ts 中实现了 detail 属性的处理
  • MessageType 枚举定义了所有必要的消息类型
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查DialogService是否正确实现了detail选项的处理
rg -t typescript "interface.*DialogService|class.*DialogService" 

# 检查相关的对话框组件是否支持detail属性
ast-grep --pattern 'interface IDialogProps {
  $$$
}'

Length of output: 157


Script:

#!/bin/bash
# Search for DialogService interface and implementation
rg "interface.*DialogService|class.*DialogService" --type-add 'ts:*.{ts,tsx}'

# Search for dialog-related interfaces and props
rg "interface.*Dialog.*Props" --type-add 'ts:*.{ts,tsx}' -A 10

# Search for detail property usage in dialog components
rg "detail.*:" --type-add 'ts:*.{ts,tsx}' -A 2

Length of output: 163122


Script:

#!/bin/bash
# 搜索 DialogService 中的 detail 相关实现
rg "detail.*:" --type-add 'ts:*.{ts,tsx}' -A 5 packages/overlay/src/

# 搜索 dialog 组件中的 detail 属性使用
rg "detail.*:" --type-add 'ts:*.{ts,tsx}' -A 5 packages/components/src/dialog/

# 搜索 MessageType 定义
rg "enum.*MessageType" --type-add 'ts:*.{ts,tsx}' -A 10

Length of output: 4317

packages/types/vscode/typings/vscode.message.d.ts (1)

184-189: 新增的 detail 属性实现符合预期!

detail 属性的实现完全符合 VSCode API 的规范:

  • 属性定义清晰,使用可选类型
  • 文档注释完整,说明了渲染特点和使用限制
  • 与 modal 消息的关联逻辑合理

让我们验证一下相关组件是否正确处理了这个新属性:

✅ Verification successful

新增的 detail 属性实现已得到验证!

从代码搜索结果可以看到:

  • MessageOptions 接口已在多个组件中正确使用
  • detail 属性已被正确集成到消息显示相关的 API 中:
    • showInformationMessage
    • showWarningMessage
    • showErrorMessage

实现完全符合 VSCode API 规范,无需进一步修改。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否有相关组件正确使用了 detail 属性

# 测试:搜索对 detail 属性的使用
rg "detail.*?:" --type typescript

Length of output: 70


Script:

#!/bin/bash
# 搜索 detail 属性的使用和相关实现
rg "detail.*?:" 

# 搜索包含 MessageOptions 的文件
rg "MessageOptions"

# 搜索可能的消息处理相关实现
rg "showMessage|showInformationMessage|showWarningMessage|showErrorMessage"

Length of output: 146055

packages/overlay/src/browser/message.service.tsx Outdated Show resolved Hide resolved
packages/components/src/dialog/index.tsx Show resolved Hide resolved
packages/overlay/src/common/index.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 11.11111% with 16 lines in your changes missing coverage. Please review.

Project coverage is 54.23%. Comparing base (a95cd6c) to head (8cf2cae).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
packages/overlay/src/browser/dialog.service.ts 20.00% 3 Missing and 1 partial ⚠️
packages/overlay/src/common/index.ts 0.00% 3 Missing ⚠️
...rowser/vscode/api/main.thread.file-system-event.ts 0.00% 2 Missing ⚠️
...sion/src/browser/vscode/api/main.thread.message.ts 0.00% 2 Missing ⚠️
...xtension/src/hosted/api/vscode/ext.host.message.ts 0.00% 1 Missing and 1 partial ⚠️
packages/editor/src/browser/untitled-resource.ts 0.00% 1 Missing ⚠️
...ges/editor/src/browser/workbench-editor.service.ts 0.00% 1 Missing ⚠️
packages/search/src/browser/replace.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4135      +/-   ##
==========================================
- Coverage   54.23%   54.23%   -0.01%     
==========================================
  Files        1598     1598              
  Lines       97627    97652      +25     
  Branches    19976    19984       +8     
==========================================
+ Hits        52952    52961       +9     
- Misses      37108    37119      +11     
- Partials     7567     7572       +5     
Flag Coverage Δ
jsdom 49.79% <11.11%> (-0.01%) ⬇️
node 15.60% <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.

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: 2

🧹 Outside diff range and nitpick comments (9)
packages/overlay/src/browser/message.service.tsx (1)

Line range hint 36-41: 需要更新 JSDoc 注释

当前的 JSDoc 注释仍然使用旧的参数格式,需要更新以反映新的对象参数结构。

建议更新为:

 /**
- * @param rawMessage message
- * @param type MessageType
- * @param buttons buttons
- * @param closable true | false
- * @param from from extension
+ * @param options 消息配置选项
+ * @param options.message 消息内容
+ * @param options.type 消息类型
+ * @param options.buttons 按钮选项
+ * @param options.closable 是否可关闭
+ * @param options.from 消息来源
+ * @param options.detail 详细信息
  */
packages/overlay/src/browser/dialog.service.ts (1)

81-83: 建议添加方法文档

getDetail 方法的实现很简单明了,但建议添加 JSDoc 文档说明该方法的用途和返回值。

建议添加如下文档:

+ /**
+  * 获取对话框的详细信息
+  * @returns 详细信息文本,如果未设置则返回 undefined
+  */
  getDetail(): string | undefined {
    return this.detail;
  }
packages/search/src/browser/replace.ts (1)

30-39: 代码重构改进了参数传递方式,建议进一步优化

代码重构将多个参数整合为单个对象参数,提高了代码的可读性和可维护性。这种改进符合现代TypeScript的最佳实践。

建议进一步改进代码结构,将按钮定义提取为常量:

+const REPLACE_DIALOG_BUTTONS = {
+  [localize('search.replace.buttonCancel')]: false,
+  [localize('search.replace.buttonOK')]: true,
+} as const;

-    const buttons = {
-      [localize('search.replace.buttonCancel')]: false,
-      [localize('search.replace.buttonOK')]: true,
-    };
     const selection = await dialogService!.open({
       message: formatLocalize(
         'search.removeAll.occurrences.files.confirmation.message',
         String(resultTotal.resultNum),
         String(resultTotal.fileNum),
         replaceText,
       ),
       type: MessageType.Warning,
-      buttons: Object.keys(buttons),
+      buttons: Object.keys(REPLACE_DIALOG_BUTTONS),
     });
-    if (!buttons[selection!]) {
-      return buttons[selection!];
+    if (!REPLACE_DIALOG_BUTTONS[selection!]) {
+      return REPLACE_DIALOG_BUTTONS[selection!];
     }

这样可以:

  1. 避免重复创建按钮对象
  2. 通过 as const 获得更好的类型推断
  3. 提高代码的可重用性
packages/overlay/src/common/index.ts (1)

54-54: 建议添加方法文档

新增的 getDetail 方法缺少 JSDoc 文档注释。建议添加文档说明该方法的用途、返回值含义以及与 VSCode API 的对应关系。

建议添加如下文档:

+ /**
+  * 获取对话框的详细信息
+  * @returns 详细信息文本,如果未设置则返回 undefined
+  */
  getDetail(): string | undefined;
packages/workspace-edit/src/browser/refactor-preview.service.tsx (1)

100-109: 对话框服务调用方式的改进

代码改动符合预期,通过使用对象参数结构提高了代码的可读性和可维护性。JSX结构清晰地区分了标题和详细信息。

建议考虑以下优化:

  1. 将JSX内容抽取为独立的常量,以提高代码的可维护性
  2. 考虑使用 TypeScript 的模板字面量类型来约束按钮文本

建议按照以下方式重构:

+ const DialogContent = (
+   <div>
+     {localize('refactor-preview.overlay.title')}
+     <p>{localize('refactor-preview.overlay.detail')}</p>
+   </div>
+ );
+
+ const DialogButtons = [
+   localize('refactor-preview.overlay.cancel'),
+   localize('refactor-preview.overlay.continue'),
+ ] as const;
+
  const continued = await this.dialogService.open({
-   message: (
-     <div>
-       {localize('refactor-preview.overlay.title')}
-       <p>{localize('refactor-preview.overlay.detail')}</p>
-     </div>
-   ),
+   message: DialogContent,
    type: MessageType.Warning,
-   buttons: [localize('refactor-preview.overlay.cancel'), localize('refactor-preview.overlay.continue')],
+   buttons: DialogButtons,
  });
packages/editor/src/browser/untitled-resource.ts (1)

214-218: 对话框服务调用结构优化良好!

代码改动符合预期,将参数传递方式规范化为对象结构,提高了代码的可读性和一致性。

建议考虑使用新增的 detail 属性来提供更详细的信息,比如显示文件的完整路径或修改内容概要,以帮助用户做出更明确的选择。

示例改进:

     const selection = await this.dialogService.open({
       message: formatLocalize('saveChangesMessage', resource.name),
       type: MessageType.Info,
       buttons: Object.keys(buttons),
+      detail: `${localize('file.path', '文件路径')}: ${resource.uri.toString()}`
     });
packages/extension/src/browser/vscode/api/main.thread.file-system-event.ts (1)

Line range hint 214-219: 建议添加详细信息支持

对话框服务调用的重构看起来不错。考虑到此PR的目标是支持MessageOptions.detail,建议在这里添加详细信息来增强用户体验。

建议按照以下方式添加detail属性:

 const answer = await this.dialogService.open({ 
   message, 
   type: MessageType.Info, 
-  buttons: choices 
+  buttons: choices,
+  detail: localize('refactoring-changes.detail', '这些更改将影响您的工作区中的文件。请仔细检查更改。')
 });
packages/editor/src/browser/fs-resource/fs-resource.ts (1)

237-241: 对话框服务调用重构符合新的API设计

代码重构将分散的参数整合为一个对象参数,提高了代码的可维护性和可读性。这种改动与PR的目标保持一致。

不过建议考虑以下优化:

     const selection = await this.dialogService.open({
       message: formatLocalize('saveChangesMessage', resource.name),
       type: MessageType.Info,
       buttons: Object.keys(buttons),
+      detail: formatLocalize('saveChangesDetail', resource.uri.path.toString()),
     });

添加detail属性可以向用户展示更多上下文信息,比如文件的完整路径,这样用户可以更清楚地知道正在处理哪个文件。

packages/search/src/browser/search.contribution.ts (1)

162-169: 对话框参数重构正确,建议增加细节信息

代码重构将 dialogService.open 的参数改为对象结构是正确的改动。不过,既然此 PR 的目标是支持 MessageOptions.detail 特性,建议在此处利用 detail 属性来提供更详细的替换信息,以增强用户体验。

建议添加 detail 属性来显示更多上下文信息,例如:

 const selection = await this.dialogService.open({
   message: formatLocalize(
     'search.removeAll.occurrences.file.confirmation.message',
     String(contentSearchResult.length),
   ),
   type: MessageType.Warning,
   buttons: Object.keys(buttons),
+  detail: formatLocalize(
+    'search.removeAll.occurrences.file.confirmation.detail',
+    this.searchBrowserService.searchValue,
+    this.searchBrowserService.replaceValue
+  ),
 });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4045d31 and 61cefb0.

📒 Files selected for processing (12)
  • packages/editor/src/browser/fs-resource/fs-resource.ts (1 hunks)
  • packages/editor/src/browser/untitled-resource.ts (1 hunks)
  • packages/editor/src/browser/workbench-editor.service.ts (1 hunks)
  • packages/extension/src/browser/vscode/api/main.thread.file-system-event.ts (2 hunks)
  • packages/extension/src/browser/vscode/api/main.thread.message.ts (1 hunks)
  • packages/file-tree-next/src/browser/dialog/window-dialog.service.tsx (2 hunks)
  • packages/overlay/src/browser/dialog.service.ts (4 hunks)
  • packages/overlay/src/browser/message.service.tsx (2 hunks)
  • packages/overlay/src/common/index.ts (6 hunks)
  • packages/search/src/browser/replace.ts (1 hunks)
  • packages/search/src/browser/search.contribution.ts (1 hunks)
  • packages/workspace-edit/src/browser/refactor-preview.service.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/extension/src/browser/vscode/api/main.thread.message.ts
  • packages/file-tree-next/src/browser/dialog/window-dialog.service.tsx
🔇 Additional comments (9)
packages/overlay/src/browser/message.service.tsx (1)

42-48: 方法签名重构改进了参数结构

通过使用对象解构的方式重构了方法签名,这样的改进:

  • ✓ 解决了可选参数的顺序问题
  • ✓ 使方法调用更清晰易读
  • ✓ 为后续添加新参数提供了更好的扩展性
packages/overlay/src/browser/dialog.service.ts (3)

4-4: 导入更改看起来不错!

新增的 OpenMessageOptions 类型导入正确放置,并且与现有的相关导入保持一致。


21-21: 属性声明符合预期!

detail 属性使用 protected 修饰符很合适,确保了类的封装性,同时允许子类访问。类型定义也符合 VSCode API 的规范。


52-52: 细节赋值实现正确!

使用可选链操作符来访问 options.detail 是个很好的做法,可以安全地处理 options 为空的情况。

packages/overlay/src/common/index.ts (3)

5-6: 类型导入使用恰当!

使用 type 导入 vscode 类型定义是正确的做法,这样可以避免在运行时引入不必要的依赖。


37-37: 接口简化改进有效!

将多个参数整合为一个 options 对象是很好的改进,这样:

  1. 提高了代码的可维护性
  2. 使接口更容易扩展
  3. 调用时参数更清晰

69-69: 验证消息服务实现的一致性

实现更改看起来正确,但建议验证所有使用这些方法的地方是否都已更新。

运行以下脚本来验证实现:

Also applies to: 78-78, 87-87, 89-89

✅ Verification successful

Let me generate additional scripts to verify the implementation:


消息服务实现已正确更新

代码分析显示所有使用 messageService 的地方都采用了正确的调用方式,没有发现旧式的调用模式。主要调用都是通过 info()warning()error() 方法,这些方法内部都正确使用了新的 open() 实现。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否有遗漏的旧式方法调用

# 搜索可能的旧式调用模式
rg "\.open\([^{]" 

# 搜索 AbstractMessageService 的实现类
ast-grep --pattern 'class $_ extends AbstractMessageService'

Length of output: 39973


Script:

#!/bin/bash
# Search for AbstractMessageService class and its implementations
ast-grep --pattern 'class AbstractMessageService {
  $$$
  open($_, $_) {
    $$$
  }
  $$$
}'

# Search for message service usage patterns
rg "messageService\.(info|warning|error)\(" -A 2

Length of output: 8684

packages/extension/src/browser/vscode/api/main.thread.file-system-event.ts (1)

202-203: 对话框服务调用重构正确!

对话框服务的调用已经更新为使用对象参数结构,这样的改动使代码更加清晰和一致。

packages/editor/src/browser/workbench-editor.service.ts (1)

566-570: 代码重构改进了可读性和可维护性!

dialogService.open() 的参数重构为对象形式是一个很好的改进:

  • 参数更加清晰和自文档化
  • 符合现代 TypeScript/JavaScript 最佳实践
  • 便于后续扩展新的参数

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 61cefb0 and 6a437a7.

📒 Files selected for processing (1)
  • packages/components/src/dialog/index.tsx (6 hunks)
🔇 Additional comments (2)
packages/components/src/dialog/index.tsx (2)

27-27: 接口设计清晰且符合预期!

新增的 IDialogContentProps 接口通过 primaryTextsecondaryText 属性明确区分了主要内容和次要内容,使得组件的数据结构更加清晰。这种设计与 VSCode API 的 MessageOptions.detail 特性保持一致。

Also applies to: 38-50


Line range hint 61-88: 组件实现逻辑合理!

DialogContent 组件通过不同的样式类名(kt-dialog-content_titlekt-dialog-message)清晰地区分了主要内容和详细信息,增强了消息的层次感和可读性。

packages/components/src/dialog/index.tsx Outdated Show resolved Hide resolved
@bk1012 bk1012 force-pushed the feat/support-MessageOptions.detail branch from 6a437a7 to 7654176 Compare October 31, 2024 08:55
packages/components/src/dialog/styles.less Outdated Show resolved Hide resolved
@erha19 erha19 merged commit c24cd87 into main Nov 4, 2024
12 checks passed
@erha19 erha19 deleted the feat/support-MessageOptions.detail branch November 4, 2024 03:21
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.

3 participants