Skip to content

feat(formatter): support printing comments #11716

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

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

Dunqing
Copy link
Member

@Dunqing Dunqing commented Jun 15, 2025

This PR supports printing leading, trailing, and dangling comments based on the Prettier algorithm.

There are two main things done in this PR:

  1. Introduce a following_node field in AstNode.

This field, which is a SiblingNode(which could be replaced by AstKind after #11490), is an enum that includes all the AST structs. It will store the next node of the current node. The purpose of this field is to help us determine whether a comment is leading or trailing.

  1. Replace Biome's Comments with our own Comments.
#[derive(Debug, Clone)]
pub struct Comments<'a> {
    source_text: &'a str,
    comments: &'a Vec<'a, Comment>,
    printed_count: usize,
}

@github-actions github-actions bot added A-ast-tools Area - AST tools A-formatter Area - Formatter C-enhancement Category - New feature or request labels Jun 15, 2025
Copy link
Member Author

Dunqing commented Jun 15, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Boshen Boshen mentioned this pull request Jun 15, 2025
@Dunqing Dunqing force-pushed the 06-15-feat_formatter_support_printing_comments branch 2 times, most recently from 5e5667c to 8843917 Compare June 16, 2025 06:27
Copy link

codspeed-hq bot commented Jun 16, 2025

CodSpeed Instrumentation Performance Report

Merging #11716 will degrade performances by 4.07%

Comparing 06-15-feat_formatter_support_printing_comments (0bbbfd8) with main (1a54184)

Summary

❌ 4 regressions
✅ 34 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
formatter[RadixUIAdoptionSection.jsx] 329.6 µs 343.6 µs -4.07%
formatter[binder.ts] 20.7 ms 21.5 ms -3.81%
formatter[cal.com.tsx] 161 ms 167 ms -3.61%
formatter[react.development.js] 10.1 ms 10.4 ms -3.01%

@Dunqing Dunqing force-pushed the 06-15-feat_formatter_support_printing_comments branch 10 times, most recently from 704cdda to 1b91111 Compare June 20, 2025 11:29
@Dunqing Dunqing force-pushed the 06-15-feat_formatter_support_printing_comments branch from 1b91111 to 0bbbfd8 Compare June 20, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast-tools Area - AST tools A-formatter Area - Formatter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant