Unnamed repository; edit this file 'description' to name the repository.
Correct has_ref detection
Wang Ruochen 2022-01-07
parent 638cc3e · commit 3a57f70
-rw-r--r--crates/ide_completion/src/context.rs16
-rw-r--r--crates/ide_completion/src/render.rs16
2 files changed, 31 insertions, 1 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs
index c6af285e86..a21de23d1d 100644
--- a/crates/ide_completion/src/context.rs
+++ b/crates/ide_completion/src/context.rs
@@ -876,7 +876,7 @@ fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<(ast::Path, bool)> {
fn has_ref(token: &SyntaxToken) -> bool {
let mut token = token.clone();
- for skip in [WHITESPACE, IDENT, T![mut]] {
+ for skip in [IDENT, WHITESPACE, T![mut]] {
if token.kind() == skip {
token = match token.prev_token() {
Some(it) => it,
@@ -997,6 +997,20 @@ fn bar(x: &mut u32) {}
);
check_expected_type_and_name(
r#"
+fn foo() { bar(& c$0); }
+fn bar(x: &u32) {}
+ "#,
+ expect![[r#"ty: u32, name: x"#]],
+ );
+ check_expected_type_and_name(
+ r#"
+fn foo() { bar(&mut c$0); }
+fn bar(x: &mut u32) {}
+"#,
+ expect![[r#"ty: u32, name: x"#]],
+ );
+ check_expected_type_and_name(
+ r#"
fn foo() { bar(&c$0); }
fn bar(x: &u32) {}
"#,
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 4b4fbb3ed9..d7184e406e 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -1156,6 +1156,22 @@ fn main() {
fn foo(…) []
"#]],
);
+ check_relevance(
+ r#"
+struct S;
+fn foo(s: &mut S) {}
+fn main() {
+ let mut ssss = S;
+ foo(&mut s$0);
+}
+ "#,
+ expect![[r#"
+ lc ssss [type+local]
+ st S []
+ fn main() []
+ fn foo(…) []
+ "#]],
+ );
}
#[test]