+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_console): add an hyperlink markup element #2911

Merged
merged 2 commits into from
Jul 25, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Jul 21, 2022

Summary

I originally left out the Hyperlink markup element from the initial implementation of rome_console since there wasn't really any use case for it at the time compare to the added complexity (requires support for properties in the rome_markup proc-macro and the Markup struct, and the implementation depends on the underlying platform)

I think there's now an interesting use case for it (turning linter error codes into links to the corresponding lint rule's documentation page), and the implementation should be easier to review in isolation

As part of this I changed the code property of diagnostics from a String to a MarkupBuf (and requiring impl Display instead of impl Into<String>). This required changing a few code paths that read out the code for a diagnostic, and raises the interesting question of whether having "inspectable codes" on diagnostics is something we actually want to support (in this case I would probably change the code back to a string and store the link in a secondary code_link: Option<String> on the Diagnostic struct)

Test Plan

I added additional test cases for the markup macro checking both passing and failing syntax, and a test for the Termcolor ANSI emitter

@leops leops requested a review from a team July 21, 2022 08:08
@leops leops temporarily deployed to aws July 21, 2022 08:08 Inactive
@github-actions
Copy link

github-actions bot commented Jul 21, 2022

@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 395 395 0
Failed 5551 5551 0
Panics 0 0 0
Coverage 6.64% 6.64% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12393 12393 0
Failed 3864 3864 0
Panics 0 0 0
Coverage 76.23% 76.23% 0.00%

@ematipico
Copy link
Contributor

and raises the interesting question of whether having "inspectable codes" on diagnostics is something we actually want to support

Could you explain to me what it means, please? What can we do with this feature?

@leops
Copy link
Contributor Author

leops commented Jul 21, 2022

and raises the interesting question of whether having "inspectable codes" on diagnostics is something we actually want to support

Could you explain to me what it means, please? What can we do with this feature?

The thing is I'm not really sure if it was intended to be a feature in the first place, but since the code for a diagnostic used to be a plain string it was possible for instance to inspect a list of diagnostic and do something if the code for one of them was "SyntaxError" and do something specific about it. Now that the diagnostic code contains markup, doing something like this is a lot less stable since you need to compare the formatting along with the text content. So my question is, should we treat the code for a diagnostic as an opaque that can only be printed to the console, or should it possible to inspect it like the severity for instance ?

@ematipico
Copy link
Contributor

ematipico commented Jul 21, 2022

and raises the interesting question of whether having "inspectable codes" on diagnostics is something we actually want to support

Could you explain to me what it means, please? What can we do with this feature?

The thing is I'm not really sure if it was intended to be a feature in the first place, but since the code for a diagnostic used to be a plain string it was possible for instance to inspect a list of diagnostic and do something if the code for one of them was "SyntaxError" and do something specific about it. Now that the diagnostic code contains markup, doing something like this is a lot less stable since you need to compare the formatting along with the text content. So my question is, should we treat the code for a diagnostic as an opaque that can only be printed to the console, or should it possible to inspect it like the severity for instance ?

I am trying to remember if we ever had the necessity to inspect the code of a diagnostic in Rome classic, and nothing comes to mind. There was some occasions where we had to inspect them, but we used the category, for in rome auto-config we used to do a dry-run of the linter, get all the diagnostics that belonged to noUndefinedVariable and extract the variable name of the variable unused.

In that case the the diagnostic had a field called categoryValue and we used to store the name of the variable.

So then, I think we can safely keep the code as raw markup

// in the legacy `cmd.exe` terminal emulator, since int modern
// clients like the Windows Terminal ANSI is used instead
if writer.supports_color() && !writer.is_synchronous() {
write!(writer, "{ESC}]8;;{href}{ESC}\\")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, I actually prefer "\x1b" directly. Easier to find. And everyone knows what it is.

let primary = diag.primary.as_ref().unwrap();

if code == "js/noDoubleEquals" {
let expect_code = markup! {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we have this check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is checking that suppression comments work correctly using the js/noDoubleEquals rule, it has to check that diagnostics are emitted or not for certain ranges but I don't want it to break if we add a new rule in the future that happens to emit a diagnostic for something in this code (for instance the checkSuppressions1 and checkSuppressions2 function are never used), so I'm filtering out all diagnostics that were not emitted by the rule that's used for testing

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

The changes look good to me but I'm leaning towards that inspectable codes might be desirable in the future and maybe even globally unique error codes, similar to Rust's diagnostics

Inspecting codes will be possible even after this change by simply stripping all markup from the code to get the "raw" code. Having guaranteed unique codes will be harder to achieve.

I don't think this is blocking us from moving forward since refactoring code back to a string and either exposing the links as an additional field on the diagnostic or having a global lookup table to resolve the documentation link for documentation is still possible. But I would be interested in hearing your thoughts on either of these approaches compared to changing the type of code on markup.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 22, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: cf8f2b3
Status: ✅  Deploy successful!
Preview URL: https://aaac8e0b.tools-8rn.pages.dev
Branch Preview URL: https://feature-markup-hyperlink.tools-8rn.pages.dev

View logs

@leops leops temporarily deployed to aws July 22, 2022 09:29 Inactive
@leops
Copy link
Contributor Author

leops commented Jul 22, 2022

But I would be interested in hearing your thoughts on either of these approaches compared to changing the type of code on markup.

For now I've rolled back the change of code from string to markup, and added an additional code_link field to the diagnostics instead

@leops leops merged commit a336912 into main Jul 25, 2022
@leops leops deleted the feature/markup-hyperlink branch July 25, 2022 07:24
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
* feat(rome_console): add an hyperlink markup element

* rollback markup in diagnostic codes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载