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

style: prettify output log #4263

Merged
merged 3 commits into from
Dec 25, 2024
Merged

style: prettify output log #4263

merged 3 commits into from
Dec 25, 2024

Conversation

Ricbet
Copy link
Member

@Ricbet Ricbet commented Dec 24, 2024

Types

  • 💄 Style Changes

Background or solution

before:
image

after:
image

Changelog

改进 log output 的输出

Summary by CodeRabbit

  • 新功能
    • 新增 $appendLine 方法,允许向输出通道追加行。
  • 更改
    • 更新 OutputChannelImpl 类中的 appendLine 方法,以直接调用新的 $appendLine 方法。
    • 修改 LogOutputChannelImpl 类中的日期格式化逻辑,提升可读性和可维护性。
    • 移除未使用的 padLeft 函数,优化代码结构。
    • 更新 OutputChannel 类中的文本插入方法,改为使用 applyEdits 直接修改文本模型。

@Ricbet Ricbet requested review from hacke2, erha19 and Aaaaash December 24, 2024 07:38
@Ricbet Ricbet self-assigned this Dec 24, 2024
@Ricbet Ricbet linked an issue Dec 24, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

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.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: 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 > [email protected]: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"

变更概述

演练

此次拉取请求主要修改了输出通道(Output Channel)的实现和接口。在多个文件中添加了 $appendLine 方法,包括 MainThreadOutput 类、IMainThreadOutput 接口和 ExtHostOutput 类。同时,对输出通道的文本追加逻辑进行了优化,修改了文本插入的方法,并改进了日志记录的格式化方法。

变更

文件路径 变更摘要
packages/extension/src/browser/vscode/api/main.thread.output.ts 新增 $appendLine 方法,用于向指定输出通道追加一行文本
packages/extension/src/common/vscode/window.ts IMainThreadOutput 接口中添加 $appendLine 方法声明
packages/extension/src/hosted/api/vscode/ext.host.output.ts 修改 appendLine 方法实现,重构日期格式化逻辑,移除 padLeft 函数
packages/output/src/browser/output.channel.ts 替换 pushEditOperations 方法为 applyEdits,使用 EditOperation.insert 插入文本

序列图

sequenceDiagram
    participant ExtHost as 扩展主机
    participant MainThread as 主线程
    participant OutputChannel as 输出通道

    ExtHost->>MainThread: 调用 $appendLine
    MainThread->>OutputChannel: 追加文本行
    OutputChannel-->>MainThread: 确认完成
    MainThread-->>ExtHost: 返回成功
Loading

可能相关的 PR

建议标签

💄 style change

建议评审人

  • bytemain
  • erha19
  • hacke2

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 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 89c4fea and ee24c79.

📒 Files selected for processing (4)
  • packages/extension/src/browser/vscode/api/main.thread.output.ts (1 hunks)
  • packages/extension/src/common/vscode/window.ts (1 hunks)
  • packages/extension/src/hosted/api/vscode/ext.host.output.ts (3 hunks)
  • packages/output/src/browser/output.channel.ts (3 hunks)
🔇 Additional comments (8)
packages/extension/src/browser/vscode/api/main.thread.output.ts (1)

43-49: 新增 $appendLine 方法的实现逻辑看起来非常合理。
此方法能够简化按行输出的处理流程,并且实现方式与 $append 保持一致,整体结构清晰明了,无需额外修改。

packages/extension/src/hosted/api/vscode/ext.host.output.ts (3)

98-98: 切换为调用 $appendLine 来输出单独行。
此处改用 this.#proxy.$appendLine 确保与新的行输出逻辑保持一致,减少了后续字符串拼接的复杂度,值得肯定。


164-172: 使用定制的数字格式化函数提升可读性。
通过 twoDigitsthreeDigits 函数,可以更轻松地确保日期与毫秒部分的格式正确,提高了代码的可维护性。


193-193: logWithLevel 方法中使用 appendLine
改为 appendLine 能够保证每条日志独立成行,避免拼接时错乱;这种方式更直观,也更便于查看与排查。

packages/output/src/browser/output.channel.ts (3)

9-9: 引入 EditOperation 为后续文本插入提供基础。
此改动明确使用了外部库的编辑操作能力,与 Monaco 编辑器的机制紧密结合,便于进行复杂文本操作。


121-125: applyEdits 方法使文本插入逻辑更简洁。
使用单次编辑操作来插入文本,替代以往的多步 pushEditOperations。这能提高代码可读性并尽量减少后续维护成本。


143-143: 调用 applyEdits 方法简化追加操作。
doAppend 内部使用统一的 applyEdits 能避免代码重复,有利于后续维护和功能扩展。

packages/extension/src/common/vscode/window.ts (1)

185-185: 新增 $appendLine 方法的接口声明。
与后端实现及其他类的调用对齐,确保输出频道可按行追加并与 $append 保持接口一致性。


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

codecov bot commented Dec 24, 2024

Codecov Report

Attention: Patch coverage is 42.10526% with 11 lines in your changes missing coverage. Please review.

Project coverage is 53.71%. Comparing base (89c4fea) to head (ee24c79).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...extension/src/hosted/api/vscode/ext.host.output.ts 14.28% 4 Missing and 2 partials ⚠️
...nsion/src/browser/vscode/api/main.thread.output.ts 0.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4263      +/-   ##
==========================================
- Coverage   53.72%   53.71%   -0.02%     
==========================================
  Files        1622     1622              
  Lines       98572    98580       +8     
  Branches    20143    20145       +2     
==========================================
- Hits        52955    52949       -6     
- Misses      37911    37920       +9     
- Partials     7706     7711       +5     
Flag Coverage Δ
jsdom 49.18% <42.10%> (-0.02%) ⬇️
node 15.46% <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

@hacke2 hacke2 merged commit f230c4d into main Dec 25, 2024
13 checks passed
@hacke2 hacke2 deleted the fix/output-format branch December 25, 2024 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] cloudide环境outputchannel日志显示问题
2 participants