aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-17 16:37:14 +0100
committerLukas Wirth <[email protected]>2021-06-17 16:37:14 +0100
commit95c8c65139c10e4de44367fead8dff88511e6d46 (patch)
tree4326d46ee282c133123f3a08aaee7d640f007050 /crates/ide_completion
parentc82a9141abe6b6cbf5b55710dc8a315a3839081b (diff)
Nest all the or-patterns!
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs18
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs8
-rw-r--r--crates/ide_completion/src/context.rs31
-rw-r--r--crates/ide_completion/src/render/builder_ext.rs2
4 files changed, 34 insertions, 25 deletions
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
65 // Don't suggest attribute macros and derives. 65 // Don't suggest attribute macros and derives.
66 hir::ScopeDef::MacroDef(mac) => mac.is_fn_like(), 66 hir::ScopeDef::MacroDef(mac) => mac.is_fn_like(),
67 // no values in type places 67 // no values in type places
68 hir::ScopeDef::ModuleDef(hir::ModuleDef::Function(_)) 68 hir::ScopeDef::ModuleDef(
69 | hir::ScopeDef::ModuleDef(hir::ModuleDef::Variant(_)) 69 hir::ModuleDef::Function(_)
70 | hir::ScopeDef::ModuleDef(hir::ModuleDef::Static(_)) 70 | hir::ModuleDef::Variant(_)
71 | hir::ModuleDef::Static(_),
72 )
71 | hir::ScopeDef::Local(_) => !ctx.expects_type(), 73 | hir::ScopeDef::Local(_) => !ctx.expects_type(),
72 // unless its a constant in a generic arg list position 74 // unless its a constant in a generic arg list position
73 hir::ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) => { 75 hir::ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) => {
@@ -81,9 +83,13 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
81 } 83 }
82 } 84 }
83 } 85 }
84 hir::PathResolution::Def(def @ hir::ModuleDef::Adt(_)) 86 hir::PathResolution::Def(
85 | hir::PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) 87 def
86 | hir::PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => { 88 @
89 (hir::ModuleDef::Adt(_)
90 | hir::ModuleDef::TypeAlias(_)
91 | hir::ModuleDef::BuiltinType(_)),
92 ) => {
87 if let hir::ModuleDef::Adt(hir::Adt::Enum(e)) = def { 93 if let hir::ModuleDef::Adt(hir::Adt::Enum(e)) = def {
88 add_enum_variants(acc, ctx, e); 94 add_enum_variants(acc, ctx, e);
89 } 95 }
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
71 // Don't suggest attribute macros and derives. 71 // Don't suggest attribute macros and derives.
72 ScopeDef::MacroDef(mac) => mac.is_fn_like(), 72 ScopeDef::MacroDef(mac) => mac.is_fn_like(),
73 // no values in type places 73 // no values in type places
74 ScopeDef::ModuleDef(hir::ModuleDef::Function(_)) 74 ScopeDef::ModuleDef(
75 | ScopeDef::ModuleDef(hir::ModuleDef::Variant(_)) 75 hir::ModuleDef::Function(_)
76 | ScopeDef::ModuleDef(hir::ModuleDef::Static(_)) 76 | hir::ModuleDef::Variant(_)
77 | hir::ModuleDef::Static(_),
78 )
77 | ScopeDef::Local(_) => !ctx.expects_type(), 79 | ScopeDef::Local(_) => !ctx.expects_type(),
78 // unless its a constant in a generic arg list position 80 // unless its a constant in a generic arg list position
79 ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) 81 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> {
242 } 242 }
243 243
244 pub(crate) fn expects_assoc_item(&self) -> bool { 244 pub(crate) fn expects_assoc_item(&self) -> bool {
245 matches!( 245 matches!(self.completion_location, Some(ImmediateLocation::Trait | ImmediateLocation::Impl))
246 self.completion_location,
247 Some(ImmediateLocation::Trait) | Some(ImmediateLocation::Impl)
248 )
249 } 246 }
250 247
251 pub(crate) fn has_dot_receiver(&self) -> bool { 248 pub(crate) fn has_dot_receiver(&self) -> bool {
252 matches!( 249 matches!(
253 &self.completion_location, 250 &self.completion_location,
254 Some(ImmediateLocation::FieldAccess { receiver, .. }) | Some(ImmediateLocation::MethodCall { receiver,.. }) 251 Some(ImmediateLocation::FieldAccess { receiver, .. } | ImmediateLocation::MethodCall { receiver,.. })
255 if receiver.is_some() 252 if receiver.is_some()
256 ) 253 )
257 } 254 }
258 255
259 pub(crate) fn dot_receiver(&self) -> Option<&ast::Expr> { 256 pub(crate) fn dot_receiver(&self) -> Option<&ast::Expr> {
260 match &self.completion_location { 257 match &self.completion_location {
261 Some(ImmediateLocation::MethodCall { receiver, .. }) 258 Some(
262 | Some(ImmediateLocation::FieldAccess { receiver, .. }) => receiver.as_ref(), 259 ImmediateLocation::MethodCall { receiver, .. }
260 | ImmediateLocation::FieldAccess { receiver, .. },
261 ) => receiver.as_ref(),
263 _ => None, 262 _ => None,
264 } 263 }
265 } 264 }
@@ -283,7 +282,7 @@ impl<'a> CompletionContext<'a> {
283 pub(crate) fn expects_ident_pat_or_ref_expr(&self) -> bool { 282 pub(crate) fn expects_ident_pat_or_ref_expr(&self) -> bool {
284 matches!( 283 matches!(
285 self.completion_location, 284 self.completion_location,
286 Some(ImmediateLocation::IdentPat) | Some(ImmediateLocation::RefExpr) 285 Some(ImmediateLocation::IdentPat | ImmediateLocation::RefExpr)
287 ) 286 )
288 } 287 }
289 288
@@ -294,14 +293,14 @@ impl<'a> CompletionContext<'a> {
294 pub(crate) fn in_use_tree(&self) -> bool { 293 pub(crate) fn in_use_tree(&self) -> bool {
295 matches!( 294 matches!(
296 self.completion_location, 295 self.completion_location,
297 Some(ImmediateLocation::Use) | Some(ImmediateLocation::UseTree) 296 Some(ImmediateLocation::Use | ImmediateLocation::UseTree)
298 ) 297 )
299 } 298 }
300 299
301 pub(crate) fn has_impl_or_trait_prev_sibling(&self) -> bool { 300 pub(crate) fn has_impl_or_trait_prev_sibling(&self) -> bool {
302 matches!( 301 matches!(
303 self.prev_sibling, 302 self.prev_sibling,
304 Some(ImmediatePrevSibling::ImplDefType) | Some(ImmediatePrevSibling::TraitDefName) 303 Some(ImmediatePrevSibling::ImplDefType | ImmediatePrevSibling::TraitDefName)
305 ) 304 )
306 } 305 }
307 306
@@ -318,14 +317,16 @@ impl<'a> CompletionContext<'a> {
318 || self.previous_token_is(T![unsafe]) 317 || self.previous_token_is(T![unsafe])
319 || matches!( 318 || matches!(
320 self.prev_sibling, 319 self.prev_sibling,
321 Some(ImmediatePrevSibling::Attribute) | Some(ImmediatePrevSibling::Visibility) 320 Some(ImmediatePrevSibling::Attribute | ImmediatePrevSibling::Visibility)
322 ) 321 )
323 || matches!( 322 || matches!(
324 self.completion_location, 323 self.completion_location,
325 Some(ImmediateLocation::Attribute(_)) 324 Some(
326 | Some(ImmediateLocation::ModDeclaration(_)) 325 ImmediateLocation::Attribute(_)
327 | Some(ImmediateLocation::RecordPat(_)) 326 | ImmediateLocation::ModDeclaration(_)
328 | Some(ImmediateLocation::RecordExpr(_)) 327 | ImmediateLocation::RecordPat(_)
328 | ImmediateLocation::RecordExpr(_)
329 )
329 ) 330 )
330 } 331 }
331 332
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 {
32 cov_mark::hit!(no_parens_in_use_item); 32 cov_mark::hit!(no_parens_in_use_item);
33 return false; 33 return false;
34 } 34 }
35 if matches!(ctx.path_call_kind(), Some(CallKind::Expr) | Some(CallKind::Pat)) 35 if matches!(ctx.path_call_kind(), Some(CallKind::Expr | CallKind::Pat))
36 | matches!( 36 | matches!(
37 ctx.completion_location, 37 ctx.completion_location,
38 Some(ImmediateLocation::MethodCall { has_parens: true, .. }) 38 Some(ImmediateLocation::MethodCall { has_parens: true, .. })