Skip to content

Commit 32864e3

Browse files
committed
Correctly complete items with leading underscore
1 parent 03dcf51 commit 32864e3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

crates/ide/src/completion/complete_unqualified_path.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,26 @@ fn quux() { <|> }
267267
);
268268
}
269269

270+
/// Regression test for issue #6091.
271+
#[test]
272+
fn correctly_completes_module_items_prefixed_with_underscore() {
273+
check_edit(
274+
"_alpha",
275+
r#"
276+
fn main() {
277+
_<|>
278+
}
279+
fn _alpha() {}
280+
"#,
281+
r#"
282+
fn main() {
283+
_alpha()$0
284+
}
285+
fn _alpha() {}
286+
"#,
287+
)
288+
}
289+
270290
#[test]
271291
fn completes_extern_prelude() {
272292
check(

crates/ide/src/completion/completion_context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ impl<'a> CompletionContext<'a> {
221221
Some(ctx)
222222
}
223223

224-
// The range of the identifier that is being completed.
224+
/// The range of the identifier that is being completed.
225225
pub(crate) fn source_range(&self) -> TextRange {
226226
// check kind of macro-expanded token, but use range of original token
227-
if self.token.kind() == IDENT || self.token.kind().is_keyword() {
227+
let kind = self.token.kind();
228+
if kind == IDENT || kind == UNDERSCORE || kind.is_keyword() {
228229
mark::hit!(completes_if_prefix_is_keyword);
229230
self.original_token.text_range()
230231
} else {

0 commit comments

Comments
 (0)