mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +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`].
|
//! See [`import_on_the_fly`].
|
||||||
use hir::ItemInNs;
|
use hir::{ItemInNs, ModuleDef};
|
||||||
use ide_db::imports::{
|
use ide_db::imports::{
|
||||||
import_assets::{ImportAssets, ImportCandidate, LocatedImport},
|
import_assets::{ImportAssets, ImportCandidate, LocatedImport},
|
||||||
insert_use::ImportScope,
|
insert_use::ImportScope,
|
||||||
|
@ -9,6 +9,7 @@ use syntax::{AstNode, SyntaxNode, T};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::{CompletionContext, PathKind},
|
context::{CompletionContext, PathKind},
|
||||||
|
patterns::ImmediateLocation,
|
||||||
render::{render_resolution_with_import, RenderContext},
|
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::Types(_)) => true,
|
||||||
(PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
|
(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::Type, ItemInNs::Values(_)) => false,
|
||||||
|
|
||||||
(PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),
|
(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