diff options
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r-- | crates/ide_completion/src/completions/qualified_path.rs | 18 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 8 | ||||
-rw-r--r-- | crates/ide_completion/src/context.rs | 31 | ||||
-rw-r--r-- | crates/ide_completion/src/render/builder_ext.rs | 2 |
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 88f4d940d..f5dbd203b 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 8ea5a2d5b..81c4fb305 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -74,9 +74,11 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
74 | // Don't suggest attribute macros and derives. | 74 | // Don't suggest attribute macros and derives. |
75 | ScopeDef::MacroDef(mac) => mac.is_fn_like(), | 75 | ScopeDef::MacroDef(mac) => mac.is_fn_like(), |
76 | // no values in type places | 76 | // no values in type places |
77 | ScopeDef::ModuleDef(hir::ModuleDef::Function(_)) | 77 | ScopeDef::ModuleDef( |
78 | | ScopeDef::ModuleDef(hir::ModuleDef::Variant(_)) | 78 | hir::ModuleDef::Function(_) |
79 | | ScopeDef::ModuleDef(hir::ModuleDef::Static(_)) | 79 | | hir::ModuleDef::Variant(_) |
80 | | hir::ModuleDef::Static(_), | ||
81 | ) | ||
80 | | ScopeDef::Local(_) => !ctx.expects_type(), | 82 | | ScopeDef::Local(_) => !ctx.expects_type(), |
81 | // unless its a constant in a generic arg list position | 83 | // unless its a constant in a generic arg list position |
82 | ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) | 84 | ScopeDef::ModuleDef(hir::ModuleDef::Const(_)) |
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index d7a7e9cca..98fb36042 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 | ||
@@ -322,14 +321,16 @@ impl<'a> CompletionContext<'a> { | |||
322 | || self.previous_token_is(T![unsafe]) | 321 | || self.previous_token_is(T![unsafe]) |
323 | || matches!( | 322 | || matches!( |
324 | self.prev_sibling, | 323 | self.prev_sibling, |
325 | Some(ImmediatePrevSibling::Attribute) | Some(ImmediatePrevSibling::Visibility) | 324 | Some(ImmediatePrevSibling::Attribute | ImmediatePrevSibling::Visibility) |
326 | ) | 325 | ) |
327 | || matches!( | 326 | || matches!( |
328 | self.completion_location, | 327 | self.completion_location, |
329 | Some(ImmediateLocation::Attribute(_)) | 328 | Some( |
330 | | Some(ImmediateLocation::ModDeclaration(_)) | 329 | ImmediateLocation::Attribute(_) |
331 | | Some(ImmediateLocation::RecordPat(_)) | 330 | | ImmediateLocation::ModDeclaration(_) |
332 | | Some(ImmediateLocation::RecordExpr(_)) | 331 | | ImmediateLocation::RecordPat(_) |
332 | | ImmediateLocation::RecordExpr(_) | ||
333 | ) | ||
333 | ) | 334 | ) |
334 | } | 335 | } |
335 | 336 | ||
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, .. }) |