Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

bk1012
Copy link
Member

@bk1012 bk1012 commented Oct 24, 2024

Types

  • 🎉 New Features

Background or solution

Support VSCode API: AutoClosingPair

Changelog

close #4108

Summary by CodeRabbit

  • 新功能

    • 增强语言配置功能,支持自动闭合对(如括号和引号)。
    • 新增语法标记类型枚举,提供更结构化的语法标记分类。
  • 接口更新

    • 添加 SerializedAutoClosingPair 接口,定义自动闭合对的结构。
    • 更新 SerializedLanguageConfiguration 接口,支持 autoClosingPairs 属性。
  • 工具函数

    • 新增 serializeAutoClosingPairs 函数,用于序列化自动闭合对。

Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Walkthrough

本次更改主要涉及对语言配置的增强,特别是添加了 autoClosingPairs 属性,以支持自动闭合对括号和引号的功能。相关的接口和枚举也进行了扩展,包括新增的 SyntaxTokenType 枚举和 SerializedAutoClosingPair 接口。这些更改影响了多个文件,确保了语言配置的灵活性和可扩展性,但未对现有逻辑或控制流进行重大修改。

Changes

文件路径 更改摘要
packages/extension/src/browser/vscode/api/main.thread.language.ts 更新了 MainThreadLanguages 类中的 $setLanguageConfiguration 方法,添加了 autoClosingPairs 属性。
packages/extension/src/common/vscode/ext-types.ts 新增 SyntaxTokenType 枚举及其对应的 toString 方法。
packages/extension/src/common/vscode/model.api.ts 新增 SerializedAutoClosingPair 接口,并更新 SerializedLanguageConfiguration 接口以包含 autoClosingPairs 属性。
packages/extension/src/common/vscode/utils.ts 新增 serializeAutoClosingPairs 方法,导入 SerializedAutoClosingPair
packages/extension/src/hosted/api/vscode/ext.host.language.ts 更新 setLanguageConfiguration 方法,添加对 autoClosingPairs 的支持。
packages/types/vscode/typings/vscode.language.d.ts 新增 SyntaxTokenType 枚举和 AutoClosingPair 接口,并更新 LanguageConfiguration 接口以包含 autoClosingPairs 属性。

Assessment against linked issues

Objective Addressed Explanation
支持 AutoClosingPair (#[4108])
支持 autoClosingPairs 属性 (#[4108])

Possibly related PRs

Suggested reviewers

  • Ricbet

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: 建议添加输入验证和文档注释

函数实现逻辑正确,但建议做以下改进:

  1. 添加对 openclose 字符串的非空验证
  2. 添加 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

📥 Commits

Files that changed from the base of the PR and between d5d4dae and e972360.

📒 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.ts

Length of output: 1116


Script:

#!/bin/bash
# Search for the serialization utility implementation
rg -A 10 "export function serializeAutoClosingPairs" packages/extension/src/common/vscode/utils.ts

Length 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[]
  • 使用 ? 标记为可选,保证了向后兼容性
  • 属性放置位置合理,便于维护

packages/extension/src/common/vscode/ext-types.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 54.26%. Comparing base (d7d8a1d) to head (8fb29fa).

Files with missing lines Patch % Lines
packages/extension/src/common/vscode/utils.ts 16.66% 3 Missing and 2 partials ⚠️
packages/extension/src/common/vscode/ext-types.ts 88.88% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
jsdom 49.82% <62.50%> (+<0.01%) ⬆️
node 15.60% <56.25%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Files that changed from the base of the PR and between e972360 and 5c631ac.

📒 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: 类型定义和映射实现优雅!

命名空间的实现采用了类型别名和常量映射的方式,使得类型转换既安全又高效。

Copy link
Member

@hacke2 hacke2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] API gap: OpenSumi main vs VS Code 1.84.0 (exclude notbook)
2 participants