From 32864e3b499426aa6a49402f07570c09ec5fcde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sat, 3 Oct 2020 03:00:09 +0200 Subject: Correctly complete items with leading underscore --- .../ide/src/completion/complete_unqualified_path.rs | 20 ++++++++++++++++++++ crates/ide/src/completion/completion_context.rs | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/completion/complete_unqualified_path.rs b/crates/ide/src/completion/complete_unqualified_path.rs index 2010d9a2f..8b6757195 100644 --- a/crates/ide/src/completion/complete_unqualified_path.rs +++ b/crates/ide/src/completion/complete_unqualified_path.rs @@ -267,6 +267,26 @@ fn quux() { <|> } ); } + /// Regression test for issue #6091. + #[test] + fn correctly_completes_module_items_prefixed_with_underscore() { + check_edit( + "_alpha", + r#" +fn main() { + _<|> +} +fn _alpha() {} +"#, + r#" +fn main() { + _alpha()$0 +} +fn _alpha() {} +"#, + ) + } + #[test] fn completes_extern_prelude() { check( diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs index 101be8eb5..8dea8a4bf 100644 --- a/crates/ide/src/completion/completion_context.rs +++ b/crates/ide/src/completion/completion_context.rs @@ -221,10 +221,11 @@ impl<'a> CompletionContext<'a> { Some(ctx) } - // The range of the identifier that is being completed. + /// The range of the identifier that is being completed. pub(crate) fn source_range(&self) -> TextRange { // check kind of macro-expanded token, but use range of original token - if self.token.kind() == IDENT || self.token.kind().is_keyword() { + let kind = self.token.kind(); + if kind == IDENT || kind == UNDERSCORE || kind.is_keyword() { mark::hit!(completes_if_prefix_is_keyword); self.original_token.text_range() } else { -- cgit v1.2.3