aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/context.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-16 20:53:43 +0100
committerGitHub <[email protected]>2021-06-16 20:53:43 +0100
commitd6b8af44829521a9f925c4d87599efa3fef38edc (patch)
tree47119538effd381ecd8e15d422103512f2b47406 /crates/ide_completion/src/context.rs
parentf38770cd2606148bfe764351849ea7ebea45132c (diff)
parentaa644b55859c6b5c6695a5d4fb35d1b6efbbebcc (diff)
Merge #9301
9301: internal: Start refactoring ide_completion tests r=Veykril a=Veykril Our current completion test infra resovles around usually just checking a specific `CompletionKind` which is suboptimal. We only see what we want to see in tests with this causing us to miss a lot of incorrect completions we are doing. Instead we should test for different cursor locations for all kinds(sans the magic kind maybe? not sure yet). This way we will also see potential duplicate completions that merely different in their kind. Also since most completion submodules complete things in tests of other modules due to the tests overlapping it makes more sense to group these tests differently which implies moving them to a new module. Exceptions for this might be stuff like attribute completion as these cannot currently interfere. I only wrote a few tests to check for completions in `ItemList` position so far and I already found a few incorrect/irrelevant completions as these haven't been tested properly due to them being hidden by the `CompletionKind` filtering. I think `CompletionKind` doesn't really seem to be beneficial to me as to I can't think of a occasion where we would want to only check a specific completion kind. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/context.rs')
-rw-r--r--crates/ide_completion/src/context.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index a8437d81c..121909857 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -302,18 +302,28 @@ impl<'a> CompletionContext<'a> {
302 ) 302 )
303 } 303 }
304 304
305 pub(crate) fn has_visibility_prev_sibling(&self) -> bool {
306 matches!(self.prev_sibling, Some(ImmediatePrevSibling::Visibility))
307 }
308
305 pub(crate) fn after_if(&self) -> bool { 309 pub(crate) fn after_if(&self) -> bool {
306 matches!(self.prev_sibling, Some(ImmediatePrevSibling::IfExpr)) 310 matches!(self.prev_sibling, Some(ImmediatePrevSibling::IfExpr))
307 } 311 }
308 312
309 pub(crate) fn is_path_disallowed(&self) -> bool { 313 pub(crate) fn is_path_disallowed(&self) -> bool {
310 matches!( 314 self.attribute_under_caret.is_some()
311 self.completion_location, 315 || self.previous_token_is(T![unsafe])
312 Some(ImmediateLocation::Attribute(_)) 316 || matches!(
313 | Some(ImmediateLocation::ModDeclaration(_)) 317 self.prev_sibling,
314 | Some(ImmediateLocation::RecordPat(_)) 318 Some(ImmediatePrevSibling::Attribute) | Some(ImmediatePrevSibling::Visibility)
315 | Some(ImmediateLocation::RecordExpr(_)) 319 )
316 ) || self.attribute_under_caret.is_some() 320 || matches!(
321 self.completion_location,
322 Some(ImmediateLocation::Attribute(_))
323 | Some(ImmediateLocation::ModDeclaration(_))
324 | Some(ImmediateLocation::RecordPat(_))
325 | Some(ImmediateLocation::RecordExpr(_))
326 )
317 } 327 }
318 328
319 pub(crate) fn expects_expression(&self) -> bool { 329 pub(crate) fn expects_expression(&self) -> bool {
@@ -685,7 +695,7 @@ mod tests {
685 use expect_test::{expect, Expect}; 695 use expect_test::{expect, Expect};
686 use hir::HirDisplay; 696 use hir::HirDisplay;
687 697
688 use crate::test_utils::{position, TEST_CONFIG}; 698 use crate::tests::{position, TEST_CONFIG};
689 699
690 use super::CompletionContext; 700 use super::CompletionContext;
691 701