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 write.rs #119

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Refactor write.rs #119

wants to merge 38 commits into from

Conversation

ISSOtm
Copy link
Contributor

@ISSOtm ISSOtm commented Jul 5, 2024

I'm aware this is a big PR, but I tried addressing that below the separation line.

The change that motivated this rewrite was allowing help and note messages to show up even on label-less diagnostics. (This turned out to be very difficult to implement in the current architecture, so I figured it wouldn't hurt to clean it up as a way to learn its ins and outs.)

The other main upshot is that the printing logic should be far less opaque and hairy, and thus more maintainable. To the best of my knowledge, there is only one breaking change here, the new Location struct. It can be removed if compat breakage is to be avoided.


As for this PR's scope, I seem to understand from looking more broadly at this repo's issue tracker, that you'd like to spend less time on this crate; perhaps more on ariadne2, perhaps on something else (including non-programming).

I understand and relate to the sentiment, and I respect your decision whatever its rationale.
I would also like to improve ariadne further, as it's a great crate that I'd like to see some kinks of ironed out for my own projects.
I think I can do my part in bringing these two together by volunteering to help with maintenance. I am willing to start owning the same code I started hacking on and tweaking, and going through the issues and PRs.

Let me know if you're interested—I'm also available at my commit email address, if you'd rather discuss that topic privately.
I'll also understand if you decline that offer and/or reject this PR, of course 😛

@zesterer
Copy link
Owner

zesterer commented Jul 7, 2024

Wow, this is a great PR! I'm going to try to get some time to look through this properly, but unfortunately I'm travelling for 2 weeks as of tomorrow so it'll have to be after that. I really appreciate the time spent on this though!

@ISSOtm
Copy link
Contributor Author

ISSOtm commented Jul 7, 2024

No worries, then :)

As for the reviewing process, I tried making the commit log be easier to process piece-meal. (GitHub's UI allows you to review each commit's changes individually.) I think that should be all the more useful as the PR's cumulative changes are really large and complex.

Do let me know if you have doubts or questions about any part of this ^^

@hellow554
Copy link

hey @ISSOtm

what an awesome PR.

One thing that bugged me a lot in ariadne is trailing whitespace in the output.
Your PR seemed to made it "worse" (not as an offend, please bear with me!)

grafik

What do you think: Would it be possible to remove trailing whitespaces in your code, or is that not possible in the current situation?

@ISSOtm
Copy link
Contributor Author

ISSOtm commented Jul 9, 2024

FWIW, this is still as much whitespace as the current code, there's just more labels so it's more whitespace.

I can look into removing trailing whitespace, but does it cause any practical trouble?

@hellow554
Copy link

Åh okay, it looked worse, sorry 🙈
Yes and no: I'm running ui tests on my program and often there's trailing white space that vscode likes to remove on every occasion.
Therefore I hoped that it can be "fixed"

@ISSOtm
Copy link
Contributor Author

ISSOtm commented Jul 10, 2024

Sublime Text has a "only trim trailing whitespace on lines I modified myself" option, which is more appropriate for this. I don't know if VS Code has something similar.

@ISSOtm
Copy link
Contributor Author

ISSOtm commented Nov 28, 2024

White rebasing this PR, I'm realising that there are several commits that could be cherry-picked into separate PRs. @zesterer, would you prefer if I did that?

@ISSOtm
Copy link
Contributor Author

ISSOtm commented Nov 28, 2024

I've rebased this PR against main, and ensured that every single commit passes cargo test on its own, so commits can be cherry-picked as necessary.

fmt and clippy fail, but they also do on main. Let me know if you'd like PRs that fix those.

And also use a simpler, `log10`-based logic
This makes its purpose clearer, and also removes one pair of parens
Makes sense to have that logic next to the `Display` impl, IMO
This ensures only a single copy of the error message exists,
and outlines yet more code outside of the massive
`write_for_stream` function.
This improves dead code analysis
Just deflating the line count a bit
Missed it, because that one didn't have the `<unknown>` fallback.
Introducing it should improve consistency a bit.
Further deflating `write_for_stream`, though it also
should improve performance slightly:
- The number of digits is only computed for the greatest line number
- This is a valid transformation, because the largest line no is also
  one of the largest
Making its purpose clearer.
In the hopes of making the function a little shorter
This is more compact, and it might be cheaper too!
The field names are more expressive than a tuple
To determine what goes to the left of a "source group" designation
It makes the purpose of the pointer comparison clearer
and is a little bit more concise.
Factor out most of the repeated code
Use `collect()` for hopefully better Vec prealloc,
derive one of the arrays from the other (since it's
a subset of the first), and sort the first array to
guarantee that the second one already is.
`format_args!` is more difficult to use (hence why `code`
stays), but avoids allocating a `String`
It has more character variety, and thus is more likely
to show differences that wouldn't be visible in ASCII
There aren't any labels left by that point
This eliminates a few parameters, and makes each "section"'s
purpose more evident
@ISSOtm ISSOtm force-pushed the write_refactor branch 3 times, most recently from c08f8e8 to dab841a Compare December 10, 2024 19:11
@zesterer
Copy link
Owner

Thanks! Going to try to review this over the weekend.

@ISSOtm
Copy link
Contributor Author

ISSOtm commented Dec 12, 2024

Those checks don't fail locally, but this seems to be caused by a Rust version difference. I'm not sure which version I should be using, since the crate doesn't specify a MSRV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants