mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
flyimport: omit types when completing where-clause
This commit is contained in:
parent
b8ed4a388c
commit
99d91bc550
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…
Reference in a new issue