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 WorkspaceEditMetadata #4120

Merged
merged 1 commit into from
Oct 30, 2024
Merged

Conversation

bk1012
Copy link
Member

@bk1012 bk1012 commented Oct 25, 2024

Types

  • 🎉 New Features

Background or solution

Support VSCode API: WorkspaceEditMetadata

fix #4108

Changelog

Summary by CodeRabbit

  • 新特性

    • 在应用工作区编辑时,新增可选的元数据参数,以指示编辑是否为重构操作。
    • 更新了多个接口和方法以支持新的元数据参数,增强了编辑功能。
  • 文档

    • 更新了 applyEdit 函数的文档,明确了新参数的用途和相关操作顺序。

@opensumi opensumi bot added 🎨 feature feature required 🐞 bug Something isn't working labels Oct 25, 2024
Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

该拉取请求对多个文件进行了修改,主要增强了 $tryApplyWorkspaceEdit 方法,允许其接受一个可选的 metadata 参数,类型为 model.WorkspaceEditMetadataDto。同时,新增了 WorkspaceEditMetadataDto 接口,包含一个可选的布尔属性 isRefactoring,用于指示编辑是否为重构操作。相关的 applyEdit 方法也进行了相应的更新,以处理这些元数据。

Changes

文件路径 更改摘要
packages/extension/src/browser/vscode/api/main.thread.workspace.ts 更新 $tryApplyWorkspaceEdit 方法签名,添加可选参数 metadata
packages/extension/src/common/vscode/model.api.ts 新增接口 WorkspaceEditMetadataDto,包含可选属性 isRefactoring
packages/extension/src/common/vscode/workspace.ts 更新 IMainThreadWorkspace 接口中的 $tryApplyWorkspaceEdit 方法签名,添加可选参数 metadata
packages/extension/src/hosted/api/vscode/ext.host.workspace.ts 更新 ExtHostWorkspace 类中的 applyEdit 方法签名,添加可选参数 metadata。更新工作区 API 工厂函数中的 applyEdit 方法签名。
packages/types/sumi-worker/worker.editor.d.ts 新增接口 WorkspaceEditMetadata,包含可选属性 isRefactoring。更新 applyEdit 函数签名,添加可选参数 metadata
packages/types/vscode/typings/vscode.d.ts 新增接口 WorkspaceEditMetadata,包含可选属性 isRefactoring
packages/types/vscode/typings/vscode.workspace.d.ts 更新 vscode.workspace 模块中的 applyEdit 函数签名,添加可选参数 metadata

Possibly related PRs

Suggested labels

🎨 feature

Suggested reviewers

  • Ricbet

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

🧹 Outside diff range and nitpick comments (3)
packages/extension/src/browser/vscode/api/main.thread.workspace.ts (1)

121-123: 建议增加错误处理和日志记录

虽然实现正确,但建议在应用工作区编辑时添加更详细的错误处理和日志记录,特别是在涉及重构操作时。

建议按照以下方式改进实现:

 const { success } = (await this.bulkEditService.apply(edits, {
   respectAutoSaveConfig: metadata?.isRefactoring,
-})) as IBulkEditResult & { success: boolean };
+})) as IBulkEditResult & { success: boolean };
+if (!success && metadata?.isRefactoring) {
+  this.logger.warn('Failed to apply workspace edit during refactoring operation');
+}
packages/extension/src/common/vscode/model.api.ts (1)

66-68: 代码变更看起来不错,建议添加 JSDoc 注释

接口定义简洁明确,符合 TypeScript 接口命名规范。建议添加 JSDoc 注释以提供更好的文档说明。

建议添加如下注释:

+/**
+ * 工作区编辑元数据的数据传输对象
+ */
 export interface WorkspaceEditMetadataDto {
+  /**
+   * 标识此编辑是否为重构操作
+   */
   isRefactoring?: boolean;
 }
packages/types/sumi-worker/worker.editor.d.ts (1)

559-574: 文档更新全面,建议细化失败场景说明!

函数签名和文档的更新很完善。不过建议在文档中补充说明当 metadata.isRefactoring 为 true 时的具体行为影响。

建议在文档中添加以下说明:

  * @param metadata Optional {@link WorkspaceEditMetadata metadata} for the edit.
+ * When metadata.isRefactoring is true, the editor may optimize its behavior
+ * for refactoring operations, such as preserving the focus or handling undo/redo differently.
  * @returns A thenable that resolves when the edit could be applied.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d5d4dae and 016052d.

📒 Files selected for processing (7)
  • packages/extension/src/browser/vscode/api/main.thread.workspace.ts (1 hunks)
  • packages/extension/src/common/vscode/model.api.ts (1 hunks)
  • packages/extension/src/common/vscode/workspace.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/ext.host.workspace.ts (2 hunks)
  • packages/types/sumi-worker/worker.editor.d.ts (1 hunks)
  • packages/types/vscode/typings/vscode.d.ts (1 hunks)
  • packages/types/vscode/typings/vscode.workspace.d.ts (1 hunks)
🔇 Additional comments (8)
packages/extension/src/browser/vscode/api/main.thread.workspace.ts (2)

115-118: 方法签名更新符合 VSCode API 规范

方法签名的更新很好地保持了类型安全性,同时通过可选参数确保了向后兼容性。


115-123: 验证重构操作的自动保存行为

请确保在启用和禁用自动保存配置的情况下测试重构操作,以验证 respectAutoSaveConfig 的行为是否符合预期。

✅ Verification successful

重构操作的自动保存行为已得到验证

根据代码分析,respectAutoSaveConfig 参数通过 IBulkEditOptions 传递给 MonacoBulkEditService,该参数会根据重构操作的 isRefactoring 标志来决定是否遵循自动保存配置。这是一个合理的设计,因为:

  1. 重构操作需要特殊处理自动保存行为,以确保文件修改的原子性
  2. 代码中已实现了完整的自动保存配置系统,包括多种自动保存模式的支持
  3. 测试用例中包含了工作区编辑操作的验证
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索相关的测试用例
rg -l "respectAutoSaveConfig.*refactoring" --type ts

Length of output: 54


Script:

#!/bin/bash
# 搜索 bulkEditService 的实现和使用
ast-grep --pattern 'interface IBulkEditService {
  $$$
}'

# 搜索 respectAutoSaveConfig 的相关代码
rg "respectAutoSaveConfig" -A 5 --type ts

# 搜索与重构和自动保存相关的测试
rg "refactoring.*autosave|autosave.*refactoring" --type ts

Length of output: 739


Script:

#!/bin/bash
# 搜索 BulkEditService 的具体实现
ast-grep --pattern 'class $_ implements IBulkEditService {
  $$$
}'

# 查找与自动保存配置相关的代码
rg "autoSave" -A 5 --type ts

# 查找工作区编辑相关的测试文件
fd "workspace.*test" --type f --extension ts

Length of output: 28279


Script:

#!/bin/bash
# 检查 main.thread.workspace.test.ts 中的相关测试用例
cat packages/extension/__tests__/browser/main.thread.workspace.test.ts

# 查找 IBulkEditOptions 接口定义
ast-grep --pattern 'interface IBulkEditOptions {
  $$$
}'

# 查找 WorkspaceEditService 的实现
ast-grep --pattern 'class $_ implements IWorkspaceEditService {
  $$$
}'

Length of output: 26043

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

15-15: 接口方法签名更新符合预期

$tryApplyWorkspaceEdit 方法签名的更新通过添加可选的 metadata 参数增强了工作区编辑功能,同时保持了向后兼容性。这个改动与 VSCode API 的 WorkspaceEditMetadata 支持保持一致。

验证接口实现的一致性:

✅ Verification successful

接口实现已正确更新

MainThreadWorkspace 类中的 $tryApplyWorkspaceEdit 方法实现已经完全符合接口定义,正确包含了可选的 metadata 参数,并在方法实现中适当使用了 metadata.isRefactoring 属性来控制工作区编辑的行为。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证所有实现了 IMainThreadWorkspace 接口的类是否都正确更新了 $tryApplyWorkspaceEdit 方法签名

