-
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: support code edits keybinding #4362
Conversation
Walkthrough本次 PR 主要对代码编辑功能进行了改进。更新集中在智能补全相关模块,替换了旧的多行补全命令为新的代码编辑命令,并增加了对应的按键绑定。在贡献模块中引入了 Changes
Sequence Diagram(s)sequenceDiagram
participant U as 用户
participant CC as IntelligentCompletionsContribution
participant IC as IntelligentCompletionsController
participant OS as 可观察信号
U->>CC: 触发 AI_CODE_EDITS_COMMANDS.TRIGGER 命令/按键
CC->>IC: 调用 trigger(tx) 方法
IC->>OS: 触发 codeEditsTriggerSignal (tx)
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 ✨ 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: 0
🧹 Nitpick comments (3)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1)
50-59
: 建议增加错误处理机制在执行
trigger
命令时,建议添加错误处理:
- 捕获并处理可能的异常
- 添加适当的错误提示
commands.registerCommand(AI_CODE_EDITS_TRIGGER, { execute: () => { const editor = this.workbenchEditorService.currentCodeEditor; if (editor) { + try { transaction((tx) => { IntelligentCompletionsController.get(editor.monacoEditor)?.trigger(tx); }); + } catch (error) { + // 处理错误,例如显示通知 + console.error('触发代码编辑失败:', error); + } } }, });packages/core-common/src/types/ai-native/index.ts (1)
84-89
: 建议增强类型约束为了提高类型安全性,建议为
triggerKeybinding
添加更具体的类型定义:export interface IAINativeCodeEditsConfig { /** * 触发 code edits 的快捷键 */ - triggerKeybinding?: string; + triggerKeybinding?: `${string}+${string}` | string; }packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (1)
401-403
: 建议为 trigger 方法添加 JSDoc 注释为了提高代码的可维护性和可读性,建议添加方法的用途说明、参数说明等文档。
+/** + * 触发代码编辑信号 + * @param tx 事务对象,用于批量处理状态更新 + */ public trigger(tx: ITransaction): void { this.codeEditsTriggerSignal.trigger(tx); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts
(3 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts
(4 hunks)packages/core-browser/src/ai-native/ai-config.service.ts
(4 hunks)packages/core-browser/src/ai-native/command.ts
(1 hunks)packages/core-common/src/types/ai-native/index.ts
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
- GitHub Check: build (ubuntu-latest, 20.x)
- GitHub Check: unittest (ubuntu-latest, 18.x, node)
- GitHub Check: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: build (macos-latest, 20.x)
- GitHub Check: unittest (macos-latest, 18.x, node)
- GitHub Check: build-windows
- GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (7)
packages/core-browser/src/ai-native/command.ts (1)
33-43
: 代码结构清晰,命名规范!新增的常量定义遵循了现有的命名模式,并且清晰地表达了其用途。
packages/core-browser/src/ai-native/ai-config.service.ts (2)
78-86
: 实现优雅,逻辑清晰!
codeEdits
getter的实现遵循了类中其他getter的模式,正确处理了配置合并逻辑。
36-38
: 请验证快捷键绑定的兼容性默认使用
alt+\
作为触发快捷键,建议验证:
- 是否与其他常用IDE或编辑器的快捷键冲突
- 在不同操作系统和键盘布局下的可用性
✅ Verification successful
🌐 Web query:
在主流IDE(VS Code, IntelliJ)中是否有使用 alt+\ 作为默认快捷键的功能?
💡 Result:
在主流IDE中,Visual Studio Code 和 IntelliJ IDEA 均未将
Alt + \
设置为默认快捷键。以下是具体分析:Visual Studio Code
- 默认布局操作:切换编辑器布局的默认快捷键为
Ctrl + \
(Windows/Linux)或⌘\
(Mac)[1][3][4]。- 多光标编辑:相关功能使用
Alt + Click
或Ctrl + Alt + ↓/↑
[1]。IntelliJ IDEA
- 布局调整:切换编辑器布局的默认快捷键为
Ctrl + Shift + F12
[1][3]。- 分屏操作:分屏编辑使用
Ctrl + Alt + Shift + 左/右方向键
[1]。其他相关功能对比
功能 VS Code 快捷键 IntelliJ IDEA 快捷键 切换侧边栏 Ctrl + B
Alt + 1
打开终端 Ctrl + `
Alt + F12
多光标选择 Alt + Click
Alt + J
(选中相同内容)如果需要使用
Alt + \
,可通过 自定义快捷键设置 实现(如修改键盘映射或安装插件)[9]。Citations:
- 1: https://blog.csdn.net/a940659387/article/details/143157344
- 2: https://www.warningrc.com/2018/06/12/idea-keyboard-shortcuts.html
- 3: https://blog.csdn.net/weixin_43820866/article/details/134999544
- 4: https://blog.csdn.net/adojayfan/article/details/115026938
- 5: https://www.cnblogs.com/pejsidney/p/8534312.html
- 6: https://yuzhigang.gitbooks.io/intellij-idea-tutorial/content/keymap-introduce.html
- 7: https://juejin.cn/post/7248804154016514085
- 8: https://intellijidea.com.cn/mastering-keyboard-shortcuts.html
- 9: https://blog.csdn.net/weixin_43577275/article/details/143055597
- 10: https://worktile.com/kb/ask/551325.html
快捷键绑定兼容性验证
经过查询,主流IDE(VS Code 和 IntelliJ IDEA)均未将
Alt + \
设置为默认快捷键,因此这项配置不会与它们默认的快捷键产生冲突。请继续采用当前配置;如发现特殊操作系统或键盘布局下存在问题,可考虑额外调整。
- 文件:
packages/core-browser/src/ai-native/ai-config.service.ts
(行 36-38)- 默认
triggerKeybinding
设置为alt+\
与 VS Code 和 IntelliJ IDEA 的默认快捷键无冲突packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1)
81-84
: 快捷键注册实现完善!使用配置服务获取触发快捷键,并正确注册了按键绑定。
packages/core-common/src/types/ai-native/index.ts (1)
101-104
: 文档完善,接口清晰!新增的配置项有完整的JSDoc注释,接口设计符合最佳实践。
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (2)
91-91
: 信号属性的类型和初始化看起来不错!
codeEditsTriggerSignal
的类型定义和初始化实现都很规范。Also applies to: 97-97
444-456
: handleChange 中的信号处理逻辑需要验证请确保在触发信号时不会与其他上下文变更产生冲突。建议添加测试用例验证这种情况。
❌ Verification inconclusive
🏁 Script executed:
#!/bin/bash # 搜索相关的测试文件 fd -g "*intelligent-completions.controller.test.ts" -x cat {} \; # 搜索信号处理相关的测试用例 rg -A 5 "codeEditsTriggerSignal"Length of output: 4442
信号处理逻辑验证反馈
目前在代码中通过对比
codeEditsSourceCollection.codeEditsContextBean
与codeEditsTriggerSignal
的变化来决定是否触发补全请求,逻辑上基本明确分离了两种触发情形。但在仓库中未发现针对这一逻辑的专门测试用例,无法完全确认在两信号同时发生或边缘情况时不会相互冲突。建议:
- 添加单元测试验证:
- 仅触发
codeEditsTriggerSignal
时返回true
;- 仅触发
codeEditsSourceCollection.codeEditsContextBean
时根据aiNativeContextKey.multiLineEditsIsVisible
的值返回相应逻辑;- 验证若两者同时发生时是否按预期处理(例如优先处理哪一信号,是否存在竞态或冲突情况)。
这种补充测试将有助于确保未来代码维护时行为的一致性和正确性。
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
🧹 Nitpick comments (2)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (2)
31-60
: 建议增加错误处理机制命令注册的实现逻辑清晰,但建议考虑以下改进:
- 在执行命令时增加 try-catch 块以处理潜在异常
- 当
IntelligentCompletionsController.get()
返回 null 时提供适当的错误提示建议参考以下改进方案:
commands.registerCommand(AI_CODE_EDITS_TRIGGER, { execute: () => { const editor = this.workbenchEditorService.currentCodeEditor; if (editor) { + try { + const controller = IntelligentCompletionsController.get(editor.monacoEditor); + if (!controller) { + console.warn('IntelligentCompletionsController not found'); + return; + } transaction((tx) => { - IntelligentCompletionsController.get(editor.monacoEditor)?.trigger(tx); + controller.trigger(tx); }); + } catch (error) { + console.error('Failed to execute code edits trigger:', error); + } } }, });
62-86
: 建议添加配置说明文档快捷键绑定的实现合理,特别是使用了配置服务来支持自定义触发键。建议添加以下改进:
- 为配置项添加注释,说明默认快捷键和自定义方式
- 考虑添加快捷键冲突检测机制
建议在代码前添加如下注释:
/** * 注册代码编辑相关的快捷键绑定 * * 支持的快捷键: * - 触发代码编辑:默认为 alt + \,可通过配置自定义 * - 接受编辑:Tab 键 * - 取消编辑:Esc 键 */ registerKeybindings(keybindings: KeybindingRegistry): void {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
- GitHub Check: unittest (ubuntu-latest, 18.x, node)
- GitHub Check: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: ubuntu-latest, Node.js 20.x
- GitHub Check: build-windows
- GitHub Check: build (ubuntu-latest, 20.x)
- GitHub Check: build (macos-latest, 20.x)
🔇 Additional comments (1)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1)
1-20
: 依赖注入和导入声明看起来结构合理!代码遵循了依赖注入的最佳实践,通过
@Autowired
装饰器注入AINativeConfigService
。Also applies to: 28-29
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4362 +/- ##
==========================================
- Coverage 54.19% 54.17% -0.02%
==========================================
Files 1639 1639
Lines 100278 100293 +15
Branches 21764 21759 -5
==========================================
- Hits 54341 54337 -4
- Misses 38173 38188 +15
- Partials 7764 7768 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
...i-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts
Outdated
Show resolved
Hide resolved
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 (1)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1)
46-55
: 建议优化错误处理新增的 trigger 命令实现中,建议添加错误处理逻辑以提高代码的健壮性。
commands.registerCommand(AI_CODE_EDITS_COMMANDS.TRIGGER, { execute: () => { const editor = this.workbenchEditorService.currentCodeEditor; if (editor) { + try { transaction((tx) => { IntelligentCompletionsController.get(editor.monacoEditor)?.trigger(tx); }); + } catch (error) { + console.error('Failed to trigger code edits:', error); + } } }, });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts
(3 hunks)packages/core-browser/src/ai-native/command.ts
(1 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: unittest (macos-latest, 18.x, jsdom)
- GitHub Check: build (macos-latest, 20.x)
- GitHub Check: build-windows
- GitHub Check: unittest (macos-latest, 18.x, node)
- GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (2)
packages/core-browser/src/ai-native/command.ts (1)
33-45
: 代码结构优化:命令统一管理将相关命令统一放在
AI_CODE_EDITS_COMMANDS
命名空间下管理是个很好的改进:
- 提高了代码的组织性和可维护性
- 命令 ID 遵循一致的命名规范
- 新增的
TRIGGER
命令支持了代码编辑的快捷键功能packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1)
3-3
: 配置服务集成合理通过依赖注入引入
AINativeConfigService
来管理配置是个不错的设计选择,使得代码编辑功能的配置更加灵活。Also applies to: 24-25
Types
Background or solution
默认 alt + \, 可配置调整
Changelog
支持快捷键触发 code edits
Summary by CodeRabbit