Skip to content

Commit 5dbd32f

Browse files
committed
bumped some dependencies
listened to clippy simlified python parsing logic a drop
1 parent 31204b1 commit 5dbd32f

File tree

8 files changed

+59
-133
lines changed

8 files changed

+59
-133
lines changed

enum_stuff/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ description = "A proc macro to generate a bunch of stuff for enums - for git_fun
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
syn = { version = "2.0.31", features = ["full", "fold", "extra-traits"] }
14+
syn = { version = "2.0.38", features = ["full", "fold", "extra-traits"] }
1515
quote = "1.0.33"
16-
proc-macro2 = "1.0.66"
16+
proc-macro2 = "1.0.69"
1717
[lib]
1818
proc-macro = true

git-function-history-lib/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ cache = ["dep:cached"]
1919

2020
[dependencies]
2121
chrono = "0.4.31"
22-
ra_ap_syntax = "0.0.174"
22+
ra_ap_syntax = "0.0.180"
2323
rayon = { version = "1.8.0", optional = true }
2424
rustpython-parser = { features = ["lalrpop"], version = "0.3.0" }
2525
lib-ruby-parser = "4.0.5"
26-
gosyn = "0.2.4"
26+
gosyn = "0.2.5"
2727
# can't be published b/c git dependency
2828
# javaparser = {git = "https://github.com/tanin47/javaparser.rs", optional = true}
2929
cfg-if = "1.0.0"
3030
cached = {version = "0.46.0", optional = true}
3131
# git-index-performanc
32-
gix = { version = "0.54.1", default-features = false, features = ["max-performance-safe", "revision"] }
33-
gix-features = { version = "0.35.0", features = ["zlib", "once_cell" ,"walkdir"] }
32+
gix = { version = "0.55.2", default-features = false, features = ["max-performance-safe", "revision"] }
33+
gix-features = { version = "0.36.0", features = ["zlib", "once_cell" ,"walkdir"] }
3434
umpl = "1.1.1"
3535
enum_stuff = {path = "../enum_stuff"}

git-function-history-lib/src/languages/go.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) fn find_function_in_file(
183183
})
184184
.collect::<Vec<_>>();
185185
if parsed.is_empty() {
186-
return Err(format!("could not find function {name} in file"))?;
186+
return Err(format!("could not find function {name} in file"));
187187
}
188188

189189
Ok(parsed)

git-function-history-lib/src/languages/python.rs

Lines changed: 23 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{collections::HashMap, fmt};
1515

1616
use crate::{impl_function_trait, UnwrapToError};
1717

18-
// TODO: cleanup adapting from rp2 tp rp3
18+
// TODO: cleanup adapting from rp2 to rp3
1919

2020
use super::FunctionTrait;
2121

