-
Notifications
You must be signed in to change notification settings - Fork 510
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
Integrate new hunk dependency algorithm #5252
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
6b54132
to
5f308f7
Compare
5f308f7
to
de8ad1c
Compare
de8ad1c
to
b0c54c1
Compare
- behind a project level feature flag
b0c54c1
to
73720ac
Compare
73720ac
to
f8b46f6
Compare
f8b46f6
to
42266b8
Compare
|
||
impl InputDiff { | ||
pub fn net_lines(&self) -> i32 { | ||
self.new_lines as i32 - self.old_lines as i32 |
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.
You can use the do different kinds of subtraction as a method on the new_lines, and you wont have to cast.
You probably wanna do the 'checked' kind though, which returns an Option.
Seems like net_lines is called from add_new which is called from add, which returns a Result.
So you can do something like
self.net_lines()
.checked_sub_unsigned(self.old_lines)
.ok_or(anyhow!("Overflowed computing net lines"))
and do the ? operator. It's gonna be so much easier to debug in the future
.collect::<HashSet<_>>(); | ||
|
||
Ok(WorkspaceRanges { | ||
paths: HashMap::from_iter( |
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.
You can skip from_iter and have the compiler infer the type like this
paths: paths
.iter()
.map(|path| (path.clone(), combine_path_ranges(path, &stacks)))
.collect(),
```
use crate::{diff::InputDiff, hunk::HunkRange, stack::StackRanges}; | ||
|
||
#[derive(Debug, Default, PartialEq, Clone)] | ||
pub struct WorkspaceRanges { |
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.
Kinda related to our IRL conversation earlier... so there is this convention to no "stutter" in names - this is module workspace, name WorkspaceRanges.
So if you want your API to be consumed as a hierarchy, it would be idiomatic to have workspace::Ranges
at the consumption side.
I tend to prefer a flatter structure - exporting these types in the root level, and in that case I need the name would be WorkspaceRanges
to be descriptive.
This is doing both which is suboptimal. Can rename later but trying to help shape the thinking here a bit
} | ||
let paths = stacks | ||
.iter() | ||
.flat_map(|stack| stack.unique_paths()) |
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.
You can write these like .flat_map(StackRanges::unique_paths)
as well
@@ -0,0 +1,6 @@ | |||
pub mod diff; |
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 is still quite a bit of panic-y access by index. You can see it by adding this clippy rule at the top of the file
#![warn(clippy::indexing_slicing)]
While annoying to replace now, it will pay dividends if/when we hit stuff to debug
No description provided.