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 trigger source code edits #4389

Merged
merged 1 commit into from
Feb 20, 2025
Merged

Conversation

Ricbet
Copy link
Member

@Ricbet Ricbet commented Feb 20, 2025

Types

  • 🎉 New Features

Background or solution

Changelog

code edits 支持 trigger source 类型

Summary by CodeRabbit

  • 新特性

    • 新增基于用户光标位置的智能触发机制,优化了内联补全和代码编辑体验。
    • 更新了快捷键绑定设置,确保用户自定义的快捷操作更精准有效。
  • 重构

    • 调整并优化了内部逻辑,提升了响应速度和稳定性,从而增强整体编辑功能的流畅性。

@Ricbet Ricbet requested review from hacke2 and erha19 February 20, 2025 08:11
@opensumi opensumi bot added the 🎨 feature feature required label Feb 20, 2025
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

本次提交在智能补全功能中引入了新的触发代码编辑逻辑。改动包括更新接口以支持触发数据、调整按键绑定注册以限定用户作用域、修改控制器以使用新的触发源替换旧的 observable 信号、改进代码编辑源集合的封装,并新增了用于处理触发事件的文件。同时,相关枚举也新增了对应的值,以支持细化代码编辑来源的标识。

Changes

文件 改动摘要
packages/ai-native/.../index.ts 新增 ITriggerData 导入;更新 ICodeEditsContextBean 接口,增加 [ECodeEditsSourceTyping.Trigger]?: ITriggerData 属性。
packages/ai-native/.../intelligent-completions.contribution.ts 修改 registerKeybindings 方法,注册 AI_CODE_EDITS_COMMANDS.TRIGGER 时新增了 KeybindingScope.USER 参数。
packages/ai-native/.../intelligent-completions.controller.ts 移除 IObservableSignal 属性;更新 trigger 方法,改为调用 TriggerCodeEditsSource.triggerSignal;在代码编辑源集合中加入 TriggerCodeEditsSource,并改进了建议项选中项的处理。
packages/ai-native/.../source/base.ts aiReporterpreferenceService 属性改为只读;在 CodeEditsSourceCollection 中新增私有属性 sources 及公开方法 getSource 以便检索特定源。
packages/ai-native/.../source/trigger.source.ts 新增文件,定义了 ITriggerData 接口与 TriggerCodeEditsSource 类,其使用 observable 模式监控编辑器位置,触发代码编辑。
packages/core-common/.../index.ts ECodeEditsSourceTyping 枚举中新增 Trigger 值,用于标识由触发行为激活的代码编辑来源。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant IC as IntelligentCompletionsController
    participant TS as TriggerCodeEditsSource
    participant E as 编辑器

    U->>IC: 发起代码编辑触发请求
    IC->>TS: 调用 trigger() 方法
    TS->>E: 通过 runOnChangeWithStore 获取当前编辑位置
    E-->>TS: 返回当前位置数据
    TS->>IC: 更新状态 (触发数据更新)
Loading

Possibly related PRs

Suggested labels

🎨 feature

Suggested reviewers

  • hacke2
  • erha19
  • ensorrow

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > glob@7.2.3: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (3)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (2)

164-180: 请谨慎使用私有属性与方法。
该处通过访问 suggestWidgetAdaptor 的私有字段 '_currentSuggestItemInfo''_onDidSelectedItemChange' 来强制重置收起逻辑,可能因内部实现变动导致 fragility。

建议在原生 API 允许的情况下使用公共方法或事件触发机制,避免因升级依赖或内部逻辑变化而导致不兼容。


419-422: 优雅处理 triggerSource 不存在的场景。
当前仅在 triggerSource 存在时才调用 triggerSignal,若不存在则直接跳过,可能令调用者不易排查具体原因。

可考虑增加日志记录或提示,例如:

 public trigger(tx: ITransaction): void {
   const triggerSource = this.codeEditsSourceCollection.getSource(TriggerCodeEditsSource) as TriggerCodeEditsSource;
   if (triggerSource) {
     triggerSource.triggerSignal.trigger(tx);
   } else {
+    this.logger.debug('No TriggerCodeEditsSource found, trigger skipped.');
   }
 }
packages/ai-native/src/browser/contrib/intelligent-completions/source/trigger.source.ts (1)

