-fn build_path(ast_func: &ast::Fn, krate_name: String) -> String {
- let mut path: Vec<String> = ast_func
- .syntax()
- .ancestors()
- .filter_map(|m| ast::Module::cast(m).and_then(|m| m.name()))
- .map(|m| m.to_string())
- .collect();
- path.push(krate_name);
- path.reverse();
- path.push(
- self_partial_type(ast_func)
- .or_else(|| ast_func.name().map(|n| n.to_string()))
- .unwrap_or_else(|| "*".into()),
- );
- intersperse_string(path.into_iter(), "::")
+fn build_path(ast_func: &ast::Fn, ctx: &AssistContext) -> Option<String> {
+ let crate_name = crate_name(ast_func, ctx)?;
+ let leaf = self_partial_type(ast_func)
+ .or_else(|| ast_func.name().map(|n| n.to_string()))
+ .unwrap_or_else(|| "*".into());
+ let func_module_def: ModuleDef = ctx.sema.to_def(ast_func)?.module(ctx.db()).into();
+ match func_module_def.canonical_path(ctx.db()) {
+ Some(path) => Some(format!("{}::{}::{}", crate_name, path, leaf)),
+ None => Some(format!("{}::{}", crate_name, leaf)),
+ }