diff --git a/crates/ide/src/completion/complete_unqualified_path.rs b/crates/ide/src/completion/complete_unqualified_path.rs index 2010d9a2fdb..8b67571950c 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 101be8eb54b..8dea8a4bf09 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 {