fix: ide: exclude sized in go-to actions

This commit is contained in:
Jake Heinz 2023-05-02 08:19:59 +00:00
parent 2fdd1ac510
commit 3132a9e7fc
3 changed files with 24 additions and 3 deletions

View file

@ -6,7 +6,7 @@ mod tests;
use std::iter;
use either::Either;
use hir::{HasSource, Semantics};
use hir::{db::DefDatabase, HasSource, LangItem, Semantics};
use ide_db::{
base_db::FileRange,
defs::{Definition, IdentClass, OperatorClass},
@ -353,7 +353,14 @@ fn goto_type_action_for_def(db: &RootDatabase, def: Definition) -> Option<HoverA
};
if let Definition::GenericParam(hir::GenericParam::TypeParam(it)) = def {
it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
let krate = it.module(db).krate();
let sized_trait =
db.lang_item(krate.into(), LangItem::Sized).and_then(|lang_item| lang_item.as_trait());
it.trait_bounds(db)
.into_iter()
.filter(|&it| Some(it.into()) != sized_trait)
.for_each(|it| push_new_def(it.into()));
} else {
let ty = match def {
Definition::Local(it) => it.ty(db),

View file

@ -2098,6 +2098,19 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
);
}
#[test]
fn test_hover_generic_excludes_sized_go_to_action() {
check_actions(
r#"
//- minicore: sized
struct S<T$0>(T);
"#,
expect![[r#"
[]
"#]],
);
}
#[test]
fn test_hover_generic_struct_has_flattened_goto_type_actions() {
check_actions(