Skip to content

Commit bc56920

Browse files
bors[bot]Jonas Schievink
and
Jonas Schievink
authored
Merge #11931
11931: fix: flyimport: omit types when completing where-clause r=jonas-schievink a=jonas-schievink Fixes #11918 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents b8ed4a3 + 99d91bc commit bc56920

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

crates/ide_completion/src/completions/flyimport.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! See [`import_on_the_fly`].
2-
use hir::ItemInNs;
2+
use hir::{ItemInNs, ModuleDef};
33
use ide_db::imports::{
44
import_assets::{ImportAssets, ImportCandidate, LocatedImport},
55
insert_use::ImportScope,
@@ -9,6 +9,7 @@ use syntax::{AstNode, SyntaxNode, T};
99

1010
use crate::{
1111
context::{CompletionContext, PathKind},
12+
patterns::ImmediateLocation,
1213
render::{render_resolution_with_import, RenderContext},
1314
};
1415

@@ -170,7 +171,13 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
170171
(PathKind::Pat, ItemInNs::Types(_)) => true,
171172
(PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
172173

173-
(PathKind::Type, ItemInNs::Types(_)) => true,
174+
(PathKind::Type, ItemInNs::Types(ty)) => {
175+
if matches!(ctx.completion_location, Some(ImmediateLocation::TypeBound)) {
176+
matches!(ty, ModuleDef::Trait(_))
177+
} else {
178+
true
179+
}
180+
}
174181
(PathKind::Type, ItemInNs::Values(_)) => false,
175182

176183
(PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),

crates/ide_completion/src/tests/flyimport.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,3 +1170,22 @@ struct Foo;
11701170
"#,
11711171
);
11721172
}
1173+
1174+
#[test]
1175+
fn flyimport_in_type_bound_omits_types() {
1176+
check(
1177+
r#"
1178+
mod module {
1179+
pub struct CompletemeStruct;
1180+
pub type CompletemeType = ();
1181+
pub enum CompletemeEnum {}
1182+
pub trait CompletemeTrait {}
1183+
}
1184+
1185+
fn f<T>() where T: Comp$0
1186+
"#,
1187+
expect![[r#"
1188+
tt CompletemeTrait (use module::CompletemeTrait)
1189+
"#]],
1190+
);
1191+
}

0 commit comments

Comments
 (0)