aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/context.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-05-27 03:34:21 +0100
committerLukas Wirth <[email protected]>2021-05-27 11:23:36 +0100
commitf41c98342476087d0a4387e7d337ce2d897e0346 (patch)
tree1c9b8e9f5a3d26d921337f6f20501b38de6fcb94 /crates/ide_completion/src/context.rs
parent30948e1ecb2fb4fe35bf9c5c1e49464d4ea1d064 (diff)
Don't complete non-macro item paths in impls and modules
Diffstat (limited to 'crates/ide_completion/src/context.rs')
-rw-r--r--crates/ide_completion/src/context.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index 66577df94..b7e116dba 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -127,6 +127,7 @@ pub(crate) struct CompletionContext<'a> {
127 127
128 no_completion_required: bool, 128 no_completion_required: bool,
129} 129}
130
130impl<'a> CompletionContext<'a> { 131impl<'a> CompletionContext<'a> {
131 pub(super) fn new( 132 pub(super) fn new(
132 db: &'a RootDatabase, 133 db: &'a RootDatabase,
@@ -281,21 +282,25 @@ impl<'a> CompletionContext<'a> {
281 self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind) 282 self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind)
282 } 283 }
283 284
284 pub(crate) fn has_impl_or_trait_parent(&self) -> bool { 285 pub(crate) fn expects_assoc_item(&self) -> bool {
285 matches!( 286 matches!(
286 self.completion_location, 287 self.completion_location,
287 Some(ImmediateLocation::Trait) | Some(ImmediateLocation::Impl) 288 Some(ImmediateLocation::Trait) | Some(ImmediateLocation::Impl)
288 ) 289 )
289 } 290 }
290 291
291 pub(crate) fn has_block_expr_parent(&self) -> bool { 292 pub(crate) fn expects_non_trait_assoc_item(&self) -> bool {
292 matches!(self.completion_location, Some(ImmediateLocation::BlockExpr)) 293 matches!(self.completion_location, Some(ImmediateLocation::Impl))
293 } 294 }
294 295
295 pub(crate) fn has_item_list_parent(&self) -> bool { 296 pub(crate) fn expects_item(&self) -> bool {
296 matches!(self.completion_location, Some(ImmediateLocation::ItemList)) 297 matches!(self.completion_location, Some(ImmediateLocation::ItemList))
297 } 298 }
298 299
300 pub(crate) fn has_block_expr_parent(&self) -> bool {
301 matches!(self.completion_location, Some(ImmediateLocation::BlockExpr))
302 }
303
299 pub(crate) fn has_ident_or_ref_pat_parent(&self) -> bool { 304 pub(crate) fn has_ident_or_ref_pat_parent(&self) -> bool {
300 matches!( 305 matches!(
301 self.completion_location, 306 self.completion_location,
@@ -303,11 +308,7 @@ impl<'a> CompletionContext<'a> {
303 ) 308 )
304 } 309 }
305 310
306 pub(crate) fn has_impl_parent(&self) -> bool { 311 pub(crate) fn expect_record_field(&self) -> bool {
307 matches!(self.completion_location, Some(ImmediateLocation::Impl))
308 }
309
310 pub(crate) fn has_field_list_parent(&self) -> bool {
311 matches!(self.completion_location, Some(ImmediateLocation::RecordFieldList)) 312 matches!(self.completion_location, Some(ImmediateLocation::RecordFieldList))
312 } 313 }
313 314
@@ -320,10 +321,10 @@ impl<'a> CompletionContext<'a> {
320 || self.record_pat_syntax.is_some() 321 || self.record_pat_syntax.is_some()
321 || self.attribute_under_caret.is_some() 322 || self.attribute_under_caret.is_some()
322 || self.mod_declaration_under_caret.is_some() 323 || self.mod_declaration_under_caret.is_some()
323 || self.has_impl_or_trait_parent()
324 } 324 }
325 325
326 fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) { 326 fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) {
327 dbg!(file_with_fake_ident);
327 let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap(); 328 let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap();
328 let syntax_element = NodeOrToken::Token(fake_ident_token); 329 let syntax_element = NodeOrToken::Token(fake_ident_token);
329 self.previous_token = previous_token(syntax_element.clone()); 330 self.previous_token = previous_token(syntax_element.clone());