source_to_def: skip items with no def

This commit is contained in:
Jonas Schievink 2021-06-08 16:42:48 +02:00
parent 16e142cd39
commit 8482329d65

View file

@ -211,7 +211,17 @@ impl SourceToDefCtx<'_, '_> {
pub(super) fn find_container(&mut self, src: InFile<&SyntaxNode>) -> Option<ChildContainer> {
for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) {
let res: ChildContainer = match_ast! {
if let Some(res) = self.container_to_def(container) {
return Some(res);
}
}
let def = self.file_to_def(src.file_id.original_file(self.db.upcast())).get(0).copied()?;
Some(def.into())
}
fn container_to_def(&mut self, container: InFile<SyntaxNode>) -> Option<ChildContainer> {
let cont = match_ast! {
match (container.value) {
ast::Module(it) => {
let def = self.module_to_def(container.with_value(it))?;
@ -257,14 +267,10 @@ impl SourceToDefCtx<'_, '_> {
let def = self.enum_variant_to_def(container.with_value(it))?;
VariantId::from(def).into()
},
_ => continue,
_ => return None,
}
};
return Some(res);
}
let def = self.file_to_def(src.file_id.original_file(self.db.upcast())).get(0).copied()?;
Some(def.into())
Some(cont)
}
fn find_generic_param_container(&mut self, src: InFile<&SyntaxNode>) -> Option<GenericDefId> {