-
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: support AutoClosingPair #4117
Conversation
Walkthrough本次更改主要涉及对语言配置的增强,特别是添加了 Changes
Assessment against linked issues
Possibly related PRs
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: 1
🧹 Outside diff range and nitpick comments (1)
packages/extension/src/common/vscode/utils.ts (1)
147-158
: 建议添加输入验证和文档注释函数实现逻辑正确,但建议做以下改进:
- 添加对
open
和close
字符串的非空验证- 添加 JSDoc 文档说明函数的用途、参数和返回值
建议的改进实现:
+/** + * 序列化 AutoClosingPair 数组为可序列化格式 + * @param pairs VSCode AutoClosingPair 数组 + * @returns 序列化后的 AutoClosingPair 数组,如果输入为 undefined 则返回 undefined + */ export function serializeAutoClosingPairs( pairs: vscode.AutoClosingPair[] | undefined, ): SerializedAutoClosingPair[] | undefined { if (!pairs) { return undefined; } return pairs.map((pair) => { + if (!pair.open || !pair.close) { + throw new Error('AutoClosingPair must have non-empty open and close strings'); + } return { open: pair.open, close: pair.close, notIn: pair.notIn ? pair.notIn.map((tokenType) => types.SyntaxTokenType.toString(tokenType)) : undefined, }; }); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- packages/extension/src/browser/vscode/api/main.thread.language.ts (1 hunks)
- packages/extension/src/common/vscode/ext-types.ts (1 hunks)
- packages/extension/src/common/vscode/model.api.ts (1 hunks)
- packages/extension/src/common/vscode/utils.ts (2 hunks)
- packages/extension/src/hosted/api/vscode/ext.host.language.ts (2 hunks)
- packages/types/vscode/typings/vscode.language.d.ts (2 hunks)
🧰 Additional context used
🪛 Biome
packages/extension/src/common/vscode/ext-types.ts
[error] 1029-1029: Do not shadow the global "toString" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
🔇 Additional comments (10)
packages/extension/src/common/vscode/utils.ts (1)
5-10
: 导入声明看起来没有问题!导入语句的位置和分组符合现有代码风格,与其他序列化相关的接口放在一起很合理。
packages/extension/src/common/vscode/model.api.ts (2)
162-166
: 代码结构清晰,符合预期!
SerializedAutoClosingPair
接口定义完整,属性类型合理,符合 VSCode API 的设计规范。
174-174
: 配置项集成正确!在
SerializedLanguageConfiguration
接口中添加autoClosingPairs
可选属性,类型定义准确,位置合理。packages/extension/src/browser/vscode/api/main.thread.language.ts (1)
1094-1094
: 自动闭合对的支持已正确实现!该实现通过在语言配置中添加
autoClosingPairs
属性,完美地集成了 VSCode 的自动闭合对特性。这个改动简洁明确,符合 VSCode API 的规范。packages/extension/src/hosted/api/vscode/ext.host.language.ts (2)
122-127
: 导入语句组织合理!新增的
serializeAutoClosingPairs
导入与其他序列化工具函数放在一起,保持了良好的代码组织结构。
1188-1188
: 配置对象正确集成了自动闭合对的支持!建议验证自动闭合对的序列化实现是否与 VSCode 的行为保持一致。
运行以下脚本来验证
autoClosingPairs
的使用:✅ Verification successful
Let me generate one more verification script to check for the
serializeAutoClosingPairs
function implementation since it wasn't found in the first search.
Let me check one final thing - the serialization utility implementation:
自动闭合对的实现已完全验证通过!
通过代码分析,我们可以确认:
serializeAutoClosingPairs
函数实现正确,能够完整序列化 VSCode 的AutoClosingPair
对象- 序列化后的配置与 Monaco Editor 的语言配置格式兼容
- 实现遵循了 VSCode API 的规范
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 描述:检查 autoClosingPairs 的使用情况和实现 # 测试:搜索 autoClosingPairs 的使用。预期:找到相关的类型定义和实现。 rg -A 5 'autoClosingPairs' # 测试:搜索序列化函数的实现。预期:找到 serializeAutoClosingPairs 的定义。 ast-grep --pattern 'function serializeAutoClosingPairs'Length of output: 14694
Script:
#!/bin/bash # Search for the serialization function with more context rg -A 10 'serializeAutoClosingPairs' packages/extension/src/hosted/api/vscode/ext.host.language.ts # Search for any serialization related functions in the same file rg 'serialize.*Pairs' packages/extension/src/hosted/api/vscode/ext.host.language.tsLength of output: 1116
Script:
#!/bin/bash # Search for the serialization utility implementation rg -A 10 "export function serializeAutoClosingPairs" packages/extension/src/common/vscode/utils.tsLength of output: 470
packages/extension/src/common/vscode/ext-types.ts (1)
1022-1027
: 语法标记类型枚举定义正确!枚举
SyntaxTokenType
定义了四种基本的语法标记类型,这些类型对于实现 AutoClosingPair 功能是必要的。枚举值的设计符合 VSCode API 的规范。packages/types/vscode/typings/vscode.language.d.ts (3)
1587-1608
: 枚举定义清晰且文档完整!
SyntaxTokenType
枚举很好地定义了常见的语法标记类型,包括:
- Other (0): 默认类型
- Comment (1): 注释
- String (2): 字符串
- RegEx (3): 正则表达式
枚举值的排序合理,文档注释清晰。
1610-1626
: 接口设计合理且具有良好的扩展性!
AutoClosingPair
接口定义了自动闭合对的结构:
open
: 触发自动插入的开始字符串close
: 自动插入的结束字符串notIn
: 可选的SyntaxTokenType
数组,用于指定不应自动闭合的上下文接口设计简洁明了,且通过
notIn
提供了细粒度的控制能力。
1654-1657
: 接口扩展符合向后兼容性要求!在
LanguageConfiguration
接口中添加了可选的autoClosingPairs
属性:
- 类型为
AutoClosingPair[]
- 使用
?
标记为可选,保证了向后兼容性- 属性放置位置合理,便于维护
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4117 +/- ##
=======================================
Coverage 54.26% 54.26%
=======================================
Files 1598 1598
Lines 97569 97584 +15
Branches 19957 19962 +5
=======================================
+ Hits 52942 52951 +9
- Misses 37075 37078 +3
- Partials 7552 7555 +3
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- packages/extension/src/common/vscode/ext-types.ts (1 hunks)
🧰 Additional context used
🪛 Biome
packages/extension/src/common/vscode/ext-types.ts
[error] 1038-1038: Do not shadow the global "toString" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
🔇 Additional comments (2)
packages/extension/src/common/vscode/ext-types.ts (2)
1022-1027
: 代码结构清晰,枚举定义合理!枚举值设计合理,涵盖了语法标记的主要类型,并且遵循了从0开始的标准枚举值设计模式。
1028-1036
: 类型定义和映射实现优雅!命名空间的实现采用了类型别名和常量映射的方式,使得类型转换既安全又高效。
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
Support VSCode API: AutoClosingPair
Changelog
close #4108
Summary by CodeRabbit
新功能
接口更新
SerializedAutoClosingPair
接口,定义自动闭合对的结构。SerializedLanguageConfiguration
接口,支持autoClosingPairs
属性。工具函数
serializeAutoClosingPairs
函数,用于序列化自动闭合对。