From 95c8c65139c10e4de44367fead8dff88511e6d46 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 17 Jun 2021 17:37:14 +0200 Subject: Nest all the or-patterns! --- .../src/completions/qualified_path.rs | 18 ++++++++----- .../src/completions/unqualified_path.rs | 8 +++--- crates/ide_completion/src/context.rs | 31 +++++++++++----------- crates/ide_completion/src/render/builder_ext.rs | 2 +- 4 files changed, 34 insertions(+), 25 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index 0597879ac..da3385bdc 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -65,9 +65,11 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon // Don't suggest attribute macros and derives. hir::ScopeDef::MacroDef(mac) => mac.is_fn_like(), // no values in type places - hir::ScopeDef::ModuleDef(hir::ModuleDef::Function(_)) - | hir::ScopeDef::ModuleDef(hir::ModuleDef::Variant(_)) - | hir::ScopeDef::ModuleDef(hir::ModuleDef::Static(_)) + hir::ScopeDef::ModuleDef( + hir::ModuleDef::Function(_) + | hir::ModuleDef::Variant(_) + | hir::ModuleDef::Static(_), + ) | hir::ScopeDef::Local(_) => !ctx.expects_type(), // unless its a constant in a generic arg list position hir::ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) => { @@ -81,9 +83,13 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon } } } - hir::PathResolution::Def(def @ hir::ModuleDef::Adt(_)) - | hir::PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) - | hir::PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => { + hir::PathResolution::Def( + def + @ + (hir::ModuleDef::Adt(_) + | hir::ModuleDef::TypeAlias(_) + | hir::ModuleDef::BuiltinType(_)), + ) => { if let hir::ModuleDef::Adt(hir::Adt::Enum(e)) = def { add_enum_variants(acc, ctx, e); } diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 6f96eceb9..77c6d706f 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -71,9 +71,11 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC // Don't suggest attribute macros and derives. ScopeDef::MacroDef(mac) => mac.is_fn_like(), // no values in type places - ScopeDef::ModuleDef(hir::ModuleDef::Function(_)) - | ScopeDef::ModuleDef(hir::ModuleDef::Variant(_)) - | ScopeDef::ModuleDef(hir::ModuleDef::Static(_)) + ScopeDef::ModuleDef( + hir::ModuleDef::Function(_) + | hir::ModuleDef::Variant(_) + | hir::ModuleDef::Static(_), + ) | ScopeDef::Local(_) => !ctx.expects_type(), // unless its a constant in a generic arg list position ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 240cac1de..84b2bcf9f 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -242,24 +242,23 @@ impl<'a> CompletionContext<'a> { } pub(crate) fn expects_assoc_item(&self) -> bool { - matches!( - self.completion_location, - Some(ImmediateLocation::Trait) | Some(ImmediateLocation::Impl) - ) + matches!(self.completion_location, Some(ImmediateLocation::Trait | ImmediateLocation::Impl)) } pub(crate) fn has_dot_receiver(&self) -> bool { matches!( &self.completion_location, - Some(ImmediateLocation::FieldAccess { receiver, .. }) | Some(ImmediateLocation::MethodCall { receiver,.. }) + Some(ImmediateLocation::FieldAccess { receiver, .. } | ImmediateLocation::MethodCall { receiver,.. }) if receiver.is_some() ) } pub(crate) fn dot_receiver(&self) -> Option<&ast::Expr> { match &self.completion_location { - Some(ImmediateLocation::MethodCall { receiver, .. }) - | Some(ImmediateLocation::FieldAccess { receiver, .. }) => receiver.as_ref(), + Some( + ImmediateLocation::MethodCall { receiver, .. } + | ImmediateLocation::FieldAccess { receiver, .. }, + ) => receiver.as_ref(), _ => None, } } @@ -283,7 +282,7 @@ impl<'a> CompletionContext<'a> { pub(crate) fn expects_ident_pat_or_ref_expr(&self) -> bool { matches!( self.completion_location, - Some(ImmediateLocation::IdentPat) | Some(ImmediateLocation::RefExpr) + Some(ImmediateLocation::IdentPat | ImmediateLocation::RefExpr) ) } @@ -294,14 +293,14 @@ impl<'a> CompletionContext<'a> { pub(crate) fn in_use_tree(&self) -> bool { matches!( self.completion_location, - Some(ImmediateLocation::Use) | Some(ImmediateLocation::UseTree) + Some(ImmediateLocation::Use | ImmediateLocation::UseTree) ) } pub(crate) fn has_impl_or_trait_prev_sibling(&self) -> bool { matches!( self.prev_sibling, - Some(ImmediatePrevSibling::ImplDefType) | Some(ImmediatePrevSibling::TraitDefName) + Some(ImmediatePrevSibling::ImplDefType | ImmediatePrevSibling::TraitDefName) ) } @@ -318,14 +317,16 @@ impl<'a> CompletionContext<'a> { || self.previous_token_is(T![unsafe]) || matches!( self.prev_sibling, - Some(ImmediatePrevSibling::Attribute) | Some(ImmediatePrevSibling::Visibility) + Some(ImmediatePrevSibling::Attribute | ImmediatePrevSibling::Visibility) ) || matches!( self.completion_location, - Some(ImmediateLocation::Attribute(_)) - | Some(ImmediateLocation::ModDeclaration(_)) - | Some(ImmediateLocation::RecordPat(_)) - | Some(ImmediateLocation::RecordExpr(_)) + Some( + ImmediateLocation::Attribute(_) + | ImmediateLocation::ModDeclaration(_) + | ImmediateLocation::RecordPat(_) + | ImmediateLocation::RecordExpr(_) + ) ) } diff --git a/crates/ide_completion/src/render/builder_ext.rs b/crates/ide_completion/src/render/builder_ext.rs index 749dfc665..33d3a5ee1 100644 --- a/crates/ide_completion/src/render/builder_ext.rs +++ b/crates/ide_completion/src/render/builder_ext.rs @@ -32,7 +32,7 @@ impl Builder { cov_mark::hit!(no_parens_in_use_item); return false; } - if matches!(ctx.path_call_kind(), Some(CallKind::Expr) | Some(CallKind::Pat)) + if matches!(ctx.path_call_kind(), Some(CallKind::Expr | CallKind::Pat)) | matches!( ctx.completion_location, Some(ImmediateLocation::MethodCall { has_parens: true, .. }) -- cgit v1.2.3