-
Notifications
You must be signed in to change notification settings - Fork 403
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
fix: diff editor model not exist error #4109
Conversation
Walkthrough此拉取请求主要涉及对 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant EditorService
participant DiffEditor
participant ConfigProvider
User->>ConfigProvider: 请求配置
ConfigProvider-->>User: 返回配置
User->>EditorService: 打开Diff编辑器
EditorService->>DiffEditor: 恢复状态
DiffEditor-->>EditorService: 返回状态
EditorService-->>User: 显示Diff编辑器
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: 0
🧹 Outside diff range and nitpick comments (2)
packages/editor/src/common/editor.ts (2)
992-992
: 新增的 getLineChanges 方法增强了差异编辑器的功能在 IDiffEditor 接口中添加 getLineChanges 方法是一个很好的改进。这个方法允许获取行级别的变更信息,可能对于以下场景很有用:
- 高亮显示具体的变更行
- 生成详细的差异报告
- 实现自定义的差异处理逻辑
建议考虑添加一些文档注释,说明返回值 ILineChange[] 的结构和可能的 null 情况。
993-1011
: 新增的 isTextEditorViewState 函数提高了类型安全性这个新增的函数很好地实现了对编辑器视图状态的类型检查,有助于提高代码的类型安全性。函数的实现逻辑看起来是正确的,并且涵盖了代码编辑器和差异编辑器的视图状态。
建议考虑以下小改进以提高可读性:
- 添加函数的文档注释,说明其用途和返回值含义。
- 考虑使用 early return 模式简化逻辑,例如:
if (!viewState) { return false; } if ('modified' in viewState) { return isTextEditorViewState(viewState.modified); } return !!( 'contributionsState' in viewState && 'viewState' in viewState && Array.isArray(viewState.cursorState) );这样可以减少嵌套并提高代码的可读性。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- packages/core-browser/src/react-providers/config-provider.tsx (0 hunks)
- packages/editor/src/browser/editor-collection.service.ts (5 hunks)
- packages/editor/src/browser/workbench-editor.service.ts (0 hunks)
- packages/editor/src/common/editor.ts (2 hunks)
💤 Files with no reviewable changes (2)
- packages/core-browser/src/react-providers/config-provider.tsx
- packages/editor/src/browser/workbench-editor.service.ts
🧰 Additional context used
🔇 Additional comments (8)
packages/editor/src/common/editor.ts (1)
25-26
: 新增的类型导入有助于改善编辑器状态管理这些新增的类型导入(ICodeEditorViewState 和 IDiffEditorViewState)看起来是为了增强编辑器视图状态的管理能力。这可能会改善编辑器状态的保存和恢复功能,提高用户体验。
packages/editor/src/browser/editor-collection.service.ts (7)
34-34
: 确认导入的有效性导入
isTextEditorViewState
用于后续状态类型检查,确保状态恢复过程的安全性和可靠性。
514-517
: 在销毁编辑器前保存当前状态在
dispose
方法中添加了调用this.saveCurrentState();
,确保在移除编辑器之前保存当前的视图状态,便于后续的状态恢复。
516-519
: 在状态恢复前验证状态类型在恢复视图状态前,检查
state
是否为有效的编辑器视图状态,确保只有有效的状态才会被恢复,防止潜在的错误。
619-619
: 更新restoreState
方法以接受选项参数
restoreState
方法增加了options: IResourceOpenOptions
参数,使其能够根据传入的选项调整状态恢复逻辑。
622-625
: 验证状态类型并调整光标状态以避免重复选中在恢复状态前,检查
state
是否为有效的编辑器视图状态。如果选项中指定了range
或originalRange
,则清空state.modified!.cursorState
以防止重复的光标选中状态。
658-659
: 移除模型缓存并直接创建视图模型
compare
方法中移除了缓存逻辑,直接通过this.monacoDiffEditor.createViewModel({ original, modified })
创建新的视图模型,简化了代码,提高了状态同步的可靠性。
673-676
: 在恢复状态前等待差异计算完成新增了
await model?.waitForDiff();
,确保在调用this.restoreState(options);
之前,差异计算已经完成,以防止在 Diff 尚未渲染时恢复状态而导致的问题。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4109 +/- ##
=======================================
Coverage 54.30% 54.30%
=======================================
Files 1596 1596
Lines 97473 97476 +3
Branches 19939 19948 +9
=======================================
+ Hits 52931 52935 +4
- Misses 36997 36998 +1
+ Partials 7545 7543 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Types
Background or solution
原有 Diff Editor 状态恢复失效主要是存在时序问题
即在新的 Diff Model 未渲染,不存在折叠代码等数据时进行恢复,最终导致恢复失败。
本次修复移除了多余的逻辑,让 Diff 编辑器的状态恢复时序回归正常留存,避免了 Model 丢失/未更新等问题出现
Changelog
修复 Diff 编辑器的状态恢复逻辑
Summary by CodeRabbit
新功能
AppConfig
接口中的enableRestoreDiffEditorState
属性,简化配置选项。getLineChanges
方法,以便在差异编辑器中检索行变更。修复
文档