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 VSCode API: SnippetTextEdit #4154

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Conversation

bk1012
Copy link
Member

@bk1012 bk1012 commented Nov 6, 2024

Types

  • 🎉 New Features

Background or solution

Support VSCode API: SnippetTextEdit

Changelog

Summary by CodeRabbit

  • 新功能

    • 引入了 SnippetTextEdit 类,支持在编辑器中进行交互式的代码片段编辑。
    • 增加了对代码片段文本编辑的支持,允许更灵活的编辑操作。
    • 更新了 WorkspaceEdit 类,支持同时处理文本编辑和代码片段编辑,并允许关联元数据。
  • 文档

    • 更新了 SnippetTextEdit 类的文档,明确了代码片段编辑的使用场景。

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

此拉取请求引入了对 vscode 模块中与工作区编辑和片段文本编辑相关的多个新功能和修改。新增的 SnippetTextEdit 命名空间及其方法 from 允许将 vscode.SnippetTextEdit 转换为 model.TextEdit,并添加可选属性 insertAsSnippet。同时,WorkspaceEdit 类的 set 方法被更新,以支持文本编辑和片段编辑的处理,增强了编辑操作的灵活性和功能性。

Changes

文件路径 更改摘要
packages/extension/src/common/vscode/converter.ts - 新增命名空间 SnippetTextEdit,包含方法 from,用于将 vscode.SnippetTextEdit 转换为 model.TextEdit,并添加可选属性 insertAsSnippet
- 修改 WorkspaceEdit.from 方法以处理 WorkspaceEditType.Snippet 类型的条目。
packages/extension/src/common/vscode/ext-types.ts - 新增接口 FileSnippetTextEdit,用于表示与片段相关的文本编辑。
- 更新 WorkspaceEditEntry 类型以包含 FileSnippetTextEdit
- 更新 WorkspaceEditType 枚举以包含 Snippet
- 新增 SnippetTextEdit 类。
packages/types/vscode/typings/vscode.d.ts - 更新 WorkspaceEdit 类中的 set 方法签名,以接受 TextEditSnippetTextEdit 对象的数组。
- 新增 set 方法重载,允许设置带有元数据的编辑。
packages/types/vscode/typings/vscode.editor.d.ts - 新增 SnippetTextEdit 类,包含用于创建片段编辑的方法 replaceinsert
- 添加 rangesnippet 属性,表示编辑应用的范围和使用的片段字符串。

Possibly related PRs

Suggested reviewers

  • Ricbet
  • hacke2

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: 3

🧹 Outside diff range and nitpick comments (3)
packages/types/vscode/typings/vscode.editor.d.ts (1)

703-749: 建议:考虑添加使用示例

为了帮助开发者更好地理解如何使用 SnippetTextEdit,建议在类的文档注释中添加一个简单的使用示例。

建议在类注释中添加如下示例:

/**
 * Example usage:
 * ```typescript
 * const snippet = new SnippetString('console.log(${1:value});');
 * const edit = SnippetTextEdit.insert(position, snippet);
 * ```
 */
packages/types/vscode/typings/vscode.d.ts (2)

Line range hint 90-107: 重复定义了 WorkspaceFolder 接口

WorkspaceFolder 接口在代码中被定义了两次(行 90-107 和行 1448-1465),这可能导致类型冲突或编译错误。建议删除一个重复的定义以避免潜在的问题。

Also applies to: 1448-1465


Line range hint 1181-1189: 构造函数文档中的参数名称不匹配

CustomExecution 类的构造函数文档中,@param 注释标记了错误的参数名称。当前文档注释为:

