aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-27 12:20:11 +0100
committerAleksey Kladov <[email protected]>2019-05-27 12:20:11 +0100
commitcf214ac4e76413bdfd2676edf834505306edc9c6 (patch)
treef2de6c2d2393effe847fa4a2151587faf2b42bdc /crates
parentce040aa90755f2294b8db39a5255d75927f2bb95 (diff)
enable profiling in tests
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs70
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs14
2 files changed, 83 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index 6f37a980d..3c2dc08ed 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -6,10 +6,11 @@ use std::{
6}; 6};
7 7
8use lsp_types::{ 8use lsp_types::{
9 CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, 9 CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, DidOpenTextDocumentParams, TextDocumentItem, TextDocumentPositionParams
10}; 10};
11use ra_lsp_server::req::{ 11use ra_lsp_server::req::{
12 CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion, 12 CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion,
13 DidOpenTextDocument, OnEnter,
13}; 14};
14use serde_json::json; 15use serde_json::json;
15use tempfile::TempDir; 16use tempfile::TempDir;
@@ -17,6 +18,7 @@ use tempfile::TempDir;
17use crate::support::{project, Project}; 18use crate::support::{project, Project};
18 19
19const LOG: &'static str = ""; 20const LOG: &'static str = "";
21const PROFILE: &'static str = "*@3>100";
20 22
21#[test] 23#[test]
22fn completes_items_from_standard_library() { 24fn completes_items_from_standard_library() {
@@ -341,3 +343,69 @@ fn main() {{}}
341 json!([]), 343 json!([]),
342 ); 344 );
343} 345}
346
347#[test]
348fn diagnostics_dont_block_typing() {
349 let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect();
350 let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
351 let server = project(&format!(
352 r#"
353//- Cargo.toml
354[package]
355name = "foo"
356version = "0.0.0"
357
358//- src/lib.rs
359{}
360
361{}
362
363fn main() {{}}
364"#,
365 librs, libs
366 ));
367 server.wait_until_workspace_is_loaded();
368 eprintln!("workspace loaded");
369 for i in 0..10 {
370 server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
371 text_document: TextDocumentItem {
372 uri: server.doc_id(&format!("src/m{}.rs", i)).uri,
373 language_id: "rust".to_string(),
374 version: 0,
375 text: "/// Docs\nfn foo() {}".to_string(),
376 },
377 });
378 }
379 eprintln!("docs opened");
380 let start = std::time::Instant::now();
381 server.request::<OnEnter>(
382 TextDocumentPositionParams {
383 text_document: server.doc_id("src/m0.rs"),
384 position: Position { line: 0, character: 5 },
385 },
386 json!({
387 "cursorPosition": {
388 "position": { "character": 4, "line": 1 },
389 "textDocument": { "uri": "file:///[..]src/m0.rs" }
390 },
391 "label": "on enter",
392 "workspaceEdit": {
393 "documentChanges": [
394 {
395 "edits": [
396 {
397 "newText": "\n/// ",
398 "range": {
399 "end": { "character": 5, "line": 0 },
400 "start": { "character": 5, "line": 0 }
401 }
402 }
403 ],
404 "textDocument": { "uri": "file:///[..]src/m0.rs", "version": null }
405 }
406 ]
407 }
408 }),
409 );
410 eprintln!("handled: {:?}", start.elapsed());
411}
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index d68182174..729067395 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -52,6 +52,11 @@ impl<'a> Project<'a> {
52 static INIT: Once = Once::new(); 52 static INIT: Once = Once::new();
53 INIT.call_once(|| { 53 INIT.call_once(|| {
54 let _ = Logger::with_env_or_str(crate::LOG).start().unwrap(); 54 let _ = Logger::with_env_or_str(crate::LOG).start().unwrap();
55 ra_prof::set_filter(if crate::PROFILE.is_empty() {
56 ra_prof::Filter::disabled()
57 } else {
58 ra_prof::Filter::from_spec(&crate::PROFILE)
59 });
55 }); 60 });
56 61
57 let mut paths = vec![]; 62 let mut paths = vec![];
@@ -121,6 +126,15 @@ impl Server {
121 TextDocumentIdentifier { uri: Url::from_file_path(path).unwrap() } 126 TextDocumentIdentifier { uri: Url::from_file_path(path).unwrap() }
122 } 127 }
123 128
129 pub fn notification<N>(&self, params: N::Params)
130 where
131 N: Notification,
132 N::Params: Serialize,
133 {
134 let r = RawNotification::new::<N>(&params);
135 self.send_notification(r)
136 }
137
124 pub fn request<R>(&self, params: R::Params, expected_resp: Value) 138 pub fn request<R>(&self, params: R::Params, expected_resp: Value)
125 where 139 where
126 R: Request, 140 R: Request,