@@ -326,6 +326,8 @@ fn get_functions(
326326
current_class: &mut Vec<StmtClassDef>,
327327
lookup_name: &str,
328328
) {
329+
// we create a list of blocks to be processed
330+
let mut blocks = Vec::new();
329331
match stmt {
330332
Stmt::FunctionDef(function) if function.name.to_string() == lookup_name => {
331333
if function.end_location().is_some() {
@@ -346,77 +348,18 @@ fn get_functions(
346348
}
347349
}
348350
Stmt::If(r#if) => {
349-
get_functions_recurisve(
350-
r#if.body,
351-
map,
352-
functions,
353-
current_parent,
354-
current_class,
355-
lookup_name,
356-
);
357-
get_functions_recurisve(
358-
r#if.orelse,
359-
map,
360-
functions,
361-
current_parent,
362-
current_class,
363-
lookup_name,
364-
);
351+
blocks.extend([r#if.body, r#if.orelse]);
365352
}
366353
Stmt::While(r#while) => {
367-
get_functions_recurisve(
368-
r#while.body,
369-
map,
370-
functions,
371-
current_parent,
372-
current_class,
373-
lookup_name,
374-
);
375-
get_functions_recurisve(
376-
r#while.orelse,
377-
map,
378-
functions,
379-
current_parent,
380-
current_class,
381-
lookup_name,
382-
);
354+
blocks.extend([r#while.body, r#while.orelse]);
383355
}
384356
Stmt::For(r#for) => {
385-
get_functions_recurisve(
386-
r#for.body,
387-
map,
388-
functions,
389-
current_parent,
390-
current_class,
391-
lookup_name,
392-
);
393-
get_functions_recurisve(
394-
r#for.orelse,
395-
map,
396-
functions,
397-
current_parent,
398-
current_class,
399-
lookup_name,
400-
);
357+
blocks.extend([r#for.body, r#for.orelse]);
401358
}
402359
Stmt::AsyncFor(r#for) => {
403-
get_functions_recurisve(
404-
r#for.body,
405-
map,
406-
functions,
407-
current_parent,
408-
current_class,
409-
lookup_name,
410-
);
411-
get_functions_recurisve(
412-
r#for.orelse,
413-
map,
414-
functions,
415-
current_parent,
416-
current_class,
417-
lookup_name,
418-
);
360+
blocks.extend([r#for.body, r#for.orelse]);
419361
}
362+
// we do functions/classes not through blocks as they tell us if a function is nested in a class/function
420363
Stmt::FunctionDef(function) => {
421364
current_parent.push(function.clone().into());
422365
get_functions_recurisve(
@@ -443,7 +386,6 @@ fn get_functions(
443386
}
444387
Stmt::ClassDef(class) => {
445388
current_class.push(class.clone());
446-
447389
get_functions_recurisve(
448390
class.body,
449391
map,
@@ -454,49 +396,26 @@ fn get_functions(
454396
);
455397
current_class.pop();
456398
}
457-
Stmt::With(with) => get_functions_recurisve(
458-
with.body,
459-
map,
460-
functions,
461-
current_parent,
462-
current_class,
463-
lookup_name,
464-
),
465-
Stmt::AsyncWith(with) => get_functions_recurisve(
466-
with.body,
399+
Stmt::With(with) => {
400+
blocks.push(with.body);
401+
}
402+
Stmt::AsyncWith(with) => {
403+
blocks.push(with.body);
404+
}
405+
Stmt::Try(r#try) => {
406+
blocks.extend([r#try.body, r#try.orelse, r#try.finalbody]);
407+
}
408+
_ => {}
409+
};
410+
for block in blocks {
411+
get_functions_recurisve(
412+
block,
467413
map,
468414
functions,
469415
current_parent,
470416
current_class,
471417
lookup_name,
472-
),
473-
Stmt::Try(r#try) => {
474-
get_functions_recurisve(
475-
r#try.body,
476-
map,
477-
functions,
478-
current_parent,
479-
current_class,
480-
lookup_name,
481-
);
482-
get_functions_recurisve(
483-
r#try.orelse,
484-
map,
485-
functions,
486-
current_parent,
487-
current_class,
488-
lookup_name,
489-
);
490-
get_functions_recurisve(
491-
r#try.finalbody,
492-
map,
493-
functions,
494-
current_parent,
495-
current_class,
496-
lookup_name,
497-
);
498-
}
499-
_ => {}
418+
);
500419
}
501420
}
502421
// TODO save arg.defaults & arg.kwdefaults and attempt to map them to the write parameters

git-function-history-lib/src/languages/ruby.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub(crate) fn find_function_in_file(
133133
let parsed = parser.do_parse();
134134
for d in parsed.diagnostics {
135135
if d.is_error() {
136-
return Err(d.message.render())?;
136+
return Err(d.message.render());
137137
}
138138
}
139139
let ast = parsed.ast.unwrap_to_error("Failed to parse file")?;

git-function-history-lib/src/languages/rust.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl RustParentFunction {
118118
map.insert("lifetime generics".to_string(), self.lifetime.join(","));
119119
map.insert("attributes".to_string(), self.attributes.join(","));
120120
map.insert("doc comments".to_string(), self.doc_comments.join(","));
121-
self.return_type.as_ref().map_or((), |return_type| {
121+
if let Some(return_type) = &self.return_type {
122122
map.insert("return type".to_string(), return_type.clone());
123-
});
123+
}
124124
map
125125
}
126126
}
@@ -584,24 +584,31 @@ impl RustFilter {
584584

585585
impl FunctionTrait for RustFunction {
586586
fn get_tops(&self) -> Vec<(String, usize)> {
587-
let mut tops = Vec::new();
588-
self.block.as_ref().map_or((), |block| {
589-
tops.push((block.top.clone(), block.lines.0));
590-
});
591-
for parent in &self.function {
592-
tops.push((parent.top.clone(), parent.lines.0));
593-
}
587+
let mut tops = self
588+
.block
589+
.as_ref()
590+
.map_or(vec![], |block| vec![(block.top.clone(), block.lines.0)]);
591+
tops.extend(
592+
self.function
593+
.iter()
594+
.cloned()
595+
.map(|parent| (parent.top.clone(), parent.lines.0)),
596+
);
597+
594598
tops
595599
}
596600

597601
fn get_bottoms(&self) -> Vec<(String, usize)> {
598-
let mut bottoms = Vec::new();
599-
self.block.as_ref().map_or((), |block| {
600-
bottoms.push((block.bottom.clone(), block.lines.1));
601-
});
602-
for parent in &self.function {
603-
bottoms.push((parent.bottom.clone(), parent.lines.1));
604-
}
602+
let mut bottoms = self
603+
.block
604+
.as_ref()
605+
.map_or(vec![], |block| vec![(block.bottom.clone(), block.lines.1)]);
606+
bottoms.extend(
607+
self.function
608+
.iter()
609+
.cloned()
610+
.map(|parent| (parent.bottom.clone(), parent.lines.1)),
611+
);
605612
bottoms
606613
}
607614

git-function-history-lib/src/languages/umpl.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ fn find_function_recurse(
102102
.lines()
103103
.enumerate()
104104
.filter(|line| line.0 >= lines.0 - 1 && line.0 < lines.1)
105-
.map(|line| format!("{}\n", line.1))
106-
.collect::<String>();
105+
.fold(String::new(), |acc, current| acc + current.1 + "\n");
107106
let new_fn = UMPLFunction {
108107
lines,
109108
name: fns.name.to_string(),
@@ -161,8 +160,7 @@ fn find_function_recurse(
161160
.lines()
162161
.enumerate()
163162
.filter(|line| line.0 >= lines.0 - 1 && line.0 <= top_end)
164-
.map(|line| format!("{}\n", line.1))
165-
.collect::<String>();
163+
.fold(String::new(), |acc, current| acc + current.1 + "\n");
166164
let pfn = UMPLParentFunction {
167165
lines,
168166
name: fns.name.to_string(),

git-function-history-lib/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub fn get_function_history(
224224
let tree = sender(i.0, &th_repo.to_thread_local(), name, *langs, file)?;
225225

226226
if tree.is_empty() {
227-
return Err("empty commit found")?;
227+
Err("empty commit found")?;
228228
}
229229

230230
Ok(FunctionHistory::new(
@@ -269,6 +269,8 @@ pub fn get_function_history(
269269
}
270270
});
271271

272+
// todo use itertools to split into vec of oks and errs
273+
// and report some of errors if no oks and if no oks and errs report no history found
272274
let commits = commits
273275
.filter_map(|i| {
274276
let tree = sender(i.0, &th_repo.to_thread_local(), name, *langs, file);

0 commit comments

Comments
 (0)