Skip to content

Commit 1b9d503

Browse files
committed
removed -> from return type field in rust function, and genrics no longer include lifetimes
1 parent ae9a89a commit 1b9d503

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ pub(crate) fn find_function_in_file(
133133
return Err(d.message.render())?;
134134
}
135135
}
136-
// POSSBLE TODO check if there is any error dianostics parsed.dadnostices and return error is so
137136
let ast = parsed.ast.unwrap_to_error("Failed to parse file")?;
138137
let fns = get_functions_from_node(&ast, &vec![], name);
139138
let index = super::turn_into_index(file_contents)?;

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{collections::HashMap, fmt};
22

33
use ra_ap_syntax::{
4-
ast::{self, HasDocComments, HasGenericParams, HasName},
4+
ast::{self, HasDocComments, HasGenericParams, HasName, Fn},
55
AstNode, SourceFile, SyntaxKind,
66
};
77

@@ -302,7 +302,7 @@ pub(crate) fn find_function_in_file(
302302
top: stuff.1 .0,
303303
bottom: stuff.1 .1,
304304
lines: (stuff.0 .0, stuff.0 .1),
305-
return_type: function.ret_type().map(|ty| ty.to_string()),
305+
return_type: get_ret_type(&function),
306306
arguments: f.param_list().map_or_else(HashMap::new, |args| {
307307
args.params()
308308
.filter_map(|arg| {
@@ -341,7 +341,7 @@ pub(crate) fn find_function_in_file(
341341
body,
342342
block: parent_block,
343343
function: parent_fn,
344-
return_type: f.ret_type().map(|ty| ty.to_string()),
344+
return_type: get_ret_type(&f),
345345
arguments: f.param_list().map_or_else(HashMap::new, |args| {
346346
args.params()
347347
.filter_map(|arg| {
@@ -419,9 +419,11 @@ fn get_genrerics_and_lifetime<T: HasGenericParams>(block: &T) -> (Vec<String>, V
419419
|| (vec![], vec![]),
420420
|gt| {
421421
(
422-
// gt.
423-
gt.generic_params()
424-
.map(|gt| gt.to_string())
422+
gt.type_or_const_params()
423+
.map(|gt|match gt {
424+
ast::TypeOrConstParam::Type(ty) => ty.to_string(),
425+
ast::TypeOrConstParam::Const(c) => c.to_string(),
426+
})
425427
.collect::<Vec<String>>(),
426428
gt.lifetime_params()
427429
.map(|lt| lt.to_string())
@@ -443,6 +445,16 @@ fn get_doc_comments_and_attrs<T: HasDocComments>(block: &T) -> (Vec<String>, Vec
443445
.collect::<Vec<String>>(),
444446
)
445447
}
448+
449+
fn get_ret_type(fns: &Fn) -> Option<String> {
450+
match fns.ret_type() {
451+
Some(ret) => match ret.ty() {
452+
Some(ty) => Some(ty.to_string()),
453+
None => None,
454+
},
455+
None => None,
456+
}
457+
}
446458
#[derive(Debug, Clone, PartialEq, Eq)]
447459
pub enum RustFilter {
448460
/// when you want to filter by function that are in a specific block (impl, trait, extern)

0 commit comments

Comments
 (0)