diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-27 12:45:41 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-27 12:45:41 +0100 |
commit | b2bf41b2bac48edd53e3059adfba4a12b3c96aa0 (patch) | |
tree | 35b1737a82c1ae207fa9288341c82fb0e8a5cfd4 /crates | |
parent | 0d1c6076073c73f57340e256dc25da9d37311ef0 (diff) | |
parent | a2845bb1f59e5f3d9f41012ace70037b783468ce (diff) |
Merge #1334
1334: check for cancellation during macro expansion r=matklad a=matklad
closes #1331
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 69 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/support.rs | 14 |
4 files changed, 87 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 2eb7f0da0..5c3799e95 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -61,6 +61,7 @@ impl HirFileId { | |||
61 | db: &impl DefDatabase, | 61 | db: &impl DefDatabase, |
62 | file_id: HirFileId, | 62 | file_id: HirFileId, |
63 | ) -> Option<TreeArc<SyntaxNode>> { | 63 | ) -> Option<TreeArc<SyntaxNode>> { |
64 | db.check_canceled(); | ||
64 | let _p = profile("parse_or_expand_query"); | 65 | let _p = profile("parse_or_expand_query"); |
65 | match file_id.0 { | 66 | match file_id.0 { |
66 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).syntax().to_owned()), | 67 | HirFileIdRepr::File(file_id) => Some(db.parse(file_id).syntax().to_owned()), |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 2434f428f..0e64abdbd 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -156,6 +156,10 @@ impl RootDatabase { | |||
156 | pub(crate) fn apply_change(&mut self, change: AnalysisChange) { | 156 | pub(crate) fn apply_change(&mut self, change: AnalysisChange) { |
157 | let _p = profile("RootDatabase::apply_change"); | 157 | let _p = profile("RootDatabase::apply_change"); |
158 | log::info!("apply_change {:?}", change); | 158 | log::info!("apply_change {:?}", change); |
159 | { | ||
160 | let _p = profile("RootDatabase::apply_change/cancellation"); | ||
161 | self.salsa_runtime().next_revision(); | ||
162 | } | ||
159 | if !change.new_roots.is_empty() { | 163 | if !change.new_roots.is_empty() { |
160 | let mut local_roots = Vec::clone(&self.local_roots()); | 164 | let mut local_roots = Vec::clone(&self.local_roots()); |
161 | for (root_id, is_local) in change.new_roots { | 165 | for (root_id, is_local) in change.new_roots { |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 6f37a980d..f61048aaf 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 | ||
8 | use lsp_types::{ | 8 | use lsp_types::{ |
9 | CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, | 9 | CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, DidOpenTextDocumentParams, TextDocumentItem, TextDocumentPositionParams |
10 | }; | 10 | }; |
11 | use ra_lsp_server::req::{ | 11 | use 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 | }; |
14 | use serde_json::json; | 15 | use serde_json::json; |
15 | use tempfile::TempDir; | 16 | use tempfile::TempDir; |
@@ -17,6 +18,7 @@ use tempfile::TempDir; | |||
17 | use crate::support::{project, Project}; | 18 | use crate::support::{project, Project}; |
18 | 19 | ||
19 | const LOG: &'static str = ""; | 20 | const LOG: &'static str = ""; |
21 | const PROFILE: &'static str = "*@3>100"; | ||
20 | 22 | ||
21 | #[test] | 23 | #[test] |
22 | fn completes_items_from_standard_library() { | 24 | fn completes_items_from_standard_library() { |
@@ -341,3 +343,68 @@ fn main() {{}} | |||
341 | json!([]), | 343 | json!([]), |
342 | ); | 344 | ); |
343 | } | 345 | } |
346 | |||
347 | #[test] | ||
348 | fn 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] | ||
355 | name = "foo" | ||
356 | version = "0.0.0" | ||
357 | |||
358 | //- src/lib.rs | ||
359 | {} | ||
360 | |||
361 | {} | ||
362 | |||
363 | fn main() {{}} | ||
364 | "#, | ||
365 | librs, libs | ||
366 | )); | ||
367 | server.wait_until_workspace_is_loaded(); | ||
368 | for i in 0..10 { | ||
369 | server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams { | ||
370 | text_document: TextDocumentItem { | ||
371 | uri: server.doc_id(&format!("src/m{}.rs", i)).uri, | ||
372 | language_id: "rust".to_string(), | ||
373 | version: 0, | ||
374 | text: "/// Docs\nfn foo() {}".to_string(), | ||
375 | }, | ||
376 | }); | ||
377 | } | ||
378 | let start = std::time::Instant::now(); | ||
379 | server.request::<OnEnter>( | ||
380 | TextDocumentPositionParams { | ||
381 | text_document: server.doc_id("src/m0.rs"), | ||
382 | position: Position { line: 0, character: 5 }, | ||
383 | }, | ||
384 | json!({ | ||
385 | "cursorPosition": { | ||
386 | "position": { "character": 4, "line": 1 }, | ||
387 | "textDocument": { "uri": "file:///[..]src/m0.rs" } | ||
388 | }, | ||
389 | "label": "on enter", | ||
390 | "workspaceEdit": { | ||
391 | "documentChanges": [ | ||
392 | { | ||
393 | "edits": [ | ||
394 | { | ||
395 | "newText": "\n/// ", | ||
396 | "range": { | ||
397 | "end": { "character": 5, "line": 0 }, | ||
398 | "start": { "character": 5, "line": 0 } | ||
399 | } | ||
400 | } | ||
401 | ], | ||
402 | "textDocument": { "uri": "file:///[..]src/m0.rs", "version": null } | ||
403 | } | ||
404 | ] | ||
405 | } | ||
406 | }), | ||
407 | ); | ||
408 | let elapsed = start.elapsed(); | ||
409 | assert!(elapsed.as_millis() < 2000, "typing enter took {:?}", elapsed); | ||
410 | } | ||
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>(¶ms); | ||
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, |