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

refactor(diagnostics): indentation #3722

Merged
merged 1 commit into from
Aug 26, 2024
Merged

Conversation

ematipico
Copy link
Member

Summary

This PR changes how the indentation of the diagnostics is printed.

Before, the IndentWriter was using the same markup elements of the elements to indent. This means that if we had <Info>Text</Info>, the IndentWriter would have created <Info> </Info><Info>Text</Info>. This isn't visible in a terminal, because Info basically sets some ANSI codes for changing the colour.

However, in the HTML adapter, this was more visible, because it create HTML like this:

<span style="color: lightgreen">  </span><span style="color: lightgreen">text</span>

This is more cumbersome when we have things like <Emphasis><Info>Text</Info></Emphasis>, which emits:

<strong><span style="color: lightgreen">  </span></strong><strong><span style="color: lightgreen">text</span></strong>

This causes some issues inside MDX files. MDX is weird, really weird, so it requires some special handling, however this change is fine also for Markdown documents.

With this PR, we just use a ::Root element, which means that we emit less HTML tags, and the spaces are emitted as they are... spaces!

Test Plan

I updated the current tests. I took the emitted HTML for the MDX variant and used it on the website to see if the printed diagnostics are correctly indented, and they are!

@github-actions github-actions bot added the A-Diagnostic Area: diagnostocis label Aug 26, 2024
@@ -2,4 +2,4 @@
source: crates/biome_diagnostics/tests/disagnostics.rs
expression: content
---
code&#95;block check <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br /><strong><span style="color: Tomato;"> </span></strong><strong><span style="color: Tomato;"></span></strong> <span style="color: Tomato;">This is the message of the diagnostic. It will appear in different colours based on the severity of the diagnostic.</span><br /> <br />
code&#95;block:1:11 check <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br /> <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">This is the message of the diagnostic. It will appear in different colours based on the severity of the diagnostic.</span><br /> <br /> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>fn main() &#123;<br /> <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><br /> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> println!(&quot;Hello, world!&quot;);<br /> <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br /> <strong>3 │ </strong>&#125;<br /> <br />
Copy link
Member Author

@ematipico ematipico Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice here, after the first two <br /><br /> that you can find after the long line. We have two whitespace. They aren't wrapped by any special tag. Instead, on the left, we have <strong><span style="color: Tomato;"> </span></strong>

@ematipico ematipico merged commit be09487 into main Aug 26, 2024
13 checks passed
@ematipico ematipico deleted the refactor/indentation-diagnostics branch August 26, 2024 10:59
@Conaclos Conaclos added the A-Changelog Area: changelog label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Diagnostic Area: diagnostocis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants