aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs36
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs13
3 files changed, 44 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fa3363bd2..2fb993689 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -696,7 +696,7 @@ dependencies = [
696 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 696 "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
697 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 697 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
698 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 698 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
699 "salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 699 "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
700 "test_utils 0.1.0", 700 "test_utils 0.1.0",
701] 701]
702 702
@@ -722,7 +722,7 @@ dependencies = [
722 "ra_syntax 0.1.0", 722 "ra_syntax 0.1.0",
723 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 723 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
724 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 724 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
725 "salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 725 "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
726 "test_utils 0.1.0", 726 "test_utils 0.1.0",
727] 727]
728 728
@@ -755,7 +755,7 @@ dependencies = [
755 "ra_syntax 0.1.0", 755 "ra_syntax 0.1.0",
756 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 756 "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
757 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 757 "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
758 "salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 758 "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
759 "test_utils 0.1.0", 759 "test_utils 0.1.0",
760] 760]
761 761
@@ -1059,7 +1059,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1059[[package]] 1059[[package]]
1060name = "salsa" 1060name = "salsa"
1061version = "0.9.0" 1061version = "0.9.0"
1062source = "registry+https://github.com/rust-lang/crates.io-index" 1062source = "git+https://github.com/matklad/salsa.git?branch=transitive-untracked#a2198f1f8a1d09894b842035a1af6b0b4c133c93"
1063dependencies = [ 1063dependencies = [
1064 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", 1064 "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
1065 "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1065 "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"
1631"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" 1631"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
1632"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" 1632"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
1633"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" 1633"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
1634"checksum salsa 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0246018bf824f282cb89c2ba9b9ef81093c563487c29ffafe20e1c129a6850" 1634"checksum salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)" = "<none>"
1635"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" 1635"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
1636"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 1636"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
1637"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1637"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs
index 514fd2f88..cd98efe95 100644
--- a/crates/ra_analysis/src/completion/complete_scope.rs
+++ b/crates/ra_analysis/src/completion/complete_scope.rs
@@ -74,7 +74,7 @@ mod tests {
74 let z = (); 74 let z = ();
75 } 75 }
76 ", 76 ",
77 "y;x;quux", 77 r#"y;x;quux "quux($0)""#,
78 ); 78 );
79 } 79 }
80 80
@@ -92,7 +92,7 @@ mod tests {
92 } 92 }
93 } 93 }
94 ", 94 ",
95 "b;a;quux", 95 r#"b;a;quux "quux()$0""#,
96 ); 96 );
97 } 97 }
98 98
@@ -106,7 +106,7 @@ mod tests {
106 } 106 }
107 } 107 }
108 ", 108 ",
109 "x;quux", 109 r#"x;quux "quux()$0""#,
110 ); 110 );
111 } 111 }
112 112
@@ -120,7 +120,7 @@ mod tests {
120 <|> 120 <|>
121 } 121 }
122 ", 122 ",
123 "quux;Foo;Baz", 123 r#"quux "quux()$0";Foo;Baz"#,
124 ); 124 );
125 } 125 }
126 126
@@ -134,7 +134,7 @@ mod tests {
134 fn quux() { <|> } 134 fn quux() { <|> }
135 } 135 }
136 ", 136 ",
137 "quux;Bar", 137 r#"quux "quux()$0";Bar"#,
138 ); 138 );
139 } 139 }
140 140
@@ -145,12 +145,12 @@ mod tests {
145 struct Foo; 145 struct Foo;
146 fn x() -> <|> 146 fn x() -> <|>
147 ", 147 ",
148 "Foo;x", 148 r#"Foo;x "x()$0""#,
149 ) 149 )
150 } 150 }
151 151
152 #[test] 152 #[test]
153 fn dont_show_to_completions_for_shadowing() { 153 fn dont_show_both_completions_for_shadowing() {
154 check_reference_completion( 154 check_reference_completion(
155 r" 155 r"
156 fn foo() -> { 156 fn foo() -> {
@@ -161,7 +161,7 @@ mod tests {
161 } 161 }
162 } 162 }
163 ", 163 ",
164 "bar;foo", 164 r#"bar;foo "foo()$0""#,
165 ) 165 )
166 } 166 }
167 167
@@ -169,4 +169,24 @@ mod tests {
169 fn completes_self_in_methods() { 169 fn completes_self_in_methods() {
170 check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self") 170 check_reference_completion(r"impl S { fn foo(&self) { <|> } }", "self")
171 } 171 }
172
173 #[test]
174 fn inserts_parens_for_function_calls() {
175 check_reference_completion(
176 r"
177 fn no_args() {}
178 fn main() { no_<|> }
179 ",
180 r#"no_args "no_args()$0"
181 main "main()$0""#,
182 );
183 check_reference_completion(
184 r"
185 fn with_args(x: i32, y: String) {}
186 fn main() { with_<|> }
187 ",
188 r#"main "main()$0"
189 with_args "with_args($0)""#,
190 );
191 }
172} 192}
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index 1d294c553..b8fa39ae3 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -138,9 +138,18 @@ impl Builder {
138 .. 138 ..
139 } => CompletionItemKind::Enum, 139 } => CompletionItemKind::Enum,
140 PerNs { 140 PerNs {
141 values: Some(hir::Def::Function(..)), 141 values: Some(hir::Def::Function(function)),
142 .. 142 ..
143 } => CompletionItemKind::Function, 143 } => {
144 if let Some(sig_info) = function.signature_info(db) {
145 if sig_info.params.is_empty() {
146 self.snippet = Some(format!("{}()$0", self.label));
147 } else {
148 self.snippet = Some(format!("{}($0)", self.label));
149 }
150 }
151 CompletionItemKind::Function
152 }
144 _ => return self, 153 _ => return self,
145 }; 154 };
146 self.kind = Some(kind); 155 self.kind = Some(kind);