Merge #11931
11931: fix: flyimport: omit types when completing where-clause r=jonas-schievink a=jonas-schievink Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11918 bors r+ Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
commit
bc56920757
2 changed files with 28 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
//! See [`import_on_the_fly`].
|
||||
use hir::ItemInNs;
|
||||
use hir::{ItemInNs, ModuleDef};
|
||||
use ide_db::imports::{
|
||||
import_assets::{ImportAssets, ImportCandidate, LocatedImport},
|
||||
insert_use::ImportScope,
|
||||
|
|
@ -9,6 +9,7 @@ use syntax::{AstNode, SyntaxNode, T};
|
|||
|
||||
use crate::{
|
||||
context::{CompletionContext, PathKind},
|
||||
patterns::ImmediateLocation,
|
||||
render::{render_resolution_with_import, RenderContext},
|
||||
};
|
||||
|
||||
|
|
@ -170,7 +171,13 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
|
|||
(PathKind::Pat, ItemInNs::Types(_)) => true,
|
||||
(PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
|
||||
|
||||
(PathKind::Type, ItemInNs::Types(_)) => true,
|
||||
(PathKind::Type, ItemInNs::Types(ty)) => {
|
||||
if matches!(ctx.completion_location, Some(ImmediateLocation::TypeBound)) {
|
||||
matches!(ty, ModuleDef::Trait(_))
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
(PathKind::Type, ItemInNs::Values(_)) => false,
|
||||
|
||||
(PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),
|
||||
|
|
|
|||
|
|
@ -1170,3 +1170,22 @@ struct Foo;
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flyimport_in_type_bound_omits_types() {
|
||||
check(
|
||||
r#"
|
||||
mod module {
|
||||
pub struct CompletemeStruct;
|
||||
pub type CompletemeType = ();
|
||||
pub enum CompletemeEnum {}
|
||||
pub trait CompletemeTrait {}
|
||||
}
|
||||
|
||||
fn f<T>() where T: Comp$0
|
||||
"#,
|
||||
expect![[r#"
|
||||
tt CompletemeTrait (use module::CompletemeTrait)
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue