Skip to content

Commit

Permalink
docs: Generate links for Class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Apr 30, 2023
1 parent 34d48f9 commit ab08e60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/codegen/doc/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ fn find_method_or_function_by_ctype(
|r| c_type.map_or(true, |t| r.type_(&env.library).c_type == t),
|r| c_type.map_or(true, |t| r.type_(&env.library).c_type == t),
c_type.map_or(false, |t| t.ends_with("Class")),
false,
)
}

Expand All @@ -418,8 +419,9 @@ pub(crate) fn find_method_or_function(
search_enum: impl Fn(&crate::analysis::enums::Info) -> bool + Copy,
search_flag: impl Fn(&crate::analysis::flags::Info) -> bool + Copy,
is_class_method: bool,
is_virtual_method: bool,
) -> Option<String> {
if is_class_method {
if is_virtual_method {
if let Some((obj_info, fn_info)) = env
.analysis
.find_object_by_virtual_method(env, search_obj, search_fn)
Expand All @@ -434,6 +436,21 @@ pub(crate) fn find_method_or_function(
} else {
None
}
} else if is_class_method {
if let Some((record_info, fn_info)) =
env.analysis
.find_record_by_function(env, search_record, search_fn)
{
let object = env.config.objects.get(&record_info.full_name);
let visible_parent = object
.and_then(|o| o.trait_name.clone())
.unwrap_or_else(|| format!("{}SubclassExt", record_info.name));
let parent = format!("subclass::prelude::{}", visible_parent);
let is_self = in_type == Some((&record_info.type_id, None));
Some(fn_info.doc_link(Some(&parent), Some(&visible_parent), is_self))
} else {
None
}
// if we can find the function in an object
} else if let Some((obj_info, fn_info)) = env
.analysis
Expand Down Expand Up @@ -509,7 +526,7 @@ pub(crate) fn gen_object_fn_doc_link(
let sym = symbols.by_tid(obj_info.type_id).unwrap();
let is_self = in_type == Some((&obj_info.type_id, Some(obj_info.function_location(fn_info))));

if fn_info.kind == FunctionKind::VirtualMethod {
if fn_info.kind == FunctionKind::VirtualMethod || fn_info.kind == FunctionKind::ClassMethod {
let (type_name, visible_type_name) = obj_info.generate_doc_link_info(fn_info);
fn_info.doc_link(
Some(&sym.full_rust_name().replace(visible_name, &type_name)),
Expand Down
2 changes: 2 additions & 0 deletions src/codegen/doc/gi_docgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ fn find_virtual_method(
|_| false,
|_| false,
|_| false,
false,
true,
)
}
Expand Down Expand Up @@ -263,6 +264,7 @@ fn find_method_or_function_by_name(
})
},
is_class_method,
false,
)
}

Expand Down

0 comments on commit ab08e60

Please sign in to comment.