@param process The [Pseudoterminal](#Pseudoterminal) to be used by the task to display output.

实际上,构造函数的参数是 callback,而非 process。请修正文档中的参数名称以保持一致。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 967717c and 16eb821.

📒 Files selected for processing (4)
  • packages/extension/src/common/vscode/converter.ts (2 hunks)
  • packages/extension/src/common/vscode/ext-types.ts (4 hunks)
  • packages/types/vscode/typings/vscode.d.ts (1 hunks)
  • packages/types/vscode/typings/vscode.editor.d.ts (1 hunks)
🧰 Additional context used
🪛 Biome
packages/extension/src/common/vscode/ext-types.ts

[error] 1300-1306: The enum declaration should not be const

Const enums are not supported by bundlers and are incompatible with the 'isolatedModules' mode. Their use can lead to import inexistent values.
See TypeScript Docs for more details.
Safe fix: Turn the const enum into a regular enum.

(lint/suspicious/noConstEnum)

🔇 Additional comments (10)
packages/types/vscode/typings/vscode.editor.d.ts (5)

703-711: 文档注释清晰地说明了 SnippetTextEdit 的用途和行为

注释很好地解释了片段编辑可以作为普通文本编辑执行的情况,以及在多文件工作区编辑中的行为。


714-721: 静态方法 replace 的实现符合预期

方法签名和文档注释都符合 VSCode API 的标准设计模式。


723-730: 静态方法 insert 的实现符合预期

方法签名和文档注释都符合 VSCode API 的标准设计模式。


732-740: 类属性定义清晰且文档完整

range 和 snippet 属性的类型定义和文档注释都很完整。


742-749: 构造函数实现简洁明了

构造函数的参数类型和文档注释符合预期。

packages/extension/src/common/vscode/converter.ts (2)

419-427: 代码实现清晰简洁

命名空间 SnippetTextEdit 的实现符合转换器模式,将 VSCode 的片段编辑类型正确转换为内部模型。


854-863: 工作区编辑处理逻辑完善

代码正确处理了片段编辑类型,与其他编辑类型保持一致的处理模式,并妥善处理了文档版本。

packages/extension/src/common/vscode/ext-types.ts (3)

1306-1330: 'SnippetTextEdit' 类的实现看起来正确。

新增的 'SnippetTextEdit' 类及其方法实现正确,符合预期功能。


1289-1295: 'FileSnippetTextEdit' 接口定义合理。

新增的 'FileSnippetTextEdit' 接口定义正确,符合类型扩展的需求。


1383-1418: 'WorkspaceEdit' 类的 'set' 方法成功支持了新的 'SnippetTextEdit' 类型。

'WorkspaceEdit' 类中的 'set' 方法已更新,能够正确处理 'SnippetTextEdit' 类型的编辑,增强了编辑操作的灵活性。

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 15.00000% with 34 lines in your changes missing coverage. Please review.

Project coverage is 54.11%. Comparing base (bb5e972) to head (6ddde61).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/extension/src/common/vscode/ext-types.ts 12.12% 26 Missing and 3 partials ⚠️
packages/extension/src/common/vscode/converter.ts 28.57% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4154      +/-   ##
==========================================
- Coverage   54.12%   54.11%   -0.02%     
==========================================
  Files        1598     1598              
  Lines       97740    97776      +36     
  Branches    20001    20024      +23     
==========================================
+ Hits        52901    52907       +6     
- Misses      37244    37271      +27     
- Partials     7595     7598       +3     
Flag Coverage Δ
jsdom 49.67% <15.00%> (-0.02%) ⬇️
node 15.58% <12.50%> (+<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: 0

🧹 Outside diff range and nitpick comments (1)
packages/extension/src/common/vscode/ext-types.ts (1)

1299-1304: 请说明为什么选择值 6 作为 Snippet 类型的枚举值

建议添加注释说明为什么跳过了 4 和 5,直接使用 6 作为 Snippet 的枚举值。这有助于其他开发者理解这个设计决策。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 16eb821 and 41ef042.

📒 Files selected for processing (1)
  • packages/extension/src/common/vscode/ext-types.ts (4 hunks)
🔇 Additional comments (4)
packages/extension/src/common/vscode/ext-types.ts (4)

1289-1295: 代码结构清晰且符合规范!

FileSnippetTextEdit 接口定义完整,使用 readonly 修饰符确保了不可变性,属性类型定义准确。


1306-1330: 实现完整且符合最佳实践!

SnippetTextEdit 类的实现:

  • 包含了必要的类型检查方法
  • 提供了便捷的工厂方法
  • 构造函数参数验证合理

1383-1389: 方法签名设计合理!

set 方法的重载签名设计:

  • 支持了新的 SnippetTextEdit 类型
  • 保持了与现有 TextEdit 用法的兼容性
  • ESLint 规则处理得当

1394-1418: 实现逻辑完善且健壮!

set 方法的实现:

  • 正确处理了 TextEdit 和 SnippetTextEdit 两种类型
  • 元数据处理保持一致性
  • 类型检查严谨

@bk1012 bk1012 changed the title feat: support VSCode API: SnippetTextEdit WIP: feat: support VSCode API: SnippetTextEdit Nov 8, 2024
@bk1012 bk1012 force-pushed the feat/support-SnippetTextEdit branch from 41ef042 to 6ddde61 Compare November 14, 2024 11:18
@bk1012 bk1012 changed the title WIP: feat: support VSCode API: SnippetTextEdit feat: support VSCode API: SnippetTextEdit Nov 14, 2024
@bk1012 bk1012 merged commit 8cdf4ec into main Nov 15, 2024
12 checks passed
@bk1012 bk1012 deleted the feat/support-SnippetTextEdit branch November 15, 2024 02:37
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.

2 participants