-
Notifications
You must be signed in to change notification settings - Fork 653
refactor(rome_diagnostics): refactor the display of diffs to how it worked in Rome JS #3306
Conversation
0a3a552
to
b6670f4
Compare
b5080d3
to
52f9d03
Compare
✅ Deploy Preview for rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Comparing refactor(rome_diagnostics): refactor the display of diffs to how it worked in Rome JS Snapshot #8 to median since last deploy of rome.tools.
1 page tested
|
Chrome Desktop | iPhone, 4G LTE | Motorola Moto G Power, 3G connection |
---|---|---|
Most significant changes
5 other significant changes: Number of Requests on iPhone, 4G LTE, Number of Requests on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection
Calibre: Site dashboard | View this PR | Edit settings | View documentation
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
@@ -36,9 +36,8 @@ file.js:1:1 lint/correctness/noDebugger FIXABLE ━━━━━━━━━━ | |||
|
|||
i Suggested fix: Remove debugger statement | |||
|
|||
| @@ -1 +0,0 @@ | |||
0 | - debugger; |
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.
I like it that the line numbers now start with 1 instead of 0. It's more intuitive and aligns with editors.
Furthermore, the new diffs look more clean... less noisy symbols that I can hardly make sense of.
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 line number starting at 0 was definitely a bug, and it might have been one of the reasons the diff gutter could end up being misaligned
2 2 | for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); | ||
3 3 | for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); | ||
4 4 | for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); | ||
2 │ - for(;true;);for(;true;);for(;true;);for(;true;);for(;true;);for(;true;); |
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.
Is it intentional that we only show "context" lines after the change but not at the start or is the line 1 all empty?
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.
Yes the first line of the file is not rendered in the context lines because it's empty, this is due to the files used in the snapshot being defined as constant string literals in the test code like this:
const ERRORS: &str = r#"
for(;true;);for(;true;); ...
"#;
Making all those strings start and end with the \n
character
6 6 | | ||
7 7 | statement(notInlinable); | ||
```diff | ||
@@ -1,8 +1,8 @@ |
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.
What's the reason that we're hiding the line numbers here. Is it because these are just snapshots of the diff and not printed diagnostics?
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 snapshots for code actions used to be rendered using the shared diff printing logic in rome_console
, but since I moved this code to rome_diagnostics
it's now no longer easily accessible outside of diagnostics. Instead I've opted to render code actions as actual Git diffs (using the printing logic built-in to the similar
diffing library), and have the editor or GitHub provide the syntax highlighting or rich display for these as part of the markdown rendering.
32 │ x·===·-0; | ||
│ - |
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.
I starred at this for a rather long time to notice that the one -
below the -
is not some dust on my screen... May it be possible to emphasise the -
more in case it's for a single character?
What's the reason that we aren't showing any context lines for this frame?
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 contexts that support rich styling such like the console or the HTML output, both the modified characters and the "diff underline" are emphasized and colored appropriately: https://deploy-preview-3306--rometools.netlify.app/docs/lint/rules/nocomparenegzero/#invalid
Ultimately I think single-character diffs are probably hard to read in most diff rendering mode, but my hope is that this way of printing those diffs makes it at least somewhat easier compared to unified diffs by not requiring the user to mentally parse the same line twice the find the difference, and printing an underline specifically to bring attention to what's above it in contexts that do not support styling.
I also intentionally did not print context lines in this mode, again to help bring the focus on the line being modified and not everything around it. In practice I expect that the line of code being modified will almost always be the same one that was highlighted in the diagnostic's location, and as such it doesn't matter too much that the context isn't printed since it should have been rendered already as part of the diagnostic code frame.
I think the reason why single-line diffs were shown on two lines, was mostly because the logic was easily adaptable for "GitHub diffs", meaning the ability to suggest diffs as GitHub comments on PRs. I am all about clarity and improvements. Let's just take that into consideration and see if this new logic is adaptable for the GitHub comments |
In practice, due to the diff gutter and the invisible characters printing it's not possible to directly copy the output of a diagnostic into a diff that GitHub understands without some significant editing anyway. But as I noted above in my comment on code action snapshots, the |
f0c9582
to
e4a1c0e
Compare
Summary
This PR brings back the rendering of diffs from Rome JS, and should be the last major change required to align the display of diagnostics in the Rust codebase with the previous JS incarnation.
For the rendering itself the code it mostly a direct adaptation of the existing JS logic for Rust. The only major difference is how one-line diffs are rendered (those are diffs that either perform only insertions or only deletions on a single line, this is different from what the code calls "single line diffs" which is when the whole file only spans a single line and we don't need to print line number). With the old logic those diffs would have been printed like this:
Now such a diff will be printed on a single line, highlighting only the parts the text that were added or removed, similarly to how Rustc displays these kinds of suggestions:
Internally, this PR changes how diffs are represented, from a sequence of insert-delete operations (replace a range of the original text with a new string), to a sequence string slices annotated with a "change tag" to know whether they belong to the old revision of the text, the new revision or both versions. Similarly to Rome JS, the Rust version also implements "compressed diffs" where large ranges of text that remained unchanged between the two versions are stored as a simple unchanged line count instead of storing the whole string. Additionally, in order to avoid allocating many short strings in each diff operation, all the string slices that make up a diff are stored in a single "dictionary" string that also de-duplicates identical substrings.
Finally, I also removed a number of unused ways of displaying suggestions in the legacy diagnostics, keeping only the diff display that's actually used (all the other rendering modes can still be implemented using the new diagnostics API)
Test Plan
Besides updating 75 snapshot files, I've added a few test cases for the generation of compressed diffs and their conversions to LSP
TextEdit
operations