-
Notifications
You must be signed in to change notification settings - Fork 384
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
Conversation
Walkthrough该拉取请求对多个文件进行了修改,主要增强了 Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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
标志来决定是否遵循自动保存配置。这是一个合理的设计,因为:
- 重构操作需要特殊处理自动保存行为,以确保文件修改的原子性
- 代码中已实现了完整的自动保存配置系统,包括多种自动保存模式的支持
- 测试用例中包含了工作区编辑操作的验证
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 搜索相关的测试用例 rg -l "respectAutoSaveConfig.*refactoring" --type tsLength 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 tsLength 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 tsLength 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 1Length of output: 226
Script:
#!/bin/bash # 查找实现类文件的内容 cat packages/extension/src/browser/vscode/api/main.thread.workspace.ts # 使用修正后的正则表达式搜索方法实现 rg "\$tryApplyWorkspaceEdit" -A 2Length 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 tsLength 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 tsLength of output: 17499
packages/types/vscode/typings/vscode.d.ts (1)
1483-1491
: 代码实现正确且符合预期!新增的
WorkspaceEditMetadata
接口设计合理:
isRefactoring
属性为可选布尔值,用于标识编辑操作是否为重构- 接口定义简洁明确,与 VSCode API 保持一致
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Types
Background or solution
Support VSCode API: WorkspaceEditMetadata
fix #4108
Changelog
Summary by CodeRabbit
新特性
文档
applyEdit
函数的文档,明确了新参数的用途和相关操作顺序。