6127: Correctly complete items with leading underscore r=SomeoneToIgnore a=fmease

Fixes #6091. Let me know if the test is placed into the right file or if it is even desired.

Co-authored-by: León Orell Valerian Liehr <liehr.exchange@gmx.net>
This commit is contained in:
bors[bot] 2020-10-05 21:27:18 +00:00 committed by GitHub
commit 44587d1bfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -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(

View file

@ -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 {