-
Notifications
You must be signed in to change notification settings - Fork 653
feat(rome_console): add an hyperlink markup element #2911
Conversation
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
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 In that case the the diagnostic had a field called 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}\\")?; |
There was a problem hiding this comment.
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.
crates/rome_js_analyze/src/lib.rs
Outdated
let primary = diag.primary.as_ref().unwrap(); | ||
|
||
if code == "js/noDoubleEquals" { | ||
let expect_code = markup! { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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.
Deploying with
|
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 |
For now I've rolled back the change of |
* feat(rome_console): add an hyperlink markup element * rollback markup in diagnostic codes
Summary
I originally left out the
Hyperlink
markup element from the initial implementation ofrome_console
since there wasn't really any use case for it at the time compare to the added complexity (requires support for properties in therome_markup
proc-macro and theMarkup
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 aString
to aMarkupBuf
(and requiringimpl Display
instead ofimpl 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 secondarycode_link: Option<String>
on theDiagnostic
struct)Test Plan
I added additional test cases for the
markup
macro checking both passing and failing syntax, and a test for theTermcolor
ANSI emitter