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: improve terminal local link parser #4302

Merged
merged 7 commits into from
Jan 7, 2025

Conversation

erha19
Copy link
Member

@erha19 erha19 commented Jan 6, 2025

Types

  • 🎉 New Features

Background or solution

Kapture.2025-01-06.at.10.31.38.mp4

support terminal local link parser for:

  1. single file name
  2. path in the current workspace

Changelog

improve terminal local link parser

Summary by CodeRabbit

  • 重构

    • 终端链接管理器中的路径解析逻辑得到简化
    • 本地链接验证提供程序的路径匹配和验证机制进行了优化
  • 改进

    • 改进了链接处理的代码结构
    • 增强了对本地链接的检测和验证能力
  • 技术更新

    • 增加了GitHub Actions工作流中的E2E测试步骤
    • 新增了对单文件路径的支持测试用例
    • 在CI工作流中为macOS和Windows添加了库安装步骤

@opensumi opensumi bot added the 🎨 feature feature required label Jan 6, 2025
@erha19
Copy link
Member Author

erha19 commented Jan 6, 2025

/next

@opensumi
Copy link
Contributor

opensumi bot commented Jan 6, 2025

🎉 PR Next publish successful!

3.6.5-next-1736131247.0

Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

变更概述

综述

本次拉取请求主要修改了终端链接管理和本地链接验证的相关代码。在 link-manager.ts 中,_resolvePath 方法的实现被简化,直接使用预处理后的链接创建 URI。在 validated-local-link-provider.ts 中,重构了链接验证逻辑,引入了新的私有方法 detectLocalLink,以提高代码的可读性和可维护性。此外,还在 GitHub Actions 工作流中新增了一步,以安装 libsecret-1 库。

变更

文件 变更摘要
packages/terminal-next/src/browser/links/link-manager.ts 简化 _resolvePath 方法,移除链接 URL 提取步骤,直接使用预处理链接创建 URI
packages/terminal-next/src/browser/links/validated-local-link-provider.ts 重构 _provideLinks 方法,引入 detectLocalLink 私有方法,优化本地链接验证逻辑
.github/workflows/e2e.yml 新增步骤以安装 libsecret-1
.github/workflows/check.yml 在 macOS 作业中新增步骤以安装 libsecret-1-dev

可能相关的 PR

建议审阅者

  • Ricbet
  • ensorrow

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c6e14d and be4eb9b.

📒 Files selected for processing (1)
  • .github/workflows/check.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: build-windows
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (1)
.github/workflows/check.yml (1)

41-42: 在 macOS 环境中安装 libsecret-1 的兼容性验证

这段脚本仅对于 Ubuntu 系统有效。请确认是否也需要在 macOS 环境中安装相应依赖(例如借助 Homebrew 或其他方式),以确保在 macOS 下也能正确使用 libsecret 函数。建议在这里添加相应的判断,以免在 macOS 环境执行时出现错误或者缺少依赖的问题。


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

🧹 Nitpick comments (2)
packages/terminal-next/src/browser/links/validated-local-link-provider.ts (1)

187-192: 异步循环调用可能带来性能负担
此处在循环内逐一等待 detectedLocalLinks 结果,若链接数量较多,可能影响速度。可考虑批量处理或并行操作。

packages/terminal-next/src/browser/links/link-manager.ts (1)

379-379: 直接使用已预处理的链接构建 URI,减少了额外校验
如果将来需要更严格的链接验证或容错机制,考虑保留原本的验证逻辑或在 _preprocessPath 中进行更全面的检测。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81708ca and 6feb19b.

📒 Files selected for processing (2)
  • packages/terminal-next/src/browser/links/link-manager.ts (1 hunks)
  • packages/terminal-next/src/browser/links/validated-local-link-provider.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build-windows
🔇 Additional comments (5)
packages/terminal-next/src/browser/links/validated-local-link-provider.ts (5)

21-33: 提取常量为枚举增强了可读性与可维护性
此处将各个路径相关的正则片段集中到 RegexPathConstants 枚举中,有效提高了代码的可维护性和可理解度。


35-37: 文档注释简明,便于后续维护
注释准确地描述了正则用途,有助于快速理解该段逻辑。


39-47: 正则逻辑较复杂,建议进行全面测试
处理多种 Unix 风格路径,在一些极端情况下(如长度过长、嵌套过深)可能出现性能问题,建议添加更多单元测试用例。


57-65: Windows 路径正则同样复杂,需确保没有漏点
同样建议在单测中包含多种场景(例如路径包含空格、特殊符号等),以防止出现意料之外的匹配失败。


194-197: 在未发现链接后对整行文本再次匹配的策略完善
这种回退策略能够进一步捕获潜在本地链接。逻辑清晰,暂时看不出问题。

@erha19
Copy link
Member Author

erha19 commented Jan 6, 2025

/next

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

🧹 Nitpick comments (2)
packages/terminal-next/__tests__/browser/links/validated-local-link-provider.test.ts (1)

289-300: 测试用例覆盖面良好,但可补充更多断言场景
本测试针对单个文件路径的用例非常有价值。然而,如果有更复杂的用例,比如包含特殊字符(如 - _ . ~ 等)或路径前后空格等,建议在将来增加额外的测试用例,以确保解析的鲁棒性和完整性。

packages/terminal-next/src/browser/links/validated-local-link-provider.ts (1)

171-176: 位置偏移量的语义可进一步说明
while 循环里对字符串进行多次索引定位后,这里调用 detectLocalLink(link, lines, startLine, stringIndex, 1),含有数值 1 的偏移量。建议在注释中解释 offset 参数的具体含义,以及为什么需要对链接文本范围作相应的额外偏移量,以便后续维护者更快理解这一逻辑。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 796a730 and 3c6e14d.

📒 Files selected for processing (2)
  • packages/terminal-next/__tests__/browser/links/validated-local-link-provider.test.ts (1 hunks)
  • packages/terminal-next/src/browser/links/validated-local-link-provider.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • 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: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: build-windows
🔇 Additional comments (1)
packages/terminal-next/src/browser/links/validated-local-link-provider.ts (1)

178-181: 备用逻辑可能导致重复解析
result.length === 0 时,再次调用 detectLocalLink(text, ...),若 text 中也可拆分出局部匹配,可能会和上一段逻辑的结果相互重叠。请确认两处解析逻辑不会造成冲突,以免误报重复链接。

@opensumi
Copy link
Contributor

opensumi bot commented Jan 6, 2025

🎉 PR Next publish successful!

3.6.5-next-1736135639.0

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 10 lines in your changes missing coverage. Please review.

Project coverage is 54.20%. Comparing base (d5f68e0) to head (9e44ad0).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...src/browser/links/validated-local-link-provider.ts 68.96% 8 Missing and 1 partial ⚠️
...es/terminal-next/src/browser/links/link-manager.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4302      +/-   ##
==========================================
- Coverage   54.21%   54.20%   -0.01%     
==========================================
  Files        1634     1634              
  Lines       99917    99934      +17     
  Branches    21699    21694       -5     
==========================================
+ Hits        54166    54170       +4     
- Misses      38008    38020      +12     
- Partials     7743     7744       +1     
Flag Coverage Δ
jsdom 49.74% <66.66%> (-0.01%) ⬇️
node 12.24% <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
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

@erha19 erha19 merged commit 83d0073 into main Jan 7, 2025
11 checks passed
@erha19 erha19 deleted the feat/improve-terminal-link-parser branch January 7, 2025 07:50
@coderabbitai coderabbitai bot mentioned this pull request Jan 20, 2025
11 tasks
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