1-44: 新增触发来源逻辑整体可行,但建议补充安全检查。

  1. priority = Number.MAX_SAFE_INTEGER 能确保该触发源优先度最高,可满足需求。
  2. position 始终为 null,可能造成后续的编辑上下文无法正常建立,建议在 setBean 前后增添必要的判断或日志,以提高可维护性。
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between feca922 and e7a032a.

📒 Files selected for processing (6)
  • packages/ai-native/src/browser/contrib/intelligent-completions/index.ts (2 hunks)
  • packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1 hunks)
  • packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (5 hunks)
  • packages/ai-native/src/browser/contrib/intelligent-completions/source/base.ts (3 hunks)
  • packages/ai-native/src/browser/contrib/intelligent-completions/source/trigger.source.ts (1 hunks)
  • packages/core-common/src/types/ai-native/index.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (10)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (3)

39-39: 导入适配器的更改看起来合理。
该导入为后续选项重置和阴影字符控制提供了基础,不存在明显风险。


60-60: 成功引入 TriggerCodeEditsSource。
这是对主动触发编辑逻辑的有效扩展,能够提升代码编辑的可控性。


108-108: 在 codeEditsSourceCollection 中添加新的来源。
此处将主动触发源纳入集合,优先级由 TriggerCodeEditsSource 内部的 Number.MAX_SAFE_INTEGER 决定,无需额外调整顺序即可保持其最高优先。

packages/ai-native/src/browser/contrib/intelligent-completions/index.ts (2)

4-4: 导入 ITriggerData 符合新的触发逻辑需求。
该改动与 TriggerCodeEditsSource 对应,逻辑上无冲突。


30-30: 在 ICodeEditsContextBean 中新增 Trigger 字段。
此扩展为代码补全上下文注入了触发位置信息,有助于更灵活地管理触发事件。

packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts (1)

77-84:

❓ Verification inconclusive

代码变更看起来不错!

新增的快捷键绑定正确地使用了 KeybindingScope.USER 作用域,并且与配置项 codeEdits.triggerKeybinding 关联。

建议验证配置项 codeEdits.triggerKeybinding 是否已在配置文件中正确定义:


🏁 Script executed:

#!/bin/bash
# 搜索配置项定义
rg -l "codeEdits.triggerKeybinding"

Length of output: 138


请注意:请确认配置项定义的范围

代码变更看起来不错!
新增的快捷键绑定正确地使用了 KeybindingScope.USER 作用域,并且在当前文件中出现了 codeEdits.triggerKeybinding 的引用。

  • 搜索结果显示,此配置项仅在 packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.contribution.ts 中存在。

请确认该配置项是否需要在全局配置或其他相关文件中正确定义,以确保功能按预期工作。

packages/ai-native/src/browser/contrib/intelligent-completions/source/base.ts (3)

75-75: 很好的改进!

将属性标记为 readonly 可以防止意外修改,提高代码的安全性。

Also applies to: 78-78


146-146: 代码结构优化得很好!

新增的 sources 私有数组和 getSource 方法提供了更好的源管理机制,使得代码更加模块化和可维护。

Also applies to: 149-151


159-161: 初始化逻辑简化得很好!

将源的初始化和挂载逻辑分离得更清晰。

packages/core-common/src/types/ai-native/index.ts (1)

428-430: 枚举值添加合理!

新增的 Trigger 枚举值有清晰的注释说明,并且符合现有的命名模式。

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

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 2.56410% with 38 lines in your changes missing coverage. Please review.

Project coverage is 53.85%. Comparing base (feca922) to head (e7a032a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...b/intelligent-completions/source/trigger.source.ts 0.00% 16 Missing ⚠️
...-completions/intelligent-completions.controller.ts 0.00% 10 Missing and 3 partials ⚠️
...ser/contrib/intelligent-completions/source/base.ts 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4389      +/-   ##
==========================================
- Coverage   53.86%   53.85%   -0.02%     
==========================================
  Files        1650     1651       +1     
  Lines      101648   101670      +22     
  Branches    21983    21984       +1     
==========================================
- Hits        54755    54754       -1     
- Misses      38994    39015      +21     
- Partials     7899     7901       +2     
Flag Coverage Δ
jsdom 49.35% <2.56%> (-0.02%) ⬇️
node 12.25% <2.56%> (-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.

@Ricbet Ricbet merged commit b300d3b into main Feb 20, 2025
13 checks passed
@Ricbet Ricbet deleted the feat/support-trigger-source branch February 20, 2025 08:46
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