}
_ => return,
},
+
+ hir::ModuleDef::Function(_) => return,
};
}
.ancestors()
.take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE)
.find_map(ast::FnDef::cast);
- match (&self.module, self.function_syntax) {
+ match (self.module, self.function_syntax) {
(Some(module), Some(fn_def)) => {
let function = source_binder::function_from_module(self.db, module, fn_def);
self.function = Some(function);
};
let (kind, docs) = match def {
hir::ModuleDef::Module(_) => (CompletionItemKind::Module, None),
+ hir::ModuleDef::Function(func) => return self.from_function(ctx, func),
hir::ModuleDef::Def(def_id) => match def_id.resolve(ctx.db) {
hir::Def::Struct(it) => (CompletionItemKind::Struct, it.docs(ctx.db)),
hir::Def::Enum(it) => (CompletionItemKind::Enum, it.docs(ctx.db)),
hir::Def::Type(it) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)),
hir::Def::Const(it) => (CompletionItemKind::Const, it.docs(ctx.db)),
hir::Def::Static(it) => (CompletionItemKind::Static, it.docs(ctx.db)),
- hir::Def::Function(function) => return self.from_function(ctx, function),
_ => return self,
},
};
let infer_result = function.infer(db);
let syntax_mapping = function.body_syntax_mapping(db);
let expr = ast::Expr::cast(method_call.syntax()).unwrap();
- if let Some(def_id) = syntax_mapping
+ if let Some(func) = syntax_mapping
.node_expr(expr)
.and_then(|it| infer_result.method_resolution(it))
{
- if let Some(target) = NavigationTarget::from_def(db, hir::ModuleDef::Def(def_id)) {
- return Exact(target);
- }
+ return Exact(NavigationTarget::from_function(db, func));
};
}
}
NavigationTarget::from_module(db, module)
}
+ pub(crate) fn from_function(db: &RootDatabase, func: hir::Function) -> NavigationTarget {
+ let (file_id, fn_def) = func.source(db);
+ NavigationTarget::from_named(file_id.original_file(db), &*fn_def)
+ }
+
// TODO once Def::Item is gone, this should be able to always return a NavigationTarget
pub(crate) fn from_def(
db: &RootDatabase,
hir::ModuleDef::Module(module) => {
return Some(NavigationTarget::from_module(db, module));
}
+ hir::ModuleDef::Function(func) => {
+ return Some(NavigationTarget::from_function(db, func));
+ }
};
let res = match def {
let (file_id, node) = ev.source(db);
NavigationTarget::from_named(file_id.original_file(db), &*node)
}
- Def::Function(f) => {
- let (file_id, node) = f.source(db);
- NavigationTarget::from_named(file_id.original_file(db), &*node)
- }
Def::Trait(f) => {
let (file_id, node) = f.source(db);
NavigationTarget::from_named(file_id.original_file(db), &*node)