Auto merge of - Veykril:completion-panic, r=Veykril

fix: Fix completions analysis not caching all nodes in Semantics

Fixes https://github.com/rust-lang/rust-analyzer/issues/16161
This commit is contained in:
bors 2023-12-22 12:13:46 +00:00
commit afbb8f31ff

@ -1,7 +1,7 @@
//! Module responsible for analyzing the code surrounding the cursor for completion.
use std::iter;
use hir::{HasSource, Semantics, Type, TypeInfo, Variant};
use hir::{Semantics, Type, TypeInfo, Variant};
use ide_db::{active_parameter::ActiveParameter, RootDatabase};
use syntax::{
algo::{find_node_at_offset, non_trivia_sibling},
@ -742,13 +742,13 @@ fn classify_name_ref(
match sema.resolve_path(&segment.parent_path().top_path())? {
hir::PathResolution::Def(def) => match def {
hir::ModuleDef::Function(func) => {
func.source(sema.db)?.value.generic_param_list()
sema.source(func)?.value.generic_param_list()
}
hir::ModuleDef::Adt(adt) => {
adt.source(sema.db)?.value.generic_param_list()
sema.source(adt)?.value.generic_param_list()
}
hir::ModuleDef::Variant(variant) => {
variant.parent_enum(sema.db).source(sema.db)?.value.generic_param_list()
sema.source(variant.parent_enum(sema.db))?.value.generic_param_list()
}
hir::ModuleDef::Trait(trait_) => {
if let ast::GenericArg::AssocTypeArg(arg) = &arg {
@ -774,14 +774,14 @@ fn classify_name_ref(
return None;
} else {
in_trait = Some(trait_);
trait_.source(sema.db)?.value.generic_param_list()
sema.source(trait_)?.value.generic_param_list()
}
}
hir::ModuleDef::TraitAlias(trait_) => {
trait_.source(sema.db)?.value.generic_param_list()
sema.source(trait_)?.value.generic_param_list()
}
hir::ModuleDef::TypeAlias(ty_) => {
ty_.source(sema.db)?.value.generic_param_list()
sema.source(ty_)?.value.generic_param_list()
}
_ => None,
},
@ -790,7 +790,7 @@ fn classify_name_ref(
},
ast::MethodCallExpr(call) => {
let func = sema.resolve_method_call(&call)?;
func.source(sema.db)?.value.generic_param_list()
sema.source(func)?.value.generic_param_list()
},
ast::AssocTypeArg(arg) => {
let trait_ = ast::PathSegment::cast(arg.syntax().parent()?.parent()?)?;
@ -807,7 +807,7 @@ fn classify_name_ref(
},
_ => None,
})?;
assoc_ty.source(sema.db)?.value.generic_param_list()
sema.source(*assoc_ty)?.value.generic_param_list()
}
_ => None,
},