-
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 VSCode API: EnvironmentVariableMutator.option #4169
Conversation
Walkthrough此次更改主要集中在环境变量处理的功能增强上。 Changes
Possibly related PRs
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
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options. 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/terminal-next/src/common/environmentVariable.ts (1)
116-118
: 接口定义清晰简洁!接口设计符合 VSCode API 规范,建议添加以下改进:
- 为接口添加 JSDoc 注释,说明
applyAtProcessCreation
的具体用途和默认值- 考虑添加示例代码展示其使用场景
+/** + * 配置环境变量修改器的行为选项 + * @property applyAtProcessCreation 是否在进程创建时应用变量修改,默认为 true + * @example + * ```ts + * const options: EnvironmentVariableMutatorOptions = { + * applyAtProcessCreation: false + * }; + * ``` + */ export interface EnvironmentVariableMutatorOptions { applyAtProcessCreation?: boolean; }packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (1)
615-620
: 建议添加 JSDoc 文档
prepend
方法的实现正确。建议为这三个方法添加 JSDoc 文档,说明options
参数的用途和默认值。示例文档:
+/** + * 在环境变量的开头添加值 + * @param variable 环境变量名 + * @param value 要添加的值 + * @param options 变更选项,默认 { applyAtProcessCreation: true } + */ prepend(variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts
(1 hunks)packages/terminal-next/src/common/environmentVariable.ts
(2 hunks)packages/terminal-next/src/common/environmentVariableCollection.ts
(2 hunks)packages/types/vscode/typings/vscode.d.ts
(3 hunks)
🔇 Additional comments (9)
packages/terminal-next/src/common/environmentVariable.ts (2)
123-123
: 属性定义正确!
readonly
修饰符的使用确保了接口的不可变性,类型定义准确。
153-153
: 接口更新合理,建议验证实现!
接口更新保持了与公共 API 的一致性,但需要确保所有实现类都正确提供了这个新属性。
✅ Verification successful
Let me gather more information about the implementation details.
接口更新已验证,无需进一步修改
经过代码分析,这个更改是安全的,原因如下:
- 文件中只有接口定义
IEnvironmentVariableMutator
,没有具体实现类 IEnvironmentVariableMutator
接口是作为数据类型使用,主要用于序列化和反序列化操作- 新增的
options
属性与现有的EnvironmentVariableMutator
接口保持一致 - 文件中的序列化/反序列化函数可以正确处理包含
options
的对象
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 搜索所有实现了 IEnvironmentVariableMutator 接口的类
ast-grep --pattern 'class $_ implements IEnvironmentVariableMutator'
# 搜索所有创建 IEnvironmentVariableMutator 对象的地方
rg -l "IEnvironmentVariableMutator"
Length of output: 163
Script:
#!/bin/bash
# 查看完整的文件内容以分析实现细节
cat packages/terminal-next/src/common/environmentVariable.ts
Length of output: 5960
packages/terminal-next/src/common/environmentVariableCollection.ts (3)
45-45
: 代码变更正确实现了选项保存!
在构造函数中正确地保存了 mutator 的 options 属性,这与其他属性的处理方式保持一致,为后续的环境变量处理提供了必要的配置信息。
67-79
: 环境变量条件应用逻辑实现正确!
通过 options?.applyAtProcessCreation ?? true
的设计,既支持了新的选项功能,又保持了向后兼容性。代码结构清晰,逻辑完整。
67-79
: 建议验证多个修改器的交互场景
当多个修改器同时作用于同一环境变量时,需要确保条件应用的行为符合预期。
✅ Verification successful
环境变量修改器的行为已经得到充分验证
通过代码分析发现:
-
测试用例已经覆盖了环境变量修改器的基本功能,包括:
- 单个变量的替换(Replace)、追加(Append)和前置(Prepend)操作
- 环境变量集合的差异比较
- 多个环境变量的并发处理
-
修改器的实现遵循了明确的优先级顺序:
- Replace (type=1):完全替换现有值
- Append (type=2):追加到现有值末尾
- Prepend (type=3):添加到现有值开头
-
代码中的条件应用(applyAtProcessCreation)确保了修改器按预期工作,不会产生意外的交互问题。
因此,当前实现已经充分考虑了多个修改器的交互场景,无需额外修改。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 搜索测试用例中的多重修改器场景
rg -l "describe.*EnvironmentVariableCollection.*multiple" -g "*.test.ts"
# 检查是否存在相关的集成测试
ast-grep --pattern 'describe($_, $_) {
$$$
it($_, $_) {
$$$
environmentVariableCollection
$$$
}
}'
Length of output: 193
Script:
#!/bin/bash
# 搜索所有与 EnvironmentVariableCollection 相关的测试文件
rg -l "EnvironmentVariableCollection" -g "*.test.ts"
# 查找所有与环境变量修改器相关的测试用例
rg -A 10 "describe.*EnvironmentVariableCollection" -g "*.test.ts"
# 查找代码中所有使用多个修改器的场景
ast-grep --pattern 'environmentVariableCollection.append($$$).prepend($$$)'
ast-grep --pattern 'environmentVariableCollection.append($$$).replace($$$)'
ast-grep --pattern 'environmentVariableCollection.prepend($$$).append($$$)'
Length of output: 1853
Script:
#!/bin/bash
# 查看环境变量集合测试文件的完整内容
cat packages/terminal-next/__tests__/common/environmentVariableCollection.test.ts
# 查找测试文件中涉及多个修改器的场景
rg -B 2 -A 5 "type: \d" packages/terminal-next/__tests__/common/environmentVariableCollection.test.ts
# 搜索代码中所有的修改器类型定义
ast-grep --pattern 'enum EnvironmentVariableMutatorType {
$$$
}'
Length of output: 6402
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (2)
599-604
: 实现正确且完整!
replace
方法的实现正确地支持了 EnvironmentVariableMutatorOptions
选项,并为 applyAtProcessCreation
设置了合理的默认值。
607-612
: 实现正确且完整!
append
方法的实现与 replace
保持一致,正确处理了选项参数。
packages/types/vscode/typings/vscode.d.ts (2)
3065-3081
: 新增的 EnvironmentVariableMutatorOptions 接口实现完整!
接口定义清晰,属性说明完整:
applyAtProcessCreation
: 控制在进程创建时是否应用变量修改,默认为 trueapplyAtShellIntegration
: 控制在 shell 集成脚本中是否应用变量修改,默认为 false
注意 applyAtShellIntegration
属性标记为 stubbed,表明这是一个待实现的功能。
3116-3152
: 环境变量集合接口方法更新合理!
replace
、append
和 prepend
方法都统一添加了可选的 options
参数:
- 参数类型为
EnvironmentVariableMutatorOptions
- 文档清晰说明了每个变量只能进行一次修改的限制
- 保持了向后兼容性,因为 options 参数是可选的
实现符合 TypeScript 接口设计最佳实践。
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/extension/__tests__/hosted/api/vscode/ext.host.terminal.test.ts (2)
260-269
: 测试用例正确验证了环境变量的序列化格式测试用例完整地覆盖了 append 操作的序列化输出,包括新增的 options 属性。建议增加对 options 中 applyAtProcessCreation 为 false 的场景测试。
314-314
: 建议增强 get 方法的测试覆盖率当前测试验证了完整的返回结构,但建议添加对各个属性值的独立断言,以提高测试的精确性和可维护性。例如:
expect(value?.type).toBe(3); expect(value?.value).toBe('BAR3'); expect(value?.options.applyAtProcessCreation).toBe(true);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/extension/__tests__/hosted/api/vscode/ext.host.terminal.test.ts
(4 hunks)
🔇 Additional comments (2)
packages/extension/__tests__/hosted/api/vscode/ext.host.terminal.test.ts (2)
278-287
: 序列化格式符合预期
replace 操作的序列化测试正确验证了变更类型(type: 1)和新增的 options 属性。测试结构保持了良好的一致性。
296-305
: 测试覆盖完整且结构一致
prepend 操作的序列化测试与其他操作保持了一致的结构,正确验证了所有必要属性。
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4169 +/- ##
=======================================
Coverage 54.07% 54.08%
=======================================
Files 1610 1610
Lines 97796 97809 +13
Branches 20019 20027 +8
=======================================
+ Hits 52885 52897 +12
+ Misses 37310 37309 -1
- Partials 7601 7603 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
* feat: add typings * feat: support environmentVariableMutator.option * fix: fix test
Types
Background or solution
Support VSCode API: EnvironmentVariableMutator.option
Changelog
Summary by CodeRabbit
EnvironmentVariableMutatorOptions
接口,允许用户在修改环境变量时提供更多配置选项。replace
、append
和prepend
方法,支持可选的options
参数,以增强环境变量管理的灵活性。applyAtProcessCreation
选项设置为true
,确保现有行为不受影响。