From e8923713c51bc3484bd98085ad620713959bbc0d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 10 Jan 2019 20:13:08 +0300 Subject: add sysroot boilerplate --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/tests/heavy_tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 9eaf46ac8..927664ffb 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -4,7 +4,7 @@ use languageserver_types::{ CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, }; use ra_lsp_server::req::{ - CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, + CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion, }; use serde_json::json; @@ -12,6 +12,45 @@ use crate::support::project; const LOG: &'static str = ""; +#[test] +fn completes_items_from_standard_library() { + let server = project( + r#" +//- Cargo.toml +[package] +name = "foo" +version = "0.0.0" + +//- src/lib.rs +use std::collections::; +"#, + ); + server.wait_for_feedback("workspace loaded"); + server.request::( + CompletionParams { + text_document: server.doc_id("src/lib.rs"), + context: None, + position: Position::new(0, 22), + }, + json!([ + { + "filterText": "self", + "insertText": "self", + "insertTextFormat": 1, + "kind": 14, + "label": "self" + }, + { + "filterText": "super", + "insertText": "super", + "insertTextFormat": 1, + "kind": 14, + "label": "super" + } + ]), + ); +} + #[test] fn test_runnables_no_project() { let server = project( -- cgit v1.2.3 From cd00158b1db9dd8565d2db08b4b0ebab9d5c00b3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 00:37:10 +0300 Subject: wire sysroot into crate graph --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 41 +++++++++-------------- crates/ra_lsp_server/tests/heavy_tests/support.rs | 13 +++---- 2 files changed, 23 insertions(+), 31 deletions(-) (limited to 'crates/ra_lsp_server/tests/heavy_tests') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 927664ffb..02d62a259 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -1,5 +1,10 @@ mod support; +use std::{ + collections::HashMap, + time::Instant, +}; + use languageserver_types::{ CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, }; @@ -14,6 +19,7 @@ const LOG: &'static str = ""; #[test] fn completes_items_from_standard_library() { + let project_start = Instant::now(); let server = project( r#" //- Cargo.toml @@ -22,33 +28,19 @@ name = "foo" version = "0.0.0" //- src/lib.rs -use std::collections::; +use std::collections::Spam; "#, ); server.wait_for_feedback("workspace loaded"); - server.request::( - CompletionParams { - text_document: server.doc_id("src/lib.rs"), - context: None, - position: Position::new(0, 22), - }, - json!([ - { - "filterText": "self", - "insertText": "self", - "insertTextFormat": 1, - "kind": 14, - "label": "self" - }, - { - "filterText": "super", - "insertText": "super", - "insertTextFormat": 1, - "kind": 14, - "label": "super" - } - ]), - ); + eprintln!("loading took {:?}", project_start.elapsed()); + let completion_start = Instant::now(); + let res = server.send_request::(CompletionParams { + text_document: server.doc_id("src/lib.rs"), + context: None, + position: Position::new(0, 23), + }); + assert!(format!("{}", res).contains("HashMap")); + eprintln!("completion took {:?}", completion_start.elapsed()); } #[test] @@ -161,7 +153,6 @@ fn test_eggs() {} ); } -use std::collections::HashMap; #[test] fn test_format_document() { 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 { R: Request, R::Params: Serialize, { - let id = self.req_id.get(); - self.req_id.set(id + 1); - let actual = self.send_request::(id, params); + let actual = self.send_request::(params); match find_mismatch(&expected_resp, &actual) { Some((expected_part, actual_part)) => panic!( "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", @@ -108,11 +106,14 @@ impl Server { } } - fn send_request(&self, id: u64, params: R::Params) -> Value + pub fn send_request(&self, params: R::Params) -> Value where R: Request, R::Params: Serialize, { + let id = self.req_id.get(); + self.req_id.set(id + 1); + let r = RawRequest::new::(id, ¶ms); self.send_request_(r) } @@ -178,7 +179,7 @@ impl Server { impl Drop for Server { fn drop(&mut self) { - self.send_request::(666, ()); + self.send_request::(()); let receiver = self.worker.take().unwrap().shutdown(); while let Some(msg) = recv_timeout(&receiver) { drop(msg); @@ -188,7 +189,7 @@ impl Drop for Server { } fn recv_timeout(receiver: &Receiver) -> Option { - let timeout = Duration::from_secs(5); + let timeout = Duration::from_secs(50); select! { recv(receiver) -> msg => msg.ok(), recv(after(timeout)) -> _ => panic!("timed out"), -- cgit v1.2.3