-
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: add code edits perferences #4155
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: 0
🧹 Outside diff range and nitpick comments (6)
packages/core-common/src/settings/ai-native.ts (1)
19-24
: 代码编辑设置的实现看起来不错,建议补充设置项的详细说明。新增的代码编辑设置遵循了现有的命名规范和命名空间模式。不过,建议为这两个新的设置项添加详细的 JSDoc 注释,说明它们的具体用途和预期行为,就像
InlineDiffPreviewMode
和IntelligentCompletionsPromptEngineeringEnabled
那样。建议添加如下注释:
/** * Code edits settings */ + /** + * 是否启用代码编辑时的 lint 错误检查 + */ CodeEditsLintErrors = 'ai.native.codeEdits.lintErrors', + /** + * 是否启用代码编辑时的行变更检查 + */ CodeEditsLineChange = 'ai.native.codeEdits.lineChange',packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts (1)
33-35
: 建议优化首选项检查的实现代码有以下几点可以改进:
- 默认值硬编码为 false 可能不够灵活
- 条件判断可以更清晰
- 缺少错误处理机制
建议按照以下方式重构:
- const isLineChangeEnabled = this.preferenceService.getValid(AINativeSettingSectionsId.CodeEditsLineChange, false); - - if (!isLineChangeEnabled || !position) { + try { + const isLineChangeEnabled = this.preferenceService.getValid( + AINativeSettingSectionsId.CodeEditsLineChange, + this.defaultPreferences.lineChangeEnabled ?? false + ); + + if (!position) { + return; + } + + if (!isLineChangeEnabled) { + return; + }另外,建议在类级别定义默认配置:
private readonly defaultPreferences = { lineChangeEnabled: false, } as const;packages/ai-native/src/browser/preferences/schema.ts (2)
53-56
: 建议添加首选项说明这个新增的
CodeEditsLintErrors
首选项缺少描述信息。建议添加description
字段来说明此功能的用途,以帮助用户理解该设置的作用。建议按如下方式修改:
[AINativeSettingSectionsId.CodeEditsLintErrors]: { type: 'boolean', default: false, + description: localize('preference.ai.native.codeEdits.lintErrors.description'), },
57-60
: 建议添加首选项说明并考虑默认值
- 同样需要为
CodeEditsLineChange
添加描述信息- 由于这两个功能都默认关闭,可能会影响功能的发现度。建议考虑是否将其默认开启,或在文档中明确说明这些新功能
建议按如下方式修改:
[AINativeSettingSectionsId.CodeEditsLineChange]: { type: 'boolean', default: false, + description: localize('preference.ai.native.codeEdits.lineChange.description'), },
packages/ai-native/src/browser/contrib/intelligent-completions/source/lint-error.source.ts (1)
94-96
: 建议优化条件判断的顺序当前实现中,即使
this.model
为空,也会先检查用户偏好设置。建议调整判断顺序以提高性能。建议按照以下方式重构:
- const isLintErrorsEnabled = this.preferenceService.getValid(AINativeSettingSectionsId.CodeEditsLintErrors, false); - - if (!isLintErrorsEnabled || !this.model) { + if (!this.model) { + return; + } + + const isLintErrorsEnabled = this.preferenceService.getValid(AINativeSettingSectionsId.CodeEditsLintErrors, false); + if (!isLintErrorsEnabled) { return; }这样可以:
- 避免在
this.model
为空时不必要的偏好设置检查- 提高代码的可读性,使逻辑更清晰
packages/ai-native/src/browser/ai-core.contribution.ts (1)
357-369
: 建议完善代码编辑功能的架构设计为了确保新增的设置项能够正确影响代码编辑功能的行为,建议:
- 在相关的代码编辑处理器中添加对这些设置的响应逻辑
- 考虑添加设置变更的事件监听,以便实时更新功能行为
- 为新增的设置项添加默认值配置
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
packages/ai-native/src/browser/ai-core.contribution.ts
(1 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/source/base.ts
(2 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts
(2 hunks)packages/ai-native/src/browser/contrib/intelligent-completions/source/lint-error.source.ts
(2 hunks)packages/ai-native/src/browser/preferences/schema.ts
(1 hunks)packages/core-common/src/settings/ai-native.ts
(1 hunks)packages/i18n/src/common/en-US.lang.ts
(1 hunks)packages/i18n/src/common/zh-CN.lang.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/i18n/src/common/zh-CN.lang.ts
🔇 Additional comments (7)
packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts (2)
2-2
: 导入声明看起来没有问题!
新增的 AINativeSettingSectionsId
导入正确地用于首选项检查。
33-33
: 验证首选项配置的完整性
需要确保首选项键 CodeEditsLineChange
在系统中被正确定义和使用。
运行以下脚本来验证首选项的定义和使用:
✅ Verification successful
Let me gather more information about the preference definition and usage.
首选项配置已正确定义和使用
首选项键 CodeEditsLineChange
在系统中已完整配置:
- 在
packages/core-common/src/settings/ai-native.ts
中定义了键名ai.native.codeEdits.lineChange
- 在
packages/ai-native/src/browser/preferences/schema.ts
中定义了布尔类型配置和默认值 - 在
packages/ai-native/src/browser/ai-core.contribution.ts
中注册了相应的本地化配置
当前代码中对该首选项的使用方式正确且符合预期。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查首选项键的定义
echo "检查 CodeEditsLineChange 的定义:"
rg -l "CodeEditsLineChange" --type ts
# 检查首选项的其他使用位置
echo "检查首选项的使用位置:"
ast-grep --pattern 'getValid($_, $AINativeSettingSectionsId.CodeEditsLineChange$_)'
Length of output: 590
Script:
#!/bin/bash
# 检查 CodeEditsLineChange 在 settings 定义文件中的具体定义
echo "在 settings 定义文件中的定义:"
rg "CodeEditsLineChange" packages/core-common/src/settings/ai-native.ts -A 3 -B 3
# 检查 schema 中的定义
echo "\n在 schema 文件中的定义:"
rg "CodeEditsLineChange" packages/ai-native/src/browser/preferences/schema.ts -A 3 -B 3
# 检查 contribution 中的使用
echo "\n在 contribution 文件中的使用:"
rg "CodeEditsLineChange" packages/ai-native/src/browser/ai-core.contribution.ts -A 3 -B 3
Length of output: 1085
packages/ai-native/src/browser/contrib/intelligent-completions/source/lint-error.source.ts (1)
2-8
: 导入声明看起来没有问题!
新增的 AINativeSettingSectionsId
导入与功能需求相符。
packages/ai-native/src/browser/contrib/intelligent-completions/source/base.ts (2)
2-2
: 导入语句正确添加!
PreferenceService 的导入位置恰当,且与新增的依赖注入属性相对应。
67-69
: 验证派生类中的 PreferenceService 使用情况
PreferenceService 的注入实现正确。由于这是一个基类的改动,建议验证所有派生类是否正确使用了这个新增的服务。
✅ Verification successful
Based on the search results, I can now generate the final response since I have enough information to verify the usage of preferenceService
in derived classes.
已验证 PreferenceService 在代码库中的使用情况
BaseCodeEditsSource 的派生类中没有直接使用 preferenceService 属性,但在基类中添加此属性是合理的,因为:
- 代码库中大量使用了 PreferenceService 来管理配置项
- 这个属性的添加为派生类提供了访问和管理配置的能力
- 使用 protected 访问级别确保了派生类可以安全地访问此服务
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:查找所有继承自 BaseCodeEditsSource 的类,以验证它们是否正确使用了 preferenceService
# 搜索继承自 BaseCodeEditsSource 的类定义
ast-grep --pattern 'export class $_ extends BaseCodeEditsSource {
$$$
}'
# 搜索这些类中是否使用了 preferenceService
rg "this\.preferenceService\." -A 3
Length of output: 66323
packages/ai-native/src/browser/ai-core.contribution.ts (1)
357-369
: 代码编辑设置部分实现正确!
设置部分的实现逻辑完整,并且正确地放置在了AI原生设置组中。建议为这些新的设置项添加详细的说明文档,以帮助用户更好地理解它们的用途。
运行以下脚本验证本地化键是否存在:
✅ Verification successful
本地化键已正确实现!
所有新添加的本地化键都已在中英文语言文件中完整定义,包括:
- 设置组标题
preference.ai.native.codeEdits.title
- Lint Error 智能改写开关
preference.ai.native.codeEdits.lintErrors
- Line Change 智能改写开关
preference.ai.native.codeEdits.lineChange
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:验证新添加的本地化键是否在语言文件中定义
# 测试:搜索本地化键。预期:在语言文件中找到对应的定义。
rg "preference\.ai\.native\.codeEdits\." packages/i18n/src/common/
Length of output: 781
packages/i18n/src/common/en-US.lang.ts (1)
1498-1501
: 本地化字符串添加正确!
新增的代码编辑首选项本地化字符串结构清晰,命名规范,与现有模式保持一致。
/next |
🎉 PR Next publish successful! 3.5.1-next-1730948411.0 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4155 +/- ##
=======================================
Coverage 54.22% 54.22%
=======================================
Files 1598 1598
Lines 97652 97663 +11
Branches 19976 19984 +8
=======================================
+ Hits 52954 52961 +7
- Misses 37125 37129 +4
Partials 7573 7573
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
Changelog
新增 code edits 相关配置项
Summary by CodeRabbit
新功能
文档