diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-10 21:57:07 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-10 21:57:07 +0000 |
commit | 28559b7dd2e2c101c4b7f2c9bb207b3af94f6e16 (patch) | |
tree | 7bee8dee5216b7eb459edaa0aad54f04dcef3f97 /crates/ra_lsp_server/tests/heavy_tests | |
parent | b6bc55f542c88b1b0789435219f9dbf38c110f47 (diff) | |
parent | 6b7699d187d51e8a26ba1a18a217a77dd236458f (diff) |
Merge #489
489: support std r=matklad a=matklad
closes #465
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/tests/heavy_tests')
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 34 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 13 |
2 files changed, 39 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 9eaf46ac8..02d62a259 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs | |||
@@ -1,10 +1,15 @@ | |||
1 | mod support; | 1 | mod support; |
2 | 2 | ||
3 | use std::{ | ||
4 | collections::HashMap, | ||
5 | time::Instant, | ||
6 | }; | ||
7 | |||
3 | use languageserver_types::{ | 8 | use languageserver_types::{ |
4 | CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, | 9 | CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, |
5 | }; | 10 | }; |
6 | use ra_lsp_server::req::{ | 11 | use ra_lsp_server::req::{ |
7 | CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, | 12 | CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion, |
8 | }; | 13 | }; |
9 | use serde_json::json; | 14 | use serde_json::json; |
10 | 15 | ||
@@ -13,6 +18,32 @@ use crate::support::project; | |||
13 | const LOG: &'static str = ""; | 18 | const LOG: &'static str = ""; |
14 | 19 | ||
15 | #[test] | 20 | #[test] |
21 | fn completes_items_from_standard_library() { | ||
22 | let project_start = Instant::now(); | ||
23 | let server = project( | ||
24 | r#" | ||
25 | //- Cargo.toml | ||
26 | [package] | ||
27 | name = "foo" | ||
28 | version = "0.0.0" | ||
29 | |||
30 | //- src/lib.rs | ||
31 | use std::collections::Spam; | ||
32 | "#, | ||
33 | ); | ||
34 | server.wait_for_feedback("workspace loaded"); | ||
35 | eprintln!("loading took {:?}", project_start.elapsed()); | ||
36 | let completion_start = Instant::now(); | ||
37 | let res = server.send_request::<Completion>(CompletionParams { | ||
38 | text_document: server.doc_id("src/lib.rs"), | ||
39 | context: None, | ||
40 | position: Position::new(0, 23), | ||
41 | }); | ||
42 | assert!(format!("{}", res).contains("HashMap")); | ||
43 | eprintln!("completion took {:?}", completion_start.elapsed()); | ||
44 | } | ||
45 | |||
46 | #[test] | ||
16 | fn test_runnables_no_project() { | 47 | fn test_runnables_no_project() { |
17 | let server = project( | 48 | let server = project( |
18 | r" | 49 | r" |
@@ -122,7 +153,6 @@ fn test_eggs() {} | |||
122 | ); | 153 | ); |
123 | } | 154 | } |
124 | 155 | ||
125 | use std::collections::HashMap; | ||
126 | #[test] | 156 | #[test] |
127 | fn test_format_document() { | 157 | fn test_format_document() { |
128 | let server = project( | 158 | let server = project( |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 7db168b0f..46107b6b6 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs | |||
@@ -93,9 +93,7 @@ impl Server { | |||
93 | R: Request, | 93 | R: Request, |
94 | R::Params: Serialize, | 94 | R::Params: Serialize, |
95 | { | 95 | { |
96 | let id = self.req_id.get(); | 96 | let actual = self.send_request::<R>(params); |
97 | self.req_id.set(id + 1); | ||
98 | let actual = self.send_request::<R>(id, params); | ||
99 | match find_mismatch(&expected_resp, &actual) { | 97 | match find_mismatch(&expected_resp, &actual) { |
100 | Some((expected_part, actual_part)) => panic!( | 98 | Some((expected_part, actual_part)) => panic!( |
101 | "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", | 99 | "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", |
@@ -108,11 +106,14 @@ impl Server { | |||
108 | } | 106 | } |
109 | } | 107 | } |
110 | 108 | ||
111 | fn send_request<R>(&self, id: u64, params: R::Params) -> Value | 109 | pub fn send_request<R>(&self, params: R::Params) -> Value |
112 | where | 110 | where |
113 | R: Request, | 111 | R: Request, |
114 | R::Params: Serialize, | 112 | R::Params: Serialize, |
115 | { | 113 | { |
114 | let id = self.req_id.get(); | ||
115 | self.req_id.set(id + 1); | ||
116 | |||
116 | let r = RawRequest::new::<R>(id, ¶ms); | 117 | let r = RawRequest::new::<R>(id, ¶ms); |
117 | self.send_request_(r) | 118 | self.send_request_(r) |
118 | } | 119 | } |
@@ -178,7 +179,7 @@ impl Server { | |||
178 | 179 | ||
179 | impl Drop for Server { | 180 | impl Drop for Server { |
180 | fn drop(&mut self) { | 181 | fn drop(&mut self) { |
181 | self.send_request::<Shutdown>(666, ()); | 182 | self.send_request::<Shutdown>(()); |
182 | let receiver = self.worker.take().unwrap().shutdown(); | 183 | let receiver = self.worker.take().unwrap().shutdown(); |
183 | while let Some(msg) = recv_timeout(&receiver) { | 184 | while let Some(msg) = recv_timeout(&receiver) { |
184 | drop(msg); | 185 | drop(msg); |
@@ -188,7 +189,7 @@ impl Drop for Server { | |||
188 | } | 189 | } |
189 | 190 | ||
190 | fn recv_timeout(receiver: &Receiver<RawMessage>) -> Option<RawMessage> { | 191 | fn recv_timeout(receiver: &Receiver<RawMessage>) -> Option<RawMessage> { |
191 | let timeout = Duration::from_secs(5); | 192 | let timeout = Duration::from_secs(50); |
192 | select! { | 193 | select! { |
193 | recv(receiver) -> msg => msg.ok(), | 194 | recv(receiver) -> msg => msg.ok(), |
194 | recv(after(timeout)) -> _ => panic!("timed out"), | 195 | recv(after(timeout)) -> _ => panic!("timed out"), |