# 测试:搜索实现类中的方法定义
ast-grep --pattern 'class $_ implements IMainThreadWorkspace {
  $$$
  $tryApplyWorkspaceEdit($_, $_?) {
    $$$
  }
  $$$
}'

Length of output: 127


Script:

#!/bin/bash
# 使用 ripgrep 搜索实现了 IMainThreadWorkspace 接口的类
rg "class.*implements.*IMainThreadWorkspace" -l

# 搜索所有 $tryApplyWorkspaceEdit 方法的实现
rg "$tryApplyWorkspaceEdit.*\(.*\).*{" -A 1

Length of output: 226


Script:

#!/bin/bash
# 查找实现类文件的内容
cat packages/extension/src/browser/vscode/api/main.thread.workspace.ts

# 使用修正后的正则表达式搜索方法实现
rg "\$tryApplyWorkspaceEdit" -A 2

Length of output: 4919

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

73-73: 代码实现正确且符合规范!

applyEdit 函数签名的更新正确地添加了可选的 metadata 参数,并且保持了向后兼容性。参数传递符合 VSCode API 的设计规范。

packages/types/sumi-worker/worker.editor.d.ts (1)

546-554: 接口定义清晰且符合最佳实践!

WorkspaceEditMetadata 接口设计简洁明了,使用可选属性 isRefactoring 来标识编辑操作的性质是一个很好的设计选择。

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

60-75: 文档更新清晰完整!

文档详细说明了工作区编辑的行为,包括操作顺序、错误处理和边缘情况,并为新增的 metadata 参数提供了清晰的说明。


76-76: 函数签名更新符合预期!

新增的可选参数 metadata 保持了向后兼容性,建议验证现有调用处是否需要更新以利用新功能。

✅ Verification successful

Let me analyze the current calls to applyEdit to verify the impact of the signature change. I'll search for the actual implementations to understand how they handle the metadata parameter.


Let me try a different pattern to check the implementations:


Based on the search results, I can now provide a final response:

applyEdit 方法签名变更已得到正确实现!

从代码分析可以看到:

  • ext.host.workspace.ts 中的实现已正确处理了可选的 metadata 参数
  • 所有现有调用都与新签名保持兼容
  • 主要实现通过 $tryApplyWorkspaceEdit 方法传递 metadata 参数
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索 applyEdit 的现有调用以确认兼容性
rg "applyEdit\(" --type ts

Length of output: 1874


Script:

#!/bin/bash
# Check the implementation details of applyEdit calls
ast-grep --pattern 'applyEdit($$$) {
  $$$
}'

Length of output: 47


Script:

#!/bin/bash
# Search for applyEdit implementations with context
rg "applyEdit.*\{" -A 10 --type ts

Length of output: 17499

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

1483-1491: 代码实现正确且符合预期!

新增的 WorkspaceEditMetadata 接口设计合理:

  • isRefactoring 属性为可选布尔值,用于标识编辑操作是否为重构
  • 接口定义简洁明确,与 VSCode API 保持一致

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.25%. Comparing base (d5d4dae) to head (016052d).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4120      +/-   ##
==========================================
- Coverage   54.26%   54.25%   -0.01%     
==========================================
  Files        1598     1598              
  Lines       97564    97565       +1     
  Branches    19946    19947       +1     
==========================================
- Hits        52941    52934       -7     
- Misses      37074    37082       +8     
  Partials     7549     7549              
Flag Coverage Δ
jsdom 49.81% <100.00%> (-0.01%) ⬇️
node 15.59% <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
Member

@hacke2 hacke2 left a comment

Choose a reason for hiding this comment

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

LGTM

@hacke2 hacke2 merged commit 1d86c46 into main Oct 30, 2024
14 checks passed
@hacke2 hacke2 deleted the feat/support-WorkspaceEditMetadata branch October 30, 2024 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] API gap: OpenSumi main vs VS Code 1.84.0 (exclude notbook)
2 participants