-
-
Notifications
You must be signed in to change notification settings - Fork 581
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
add syntax highlighting for blame view (#745) #1914
Conversation
2a47110
to
243d7a5
Compare
Hi @extrawurst, could you take a look into this PR? If there is anything need to change please let me know. Thank you! |
src/components/blame_file.rs
Outdated
struct SyntaxFileBlame { | ||
/// | ||
pub commit_id: CommitId, | ||
/// |
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 some empty comments and some without? consistency please
src/components/blame_file.rs
Outdated
@@ -295,6 +315,10 @@ impl BlameFileComponent { | |||
table_state: std::cell::Cell::new(TableState::default()), | |||
key_config, | |||
current_height: std::cell::Cell::new(0), | |||
async_highlighting: AsyncSingleJob::new( |
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 would argue we should put it in an option and only keep it around while there is an async job ongoing and initialize it to None
first
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.
As I see in the codebase, this is currently the way that other components instantiate the async jobs. Also, keeping this way makes it easier to process the job's result, instead of multi-level pattern-matching.
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 order to keep things maintainable i started using this pattern successfully in Revlog
with LogSearch
.
in our case here we can combine probably 4 member (async_blame
, syntax_progress
, file_blame
and async_highlighting
) variables into an enum depending on our state and it makes it easier to reason which ones are expected to be valid at what state.
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.
Looks great. Let me try it.
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 status here? Would be great to carry over the finish line!
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.
Will put it in draft till reworked
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 refactored it and combined all those 4 processes into the one below just as you suggested.
gitui/src/components/blame_file.rs
Lines 57 to 64 in 1faaf4a
enum BlameProcess { | |
GettingBlame(AsyncBlame), | |
SyntaxHighlighting { | |
unstyled_file_blame: SyntaxFileBlame, | |
job: AsyncSingleJob<AsyncSyntaxJob>, | |
}, | |
Result(SyntaxFileBlame), | |
} |
gitui/src/components/blame_file.rs
Lines 86 to 98 in 1faaf4a
pub struct BlameFileComponent { | |
title: String, | |
theme: SharedTheme, | |
queue: Queue, | |
visible: bool, | |
open_request: Option<BlameFileOpen>, | |
params: Option<BlameParams>, | |
table_state: std::cell::Cell<TableState>, | |
key_config: SharedKeyConfig, | |
current_height: std::cell::Cell<usize>, | |
blame: BlameProcess, | |
app_sender: Sender<AsyncAppNotification>, | |
} |
src/components/blame_file.rs
Outdated
match progress { | ||
SyntaxHighlightProgress::Progress => { | ||
self.syntax_progress = | ||
self.async_highlighting.progress(); |
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 have to double check but i think the progress retrieval is pretty lightweight, no need to cache it
src/components/blame_file.rs
Outdated
file_blame.styled_text = | ||
Some(syntax); | ||
} | ||
// *(self.file_blame.s = Either::Left(syntax); |
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.
please clean up not needed comments
src/components/blame_file.rs
Outdated
self.file_blame | ||
.as_ref() | ||
.map_or_else(Vec::new, |file_blame| { | ||
file_blame | ||
return file_blame |
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.
please keep it consistent with the non-return call style, last statement without ;
is the return value
src/components/blame_file.rs
Outdated
text.clone(), | ||
params.file_path.clone(), | ||
)); | ||
self.async_highlighting.spawn(AsyncSyntaxJob::new( |
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 spawn the same job twice?
243d7a5
to
045b204
Compare
src/components/blame_file.rs
Outdated
|
||
static NO_COMMIT_ID: &str = "0000000"; | ||
static NO_AUTHOR: &str = "<no author>"; | ||
static MIN_AUTHOR_WIDTH: usize = 3; | ||
static MAX_AUTHOR_WIDTH: usize = 20; | ||
|
||
struct SyntaxFileBlame { | ||
pub commit_id: CommitId, |
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.
these elements (commit_id
, path
and lines
) are FileBlame
please reuse that component
src/components/blame_file.rs
Outdated
@@ -295,6 +315,10 @@ impl BlameFileComponent { | |||
table_state: std::cell::Cell::new(TableState::default()), | |||
key_config, | |||
current_height: std::cell::Cell::new(0), | |||
async_highlighting: AsyncSingleJob::new( |
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 order to keep things maintainable i started using this pattern successfully in Revlog
with LogSearch
.
in our case here we can combine probably 4 member (async_blame
, syntax_progress
, file_blame
and async_highlighting
) variables into an enum depending on our state and it makes it easier to reason which ones are expected to be valid at what state.
045b204
to
e5a711f
Compare
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.
Please update
e5a711f
to
1faaf4a
Compare
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.
looks much better. please update to current master and then we can merge
a7999ef
to
2bf6c45
Compare
2bf6c45
to
5c331ff
Compare
@tdtrung17693 thank you so much! |
This Pull Request fixes/closes #745.
It changes the following:
I followed the checklist:
make check
without errors