-
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: GlobalEnvironmentVariableCollectoin #4171
feat:support VSCode API: GlobalEnvironmentVariableCollectoin #4171
Conversation
Walkthrough此拉取请求引入了一个新的 Changes
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
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 (8)
packages/core-common/src/index.ts (1)
38-38
: 导出语句的位置建议调整建议将相关的导出语句进行分组组织,将集合相关的导出与其他数据结构相关的导出(如 comparers)放在一起,以提高代码的可维护性。
建议应用以下更改:
export * from './comparers'; +export * from './collections'; export * from './problem-pattern'; -export * from './collections';packages/extension/src/common/vscode/terminal.ts (1)
102-102
: 建议添加方法文档建议为
getEnvironmentVariableCollection
方法添加 JSDoc 文档,说明:
- 方法的用途
- 参数
extension
的作用- 返回值
GlobalEnvironmentVariableCollection
的使用说明+ /** + * 获取指定扩展的全局环境变量集合 + * @param extension 扩展属性 + * @returns 全局环境变量集合实例 + */ getEnvironmentVariableCollection(extension: IExtensionProps): vscode.GlobalEnvironmentVariableCollection;packages/core-common/src/collections.ts (3)
21-21
: 建议为rootMap添加类型注解以提高类型安全性当前
rootMap
未指定类型,可以考虑为其添加类型注解,提升代码的类型安全性和可读性。建议修改为:
- private rootMap = new Map(); + private rootMap = new Map<K, any>();
35-36
: 建议使用更具体的错误类型在多个方法中,当键长度不符合要求时,抛出了通用的
Error
。为提高错误信息的清晰度和代码的可维护性,建议使用更具体的错误类型,如RangeError
或自定义错误。例如,修改为:
- throw new Error(`inappropriate key length: ${key.length}, should be ${this.keyLength}`); + throw new RangeError(`Invalid key length: ${key.length}, expected: ${this.keyLength}`);Also applies to: 53-54, 72-73, 91-92
112-122
: 优化doForeach方法的类型注解在
doForeach
方法中,使用了any
类型,可能会降低类型安全性。建议为参数和内部变量添加具体的类型注解,以增强类型检查和代码可读性。例如,修改为:
- // eslint-disable-next-line @typescript-eslint/no-explicit-any - private doForeach(handler: (value: V, key: K[]) => void, currentMap: Map<any, any>, keys: K[]): void { + private doForeach(handler: (value: V, key: K[]) => void, currentMap: Map<K, any> | Map<K, V>, keys: K[]): void {packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (1)
600-601
: 无需禁用未使用变量的 eslint 规则参数
_scope
已经以下划线开头,根据 eslint 规则,未使用的参数会被自动忽略。因此,第600行的// eslint-disable-next-line @typescript-eslint/no-unused-vars
注释是多余的,可以安全地移除以简化代码。packages/types/vscode/typings/vscode.d.ts (2)
3187-3201
: 建议优化getScoped
方法的注释以提高可读性。当前注释中的一些句子较为复杂,可能导致理解困难。建议对注释进行简化,使其更加清晰易懂。
建议修改注释如下:
/** * 获取适用于指定作用域的环境变量集合。这使得能够仅在指定的作用域内修改终端环境变量,新的集合将在全局集合之后应用。 * - * Each object obtained through this method is isolated and does not impact objects for other scopes, - * including the global collection. + * 通过此方法获得的每个对象都是独立的,不会影响其他作用域(包括全局集合)中的对象。 * * @param scope 环境变量集合适用的作用域。 * - * If a scope parameter is omitted, collection applicable to all relevant scopes for that parameter is - * returned. For instance, if the 'workspaceFolder' parameter is not specified, the collection that applies - * across all workspace folders will be returned. + * 如果省略了 scope 参数,将返回适用于所有相关作用域的集合。例如,如果未指定 'workspaceFolder' 参数,将返回适用于所有工作区文件夹的集合。 * * @returns 指定作用域的环境变量集合。 */
3205-3214
:EnvironmentVariableScope
接口定义清晰,但可补充更多说明。目前
EnvironmentVariableScope
接口只有一个可选属性workspaceFolder
。建议在注释中提供更多关于该属性的使用示例,以帮助开发者更好地理解其用途。建议在注释中添加使用示例:
/** * 环境变量集合适用的作用域对象。 */ export interface EnvironmentVariableScope { /** * 指定要获取其环境变量集合的特定工作区文件夹。 + * + * 示例: + * ```typescript + * const envCollection = globalEnvVarCollection.getScoped({ workspaceFolder: myWorkspaceFolder }); + * ``` */ workspaceFolder?: WorkspaceFolder; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (9)
packages/core-common/src/collections.ts
(1 hunks)packages/core-common/src/index.ts
(1 hunks)packages/extension/__tests__/hosted/api/vscode/ext.host.terminal.test.ts
(1 hunks)packages/extension/src/common/extension.ts
(1 hunks)packages/extension/src/common/vscode/terminal.ts
(1 hunks)packages/extension/src/hosted/api/vscode/env/envApiFactory.ts
(1 hunks)packages/extension/src/hosted/api/vscode/ext.host.extensions.ts
(1 hunks)packages/extension/src/hosted/api/vscode/ext.host.terminal.ts
(7 hunks)packages/types/vscode/typings/vscode.d.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- packages/extension/tests/hosted/api/vscode/ext.host.terminal.test.ts
- packages/extension/src/common/extension.ts
- packages/extension/src/hosted/api/vscode/ext.host.extensions.ts
🔇 Additional comments (7)
packages/core-common/src/index.ts (1)
38-38
: 验证 collections 模块的实现
需要确认新导出的 collections 模块是否正确实现了 VSCode API 的 GlobalEnvironmentVariableCollection 接口要求。
运行以下脚本以验证实现:
packages/extension/src/hosted/api/vscode/env/envApiFactory.ts (1)
84-86
: 代码更改正确实现了 GlobalEnvironmentVariableCollection API 支持
环境变量集合的 getter 实现看起来正确,通过扩展上下文获取全局环境变量集合。
运行以下脚本验证相关接口实现:
✅ Verification successful
Let me gather more information about the implementation details.
GlobalEnvironmentVariableCollection 实现验证完成
代码实现完全符合预期:
EnvironmentVariableCollection
类正确实现了GlobalEnvironmentVariableCollection
接口- 包含了所有必要的方法(
replace
、append
、prepend
、get
、delete
、clear
等) - 正确处理了持久化属性和作用域相关功能
- 通过
_onDidChangeCollection
事件正确通知变更
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:验证 GlobalEnvironmentVariableCollection 接口实现和使用
# 检查接口定义
ast-grep --pattern 'interface GlobalEnvironmentVariableCollection {
$$$
}'
# 检查实现类
ast-grep --pattern 'class $_ implements GlobalEnvironmentVariableCollection {
$$$
}'
# 检查使用情况
rg "GlobalEnvironmentVariableCollection"
Length of output: 810
Script:
#!/bin/bash
# Check the implementation of EnvironmentVariableCollection class
ast-grep --pattern 'class EnvironmentVariableCollection implements vscode.GlobalEnvironmentVariableCollection {
$$$
}'
# Check the implementation of getEnvironmentVariableCollection method
ast-grep --pattern 'getEnvironmentVariableCollection($_) {
$$$
}'
# Check the interface definition in vscode.d.ts
rg -A 5 "interface GlobalEnvironmentVariableCollection extends EnvironmentVariableCollection" packages/types/vscode/typings/vscode.d.ts
Length of output: 8988
packages/extension/src/common/vscode/terminal.ts (1)
102-102
: 验证类型更改的兼容性
请确认 GlobalEnvironmentVariableCollection
是否继承自 EnvironmentVariableCollection
,以避免破坏现有的调用代码。
✅ Verification successful
Let me gather more information about the type definitions to verify the compatibility.
Let me try one more search to find the type definitions in other possible locations.
类型更改是安全的,无需担心兼容性问题
根据代码分析,我们可以确认:
GlobalEnvironmentVariableCollection
确实继承自EnvironmentVariableCollection
- 现有实现类
EnvironmentVariableCollection
已经实现了GlobalEnvironmentVariableCollection
接口 - 所有调用处都能正确处理这个类型
这个类型更改是向后兼容的,不会破坏现有代码。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查 GlobalEnvironmentVariableCollection 的类型定义和继承关系
# 搜索 GlobalEnvironmentVariableCollection 的定义
ast-grep --pattern 'interface GlobalEnvironmentVariableCollection extends $_'
# 搜索现有代码中对 getEnvironmentVariableCollection 的调用
rg -A 2 'getEnvironmentVariableCollection'
Length of output: 2126
Script:
#!/bin/bash
# 搜索 vscode 类型定义中的 EnvironmentVariableCollection 相关定义
rg -A 5 "EnvironmentVariableCollection" packages/extension/src/types/vscode.d.ts
# 搜索 GlobalEnvironmentVariableCollection 的使用和实现
rg -A 5 "GlobalEnvironmentVariableCollection" packages/extension/src/types/vscode.d.ts
# 搜索实际的实现类
ast-grep --pattern 'class $_ implements GlobalEnvironmentVariableCollection'
Length of output: 408
Script:
#!/bin/bash
# 搜索所有可能包含类型定义的文件
fd -e d.ts -x rg -A 5 "EnvironmentVariableCollection|GlobalEnvironmentVariableCollection" {}
# 搜索实现文件中的类型关系
rg -A 5 "implements.*EnvironmentVariableCollection"
# 查找可能的类型导入
rg "@types/vscode"
Length of output: 3193
packages/core-common/src/collections.ts (1)
70-73
: 注意方法中键长度处理不一致
在has
和delete
方法中,允许键的长度小于等于keyLength
,而在set
和get
方法中,要求键的长度必须等于keyLength
。请确认这是否为预期行为,或考虑统一键长度的处理方式,以避免使用上的混淆。
Also applies to: 89-92
packages/extension/src/hosted/api/vscode/ext.host.terminal.ts (2)
67-67
: 使用 MultiKeyMap 实现多级键映射
在第67行中,将 environmentVariableCollections
的类型更改为 MultiKeyMap<string, EnvironmentVariableCollection>
,支持基于 extension.id
和 rootUri
的多级键。这样可以更高效地管理环境变量集合,代码实现正确。
528-537
: 正确实现了 getEnvironmentVariableCollection 方法
在第528-537行,修改了 getEnvironmentVariableCollection
方法,增加了 rootUri
参数,并使用多级键获取或创建环境变量集合。匿名子类中重写了 getScoped
方法,实现了对作用域特定的环境变量集合的支持,设计合理,逻辑清晰。
packages/types/vscode/typings/vscode.d.ts (1)
3182-3204
: 新增的接口设计合理,命名清晰。
GlobalEnvironmentVariableCollection
接口清晰地扩展了 EnvironmentVariableCollection
,支持全局作用域的环境变量集合,这对于在所有作用域中管理环境变量非常有用。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4171 +/- ##
==========================================
- Coverage 54.07% 54.06% -0.01%
==========================================
Files 1610 1612 +2
Lines 97809 97911 +102
Branches 20035 20051 +16
==========================================
+ Hits 52892 52940 +48
- Misses 37314 37360 +46
- Partials 7603 7611 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
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
* feat: add typings * chore: fix typo * feat: api support
Types
Background or solution
Support VSCode API: GlobalEnvironmentVariableCollectoin
Changelog
Summary by CodeRabbit
MultiKeyMap
类,提供多层次键值管理。NO_ROOT_URI
常量,表示无根 URI 的情况。GlobalEnvironmentVariableCollection
接口,支持按范围检索环境变量集合。getEnviromentVariableCollection
方法名为getEnvironmentVariableCollection
,确保一致性。ExtHostTerminal
类以支持多键结构,改进环境变量管理。EnvironmentVariableCollection
类,使其扩展GlobalEnvironmentVariableCollection
。