-
Notifications
You must be signed in to change notification settings - Fork 132
feat: just in time rendering #392
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
Conversation
NOTE: we still need to implement the rendering of commits
this makes more sense since we store a lot of different data
Something is very broken with diffing in this commit lol. On the bright side; We are rendering the status items and commits again!
this method now returns a `Vec<Line>` instead of a single `Line` NOTE: hunk highlighting is crashing in this commit for some reason :(
|
Crashing somewhere here at the moment: Lines 330 to 373 in 1d1a7a7
ERROR: Reading errors is really tricky currently, maybe I should implement a panic hook that logs the stacktrace to a file somewhere in a separate PR. What do you think about that @altsem ? |
|
I've been hacking away some more and the current problem is rendering We have since moved over highlighting to the render step but the problem is now that we need to rework I skimmed through
|
Panic hookI realize this used to exist, seems I dropped it (by mistake?) in 3cb28c6. HighlightingIt does become tricky to highlight just a single line, since the highlighting is contextual. Now, it has some limited context actually -just a single hunk at a time. My idea was that if there was some way to cache/memoize highlighted lines, the code constructing the screen could just be asking
Now some caching/memoizing middle layer could then check if it has hunk 1 in store. And then either:
But in practice, using something like https://github.com/jaemk/cached could be neat: #[cached]
pub(crate) fn highlight_hunk<'a>(
config: &'a Config,
diff: &'a Rc<Diff>,
file_i: usize,
hunk_i: usize,
) -> HunkHighlights {
struct HunkHighlights {
spans: Vec<(Range<usize>, Style)>,
line_index: Vec<usize, Range<usize>>,
}
impl HunkHighlights {
fn get_line_spans(&self, line: usize) -> &[(Range<usize>, Style)] {
let line_range = self.line_index[line];
spans[line_range]
}
}Consider these some suggestions. |
Syntax highlightingHad never heard of cached before but it looked pretty fitting so I tried my hand at implementing some caching for syntax highlighting and it seems to be working! I'm currently failing a bunch of tests but most of the original functionality seems to be restored. Will take a closer look at tests next. One thing I've also noticed is that even if we don't highlight the diffs immediately anymore, we parse and prepare diffs for highlighting even if they are not being rendered on the screen. Not sure if this means that they'll get processed for syntax highlighting anyways because of how Panic hookI've moved discussion to #393 :) |
this takes care of the last of the tests that were failing
|
@mWalrus i made some hashes for other purposes the other day here :) https://github.com/altsem/gitu/blob/master/src/items.rs#L126 It's needed to populate Item.id. Perhaps there's a way to compute it just once? Else it might not be too expensive to call again |
@altsem, |
altsem
left a comment
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.
Checking in on the progress and dumped some thoughts.
I think this is coming along really well. Feels like pieces are falling into place.
Will try poke around some more soon again
this fails compilation even though it shouldn't so I just removed it lol
altsem
left a comment
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.
Found just one potential issue with the collapsed section config.
I'm curious how this will perform, if it solves that nasty lag in larger projects.
| ), | ||
| format!(" ({})", diff.file_diffs.len()).into(), | ||
| ]), | ||
| id: hash(section), |
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.
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.
@altsem,
I'm not really liking how we were passing around strings for section headers as it makes matching more brittle in my opinion, hence why I went with an enum.
Restoring this is no problem if keeping the old behavior is required but I'd love to rework this slightly so it's easier to maintain while keeping original behavior, if that's not out of scope.
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 made an attempt in f732d3e.
This comment was marked as spam.
This comment was marked as spam.
|
Oh, and, I reviewed everything and think we're basically good to go with the aforementioned things fixed! The changelog generation is currently based on git commits, but I'm considering trashing it and doing it manually at some point... Or if we squash everything in here. 🤔 |
|
@altsem, |
|
I'll merge this, let it sit in master for a few days, perhaps bundle some more stuff in, then include it in a release soon :) gj! |
|
This is a great improvement, I recently had a case where highlighting (a brutal JSON file) caused a lot of slowdown, so thanks!
I noticed this, and thought I'd point out that you could configure git-cliff to filter based on merge commit, so if you discard non-merge commits then as long as your merge commit is conventional, it would be a "one PR equals one changelog item" workflow. |
Cherry picked commits from #391.
Todo
Above are not working because they are not being assigned
ItemData.Supersedes #391.