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

fix: improve live inline diff prioritization and fix discard functionality #3837

Merged
merged 7 commits into from
Jul 5, 2024

Conversation

Ricbet
Copy link
Member

@Ricbet Ricbet commented Jul 5, 2024

Types

  • 🐛 Bug Fixes

Background or solution

  • 快捷键的 采纳/丢弃 将优先处理离当前光标最近的操作点
  • 修复 discard 操作引起的代码错位问题
  • 当所有的 partial edit widget 都操作完成后,将自动隐藏 content widget

Changelog

修复 live 模式的 inline diff undo/redo 功能并改进丢弃操作

Summary by CodeRabbit

  • 新功能

    • 增加了 AI 内联内容小部件,用于增强内联聊天和差异预览功能。
  • 改进

    • 改善了内联差异预览器的挂载和显示逻辑,提高了渲染效率。
    • 优化了内联流差异处理,添加了部分编辑小部件的注册和处理功能。
    • 精简了导入语句,提高了代码的可维护性和功能性。
  • 修复

    • 更新了事件处理和小部件排序逻辑,解决了一些潜在的功能问题。

@Ricbet Ricbet requested review from erha19 and bytemain July 5, 2024 05:40
@Ricbet Ricbet self-assigned this Jul 5, 2024
Copy link

railway-app bot commented Jul 5, 2024

This PR was not deployed automatically as @Ricbet does not have access to the Railway project.

In order to get automatic PR deploys, please add @Ricbet to the project inside the project settings page.

Copy link
Contributor

coderabbitai bot commented Jul 5, 2024

Warning

Rate limit exceeded

@Ricbet has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 44 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between f14de91 and 511d9a1.

Walkthrough

这些更改主要是为了改进和优化与小部件 (widget) 相关的功能,包括 InlineChatHandlerInlineDiffPreviewer。具体操作包括引入和安装新组件 (AIInlineContentWidget), 清除旧方法 (doLayoutContentWidget), 以及根据新逻辑调整布局和渲染方法,以增强内容处理、事件处理和界面更新的效率。

Changes

文件 变更摘要
.../inline-chat/inline-chat.handler.ts 增加 mount 方法调用来安装 aiInlineContentWidget,替换 doLayoutContentWidget 方法。
.../inline-diff/inline-diff-previewer.ts 更新依赖,增加 AIInlineContentWidget,调整方法来创建、处理以及渲染小部件。
.../inline-stream-diff/inline-stream-diff.handler.tsx 引入 LineTokensAcceptPartialEditWidget,添加属性和方法进行细粒度控制和优化逻辑流。
.../inline-stream-diff/live-preview.decoration.tsx 规范导入语句,更新 AcceptPartialEditWidget 类,增强事件和小部件处理,增加 discardUnProcessed 方法。

Sequence Diagram(s)

生成图表没有意义,因为这些更改过于简单和多样化。


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@opensumi opensumi bot added the 🐞 bug Something isn't working label Jul 5, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b9caae and 958558b.

Files selected for processing (4)
  • packages/ai-native/src/browser/widget/inline-chat/inline-chat.handler.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (7 hunks)
  • packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx (8 hunks)
  • packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx (11 hunks)
Files skipped from review due to trivial changes (1)
  • packages/ai-native/src/browser/widget/inline-chat/inline-chat.handler.ts
Additional comments not posted (19)
packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (5)

9-9: 导入声明看起来不错。

已正确导入 AIInlineContentWidget 模块。


19-20: 新属性和方法实现看起来不错。

inlineContentWidget 属性已添加,并在 mount 方法中正确初始化。

Also applies to: 35-37


157-163: 创建节点和处理部分编辑小部件的逻辑看起来不错。

createNode 方法现在注册了处理部分编辑小部件的处理程序。


179-179: 处理操作的逻辑看起来不错。

handleAction 方法现在在 DISCARDREGENERATE 操作时正确处理节点的释放。


195-196: 结束方法的逻辑看起来不错。

onEnd 方法现在重新计算差异模型并调用 readyRender

packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx (7)

10-10: 导入声明看起来不错。

已正确导入 LineTokens 模块。


13-13: 导入声明看起来不错。

已正确导入 AcceptPartialEditWidgetLivePreviewDiffDecorationModel 模块。


46-47: 新属性和初始化看起来不错。

rawOriginalTextLinesTokens 属性已添加,并在构造函数中正确初始化。

Also applies to: 74-79


54-54: 新属性和初始化看起来不错。

partialEditWidgetHandle 属性已添加,并在构造函数中正确初始化。

Also applies to: 194-196


87-104: 初始化装饰模型的方法看起来不错。

initializeDecorationModel 方法现在设置了部分编辑小部件列表更改的事件监听器。


199-199: 丢弃方法的逻辑看起来不错。

discard 方法现在调用了装饰模型的 discardUnProcessed 方法。


390-395: 准备渲染的方法看起来不错。

readyRender 方法现在调用了 doSchedulerEditsrenderPartialEditWidgetspushStackElement 方法。

packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx (7)

49-53: 新接口定义看起来不错。

ITextLinesTokens 接口已正确定义,用于表示文本行及其标记。


54-54: 新类定义看起来不错。

AcceptPartialEditWidget 类已添加,并扩展了 ReactInlineContentWidget

Also applies to: 58-58


208-211: 新事件定义和使用看起来不错。

LivePreviewDiffDecorationModel 类现在包含了新的事件 onPartialEditWidgetListChange


290-313: 显示移除小部件的方法看起来不错。

showRemovedWidgetByLineNumber 方法现在接受一个 ITextLinesTokens 数组,并正确处理新的参数以更新移除小部件的显示。


371-371: 丢弃部分小部件的方法看起来不错。

doDiscardPartialWidget 方法现在正确处理部分编辑小部件,并相应地更新编辑操作。


Line range hint 414-473:
处理部分编辑操作的方法看起来不错。

handlePartialEditAction 方法现在包括一个用于堆栈推送控制的新参数,并在小部件列表更改时发出事件。


491-497: 新方法定义看起来不错。

discardUnProcessed 方法已添加,并正确处理未处理的部分编辑小部件。

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 32 lines in your changes missing coverage. Please review.

Project coverage is 55.02%. Comparing base (4b9caae) to head (511d9a1).

Files Patch % Lines
...rowser/widget/inline-diff/inline-diff-previewer.ts 0.00% 21 Missing and 6 partials ⚠️
.../browser/widget/inline-chat/inline-chat.handler.ts 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3837      +/-   ##
==========================================
- Coverage   55.02%   55.02%   -0.01%     
==========================================
  Files        1553     1553              
  Lines       94700    94696       -4     
  Branches    19378    19380       +2     
==========================================
- Hits        52111    52108       -3     
+ Misses      35384    35379       -5     
- Partials     7205     7209       +4     
Flag Coverage Δ
jsdom 50.46% <0.00%> (-0.01%) ⬇️
node 15.56% <0.00%> (+<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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 958558b and 86be544.

Files selected for processing (2)
  • packages/ai-native/src/browser/widget/inline-chat/inline-chat.handler.ts (5 hunks)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts
Additional comments not posted (4)
packages/ai-native/src/browser/widget/inline-chat/inline-chat.handler.ts (4)

339-340: 验证挂载方法的正确性

请确保 diffPreviewer.mount(this.aiInlineContentWidget) 方法正确挂载了 aiInlineContentWidget,并检查其对整个应用程序的影响。

Verification successful

验证挂载方法的正确性

diffPreviewer.mount(this.aiInlineContentWidget) 方法正确挂载了 aiInlineContentWidget。根据代码检查,inlineContentWidget 被正确使用于设置选项、布局、位置偏好和资源释放。这些操作确保了挂载方法的正确性和一致性。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the mount method implementation and its usage.

# Test: Search for the mount method implementation. Expect: Correct implementation and usage.
rg --type ts $'mount'

Length of output: 10985


Script:

#!/bin/bash
# Description: Fetch the implementation of the mount method in inline-diff-previewer.ts

# Locate the file containing the relevant mount method
file_path=$(rg --files-with-matches 'public mount\(contentWidget: AIInlineContentWidget\): void' | grep 'inline-diff-previewer.ts')

# Display the implementation of the mount method
if [[ -n "$file_path" ]]; then
  rg -A 10 -B 2 'public mount\(contentWidget: AIInlineContentWidget\): void' "$file_path"
else
  echo "Relevant mount method not found."
fi

Length of output: 798


Script:

#!/bin/bash
# Description: Search for all usages of inlineContentWidget within the inline-diff-previewer.ts file

# Locate the file containing the inlineContentWidget property
file_path=$(rg --files-with-matches 'inlineContentWidget' | grep 'inline-diff-previewer.ts')

# Display all usages of inlineContentWidget within the file
if [[ -n "$file_path" ]]; then
  rg 'inlineContentWidget' "$file_path"
else
  echo "inlineContentWidget not found."
fi

Length of output: 811


378-378: 验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在中止处理块中正确调用,并检查其对整个应用程序的影响。


367-367: 验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在错误处理块中正确调用,并检查其对整个应用程序的影响。

Verification successful

验证布局方法的正确性

已确认 diffPreviewer.layout() 方法在错误处理块中正确调用,并且该方法的实现和使用都是合理的。无需进一步修改。

  • packages/ai-native/src/browser/widget/inline-chat/inline-chat.handler.ts 第 367 行
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the layout method implementation and its usage.

# Test: Search for the layout method implementation. Expect: Correct implementation and usage.
rg --type ts $'layout'

Length of output: 108306


Script:

#!/bin/bash
# Extract the implementation of the layout method in inline-diff-previewer.ts
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  layout() {
    $$$
  }
  $$$
}' --files-with-matches packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts

# Extract the usage and related code for the layout method in inline-diff-previewer.ts
rg 'layout' packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts

Length of output: 825


Script:

#!/bin/bash
# Extract the implementation of the layout method in inline-diff-previewer.ts
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  layout() {
    $$$
  }
  $$$
}' packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts

Length of output: 165


Script:

#!/bin/bash
# Search for the layout method definition in inline-diff-previewer.ts
rg 'layout()' packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts

Length of output: 406


388-388: 验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在结束处理块中正确调用,并检查其对整个应用程序的影响。

Verification successful

验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在结束处理块中正确调用,并检查其对整个应用程序的影响。我们需要进一步确认 diffPreviewer 对象的 layout 方法的定义和实现。


验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在结束处理块中正确调用,并检查其对整个应用程序的影响。我们需要进一步确认 diffPreviewer 对象的 layout 方法的定义和实现。


验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在结束处理块中正确调用,并检查其对整个应用程序的影响。我们需要进一步确认 BaseInlineDiffPreviewer 类及其可能的类型 InlineDiffWidgetInlineStreamDiffHandler 中的 layout 方法的定义和实现。


验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在结束处理块中正确调用,并检查其对整个应用程序的影响。我们需要进一步确认 layout 方法的定义和实现。


验证布局方法的正确性

请确保 diffPreviewer.layout() 方法在结束处理块中正确调用,并检查其对整个应用程序的影响。以下是 inline-diff-previewer.ts 文件中 layout 方法的实现:

  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts 文件中定义了 layout() 方法。

请检查此方法的实现和使用情况,以确保其正确性。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the layout method implementation and its usage.

# Test: Search for the layout method implementation. Expect: Correct implementation and usage.
rg --type ts $'layout'

Length of output: 108306


Script:

#!/bin/bash
# Description: Verify the layout method implementation in the diffPreviewer context.

# Test: Search for the definition of the layout method in the context of diffPreviewer. Expect: Correct implementation and usage.
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  layout() {
    $$$
  }
  $$$
}' --json

Length of output: 100


Script:

#!/bin/bash
# Description: Locate the declaration of diffPreviewer and identify its type.

# Test: Search for the declaration of diffPreviewer. Expect: Find the type and location of its definition.
rg --type ts 'diffPreviewer'

Length of output: 2755


Script:

#!/bin/bash
# Description: Verify the layout method implementation in the BaseInlineDiffPreviewer and its possible types.

# Test: Search for the layout method in BaseInlineDiffPreviewer, InlineDiffWidget, and InlineStreamDiffHandler. Expect: Correct implementation and usage.
ast-grep --lang typescript --pattern $'class BaseInlineDiffPreviewer {
  $$$
  layout() {
    $$$
  }
  $$$
}' --json

ast-grep --lang typescript --pattern $'class InlineDiffWidget {
  $$$
  layout() {
    $$$
  }
  $$$
}' --json

ast-grep --lang typescript --pattern $'class InlineStreamDiffHandler {
  $$$
  layout() {
    $$$
  }
  $$$
}' --json

Length of output: 358


Script:

#!/bin/bash
# Description: Search for the layout method definition in the broader context of the codebase.

# Test: Search for the layout method definition. Expect: Find the correct implementation and usage.
rg --type ts 'layout()'

Length of output: 108310

@bytemain bytemain changed the title fix: improve live inline diff prioritization & fix discard functionality fix: improve live inline diff prioritization and fix discard functionality Jul 5, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 86be544 and 7010626.

Files selected for processing (1)
  • packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx (11 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/ai-native/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7010626 and f14de91.

Files selected for processing (2)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (6 hunks)
  • packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx (8 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts
  • packages/ai-native/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx

@Ricbet Ricbet merged commit ae0cfd5 into main Jul 5, 2024
11 checks passed
@Ricbet Ricbet deleted the feat/support-redo-re-render branch July 5, 2024 07:12
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants