362: Complete call parens r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2018-12-30 09:49:43 +00:00
commit 75acc25c5a
3 changed files with 44 additions and 15 deletions

10
Cargo.lock generated
View file

@ -696,7 +696,7 @@ dependencies = [
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
"test_utils 0.1.0",
]
@ -722,7 +722,7 @@ dependencies = [
"ra_syntax 0.1.0",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
"test_utils 0.1.0",
]
@ -755,7 +755,7 @@ dependencies = [
"ra_syntax 0.1.0",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
"test_utils 0.1.0",
]
@ -1059,7 +1059,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "salsa"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "git+https://github.com/matklad/salsa.git?branch=transitive-untracked#a2198f1f8a1d09894b842035a1af6b0b4c133c93"
dependencies = [
"derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1631,7 +1631,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
"checksum salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0246018bf824f282cb89c2ba9b9ef81093c563487c29ffafe20e1c129a6850"
"checksum salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)" = "<none>"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"

View file

@ -74,7 +74,7 @@ mod tests {
let z = ();
}
",
"y;x;quux",
r#"y;x;quux "quux($0)""#,
);
}
@ -92,7 +92,7 @@ mod tests {
}
}
",
"b;a;quux",
r#"b;a;quux "quux()$0""#,
);
}
@ -106,7 +106,7 @@ mod tests {
}
}
",
"x;quux",
r#"x;quux "quux()$0""#,
);
}
@ -120,7 +120,7 @@ mod tests {
<|>
}
",
"quux;Foo;Baz",
r#"quux "quux()$0";Foo;Baz"#,
);
}
@ -134,7 +134,7 @@ mod tests {
fn quux() { <|> }
}
",
"quux;Bar",
r#"quux "quux()$0";Bar"#,
);
}
@ -145,12 +145,12 @@ mod tests {
struct Foo;
fn x() -> <|>
",
"Foo;x",
r#"Foo;x "x()$0""#,
)
}
#[test]
fn dont_show_to_completions_for_shadowing() {
fn dont_show_both_completions_for_shadowing() {
check_reference_completion(
r"
fn foo() -> {
@ -161,7 +161,7 @@ mod tests {
}
}
",
"bar;foo",
r#"bar;foo "foo()$0""#,
)
}
@ -169,4 +169,24 @@ mod tests {
fn completes_self_in_methods() {
check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self")
}
#[test]
fn inserts_parens_for_function_calls() {
check_reference_completion(
r"
fn no_args() {}
fn main() { no_<|> }
",
r#"no_args "no_args()$0"
main "main()$0""#,
);
check_reference_completion(
r"
fn with_args(x: i32, y: String) {}
fn main() { with_<|> }
",
r#"main "main()$0"
with_args "with_args($0)""#,
);
}
}

View file

@ -138,9 +138,18 @@ impl Builder {
..
} => CompletionItemKind::Enum,
PerNs {
values: Some(hir::Def::Function(..)),
values: Some(hir::Def::Function(function)),
..
} => CompletionItemKind::Function,
} => {
if let Some(sig_info) = function.signature_info(db) {
if sig_info.params.is_empty() {
self.snippet = Some(format!("{}()$0", self.label));
} else {
self.snippet = Some(format!("{}($0)", self.label));
}
}
CompletionItemKind::Function
}
_ => return self,
};
self.kind = Some(kind);