-
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
feat: improve line change code edits trigger rule #4373
Conversation
Walkthrough此次提交对编辑器内智能补全功能进行了更新。主要修改包括:调整智能补全控制器的注册时机(由编辑器渲染后延迟改为立即初始化)、增加新的常量用于处理视图显示的有效时长、以及重构智能补全控制器和行变化的处理逻辑,采用了基于 observable 的事件订阅方式,此外还更新了 observable 工具模块的部分函数签名和新增观察器函数。 Changes
Sequence Diagram(s)sequenceDiagram
participant E as 编辑器
participant B as AINativeBrowserContribution
participant IC as IntelligentCompletionsController
participant O as Observable
participant L as LineChangeSource
E->>B: 启动编辑器
B->>IC: Eager 时注册智能补全控制器
IC->>O: 订阅多行编辑和内容变化事件
E->>L: 触发行变化或内容更新
L->>O: 发布更新事件
O-->>IC: 通知状态变化
IC->>IC: 调用 discard/accept 逻辑处理
Possibly related PRs
Suggested labels
Suggested reviewers
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
yarn install v1.22.22 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (8)
✨ Finishing Touches
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
🧹 Nitpick comments (6)
packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts (3)
28-33
: 存储弃用次数的映射可能存在生命周期管理隐患。
deprecatedStore
使用Map<string, number>
来记录弃用计数,但若编辑器中打开了很多文件并未及时调用accept
或discard
,该Map
可能逐渐增大。建议在对应模型被关闭或销毁后及时清理,防止潜在的内存泄漏。
64-96
: 对是否允许触发的计算逻辑建议支持可配置化。目前 60 秒的阈值写死在
CONTENT_CHANGE_VALID_TIME
常量里。若日后需要动态调整,可考虑将其加入到用户可配置项以增强灵活度。不过整体逻辑保持简单也很直观,视项目需求酌情处理即可。
98-150
: 弃用与接受逻辑令人关注未来交互和用户提示。
mount()
方法里对discard
和accept
分别更新deprecatedStore
,逻辑清晰。若在达到弃用上限后想提供用户提示或日志,可进一步在此处实现,以强化可观测与可维护性。packages/ai-native/src/browser/contrib/intelligent-completions/index.ts (1)
7-12
: 使用硬编码 750 毫秒作为有效弃用时长可能需要场景化讨论。数值虽然不大,但也可能不适用所有场景。除非本项目严格要求固定 750ms,否则可考虑提供配置或注释补充说明该数值的设计理由。
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (2)
353-384
: 优化了丢弃逻辑的实现使用
derivedHandleChanges
重构了丢弃逻辑,增加了基于时间的有效性验证机制。建议:
- 考虑将
VALID_TIME
的值作为可配置项,方便根据不同场景调整超时时间。- 添加日志记录,便于追踪丢弃操作的时间线。
386-412
: 接受更改的实现逻辑完善使用
derivedOpts
实现了更改接受的逻辑,并正确处理了虚拟编辑器的装饰器。建议添加错误处理:public accept = derivedOpts({ owner: this, equalsFn: () => false }, (reader) => { + try { const report = this.reportData.read(reader); report?.('isReceive'); this.multiLineDecorationModel.accept(); if (this.rewriteWidget) { this.rewriteWidget.accept(); // ... } this.hide(); + } catch (error) { + this.logger.error('Error accepting changes:', error); + this.hide(); + } });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/ai-native/src/browser/ai-core.contribution.ts
(1 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/index.ts
(1 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts
(7 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts
(3 hunks)packages/monaco/src/common/observable.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
- GitHub Check: unittest (ubuntu-latest, 18.x, node)
- GitHub Check: build (ubuntu-latest, 20.x)
- GitHub Check: ubuntu-latest, Node.js 20.x
- GitHub Check: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: build-windows
- GitHub Check: unittest (macos-latest, 18.x, node)
- GitHub Check: build (macos-latest, 20.x)
🔇 Additional comments (10)
packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts (5)
3-10
: 引入全局事件与可观测工具的导入看起来符合需求。这些新增的导入与项目整体可观测模型的用法保持一致,便于监听光标与内容变动事件,功能结构清晰。
12-12
: 智能补全控制器的引用。此导入对后续逻辑有重要作用,用来对接 discard/accept 等事件,导入配置无问题。
21-22
: 常量定义命名明确。
DEPRECATED_LIMIT
和CONTENT_CHANGE_VALID_TIME
命名易懂,符合业务场景。可快速理解其用途。
35-46
: 光标位置可观测对象的创建实现良好。通过
observableFromEvent
监听光标位置变动逻辑简单可依赖。无明显问题。
47-62
: 推导最新内容变动时间的派生逻辑清晰。
derivedHandleChanges
对变更时间进行记录,为后续判断是否触发有效编辑提供了基础,且符合常见可观测模式。packages/monaco/src/common/observable.ts (2)
2-6
: 新导入的接口和类型定义。添加
IObservable
,IObserver
,IReader
等,让可观测机制更易理解,暂无可见问题。
73-91
: 新增的onObservableChange
函数实现符合可观测范式。实现简单直观,可在多个观察者场景下灵活使用。功能上无明显问题,值得后续在更多场景推广。
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (2)
1-34
: 导入和常量声明看起来合理新增的导入和常量声明增强了状态管理和上下文变更的处理能力。
Also applies to: 64-64
100-123
: 使用 Observable 模式优化了可见性状态管理通过
observableFromEvent
实现了对多行编辑可见性状态的响应式管理,提高了代码的可维护性。packages/ai-native/src/browser/ai-core.contribution.ts (1)
262-264
:✅ Verification successful
更改了控制器的初始化时机
将
IntelligentCompletionsController
的实例化时机从AfterFirstRender
改为Eager
,这样可以更早地初始化控制器。需要注意:
- 提前初始化可能会影响编辑器的启动性能
- 建议添加性能监控,确保这个改动不会显著影响编辑器的加载时间
🏁 Script executed:
#!/bin/bash # 检查是否有其他组件也使用了 Eager 初始化 rg "EditorContributionInstantiation.Eager" -A 2 -B 2Length of output: 1489
调整初始化时机:请监控性能影响
我们注意到
IntelligentCompletionsController
的实例化时机从AfterFirstRender
调整为Eager
,这一变化使控制器能更早地初始化,并与packages/monaco/src/browser/monaco.contribution.ts
中相似的实现保持一致。请注意以下几点:
- 提前初始化可能会增加编辑器启动时的性能负担。
- 建议在合并变更后添加性能监控,确保这一改动不会显著影响编辑器的加载速度。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4373 +/- ##
==========================================
- Coverage 54.12% 54.09% -0.04%
==========================================
Files 1639 1639
Lines 100362 100425 +63
Branches 21784 21789 +5
==========================================
+ Hits 54320 54322 +2
- Misses 38246 38295 +49
- Partials 7796 7808 +12
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
packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts
Show resolved
Hide resolved
c42110c
to
f6b1b6f
Compare
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
规则一:未编辑过代码不触发,然后自上次编辑代码以来 60 秒内没有再次编辑过则不触发
规则二:当前文件弃用次数超过阈值(暂定 5 次)则不触发
Changelog
增加一些 line change 类型的 code edits 触发规则
Summary by CodeRabbit
新功能
重构