-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Words on the first line being dropped? #76
Comments
That's very strange. I literally have tests for this: https://github.com/zkat/miette/blob/main/src/source_impls.rs#L190-L271 Can you tell what corner case there you happen to be running into? Sorry this happened! |
I have no idea what's going on, but to be clear I was expecting the first line of that report to render as...
Maybe I should have posted a failing test rather than trying to explain my expectation in the actual test 🤦 |
This is also what I would expect! |
Hello, I'll be happy to help with this issue ! The issue occurs every time there is a break line ( \n ) and a |
I think you've almost got it. I suspect this is the specific bit that's breaking, because there's no before_context_lines in this particular case. My guess is that the fix will either involve flipping that conditional (oops), or just adding another condition in place. To explain a bit what |
anyway, PRs welcome if you make a test that minimally reproduces this, and then fix that :) |
Here's a failing test: +
+ #[test]
+ fn multiline_with_context_line_start() -> Result<(), MietteError> {
+ let src = String::from("aaa\nxxx\n\nfoo\nbar\nbaz\n\nyyy\nbbb\n");
+ let contents = src.read_span(&(2, 0).into(), 2, 2)?;
+ assert_eq!(
+ "aaa\nxxx\n\n",
+ std::str::from_utf8(contents.data()).unwrap()
+ );
+ assert_eq!(0, contents.line());
+ assert_eq!(0, contents.column());
+ let span: SourceSpan = (0, 9).into();
+ assert_eq!(&span, contents.span());
+ Ok(())
+ } |
It occurred to me after my last comments that I need to add some context: The whole reason for this weirdness is that I tried to solve the problem that #20 is supposed to generalize: Snippets are meant to be windows into the SourceCode that we're trying to render. Good enough windows to show the user what's wrong. But we only have so much space to do it! So this code tries to do two things at once:
If both try to happen at the same time, or if our checks run into those corner cases, everything breaks, and that's what's actually happening here. So... the Ideal Solution is actually to just solve #20 and add a "bounding box width" option that will give us the width, alongside the height (context lines), for our little bounding box. That's an API breaking change, though, so I'd rather just fix this issue's bug individually if we can, for now. I just thought the context might help make sense of why this code is being so weird. |
Thank you for all these helpful information :) It's very clear, what data is and how is it used ! |
Hey,
First up, this library is dope. Love your work. 🚀
I'm having one small issue though - if I have a
SourceSpan
that points somewhere in the first line of some source code, that first line seems to get chopped.Here's a test to reproduce:
The text was updated successfully, but these errors were encountered: