diff options
author | Emil Lauridsen <[email protected]> | 2020-01-15 14:50:49 +0000 |
---|---|---|
committer | Emil Lauridsen <[email protected]> | 2020-01-15 14:50:49 +0000 |
commit | 478ba65f8da6ffd4a3fea09c6a4a1f0fb92e1c85 (patch) | |
tree | 7406f354ac2f5ade2f0437a418cc172f76d861b4 /crates/ra_lsp_server/src | |
parent | fdb13dade970d730468cab80ab62837124b08195 (diff) |
Manage check state updates in main_loop to reduce lock contention
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 28 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 6 |
2 files changed, 29 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 84012b99d..e087c4f7e 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -337,11 +337,34 @@ fn loop_turn( | |||
337 | loop_state.in_flight_libraries -= 1; | 337 | loop_state.in_flight_libraries -= 1; |
338 | } | 338 | } |
339 | Event::CheckWatcher(task) => match task { | 339 | Event::CheckWatcher(task) => match task { |
340 | CheckTask::Update(uri) => { | 340 | CheckTask::ClearDiagnostics => { |
341 | let cleared_files = world_state.check_watcher.state.write().clear(); | ||
342 | |||
343 | // Send updated diagnostics for each cleared file | ||
344 | for url in cleared_files { | ||
345 | let path = url.to_file_path().map_err(|()| format!("invalid uri: {}", url))?; | ||
346 | if let Some(file_id) = world_state.vfs.read().path2file(&path) { | ||
347 | let params = handlers::publish_diagnostics( | ||
348 | &world_state.snapshot(), | ||
349 | FileId(file_id.0), | ||
350 | )?; | ||
351 | let not = notification_new::<req::PublishDiagnostics>(params); | ||
352 | task_sender.send(Task::Notify(not)).unwrap(); | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | |||
357 | CheckTask::AddDiagnostic(url, diagnostic) => { | ||
358 | world_state | ||
359 | .check_watcher | ||
360 | .state | ||
361 | .write() | ||
362 | .add_diagnostic_with_fixes(url.clone(), diagnostic); | ||
363 | |||
341 | // We manually send a diagnostic update when the watcher asks | 364 | // We manually send a diagnostic update when the watcher asks |
342 | // us to, to avoid the issue of having to change the file to | 365 | // us to, to avoid the issue of having to change the file to |
343 | // receive updated diagnostics. | 366 | // receive updated diagnostics. |
344 | let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?; | 367 | let path = url.to_file_path().map_err(|()| format!("invalid uri: {}", url))?; |
345 | if let Some(file_id) = world_state.vfs.read().path2file(&path) { | 368 | if let Some(file_id) = world_state.vfs.read().path2file(&path) { |
346 | let params = | 369 | let params = |
347 | handlers::publish_diagnostics(&world_state.snapshot(), FileId(file_id.0))?; | 370 | handlers::publish_diagnostics(&world_state.snapshot(), FileId(file_id.0))?; |
@@ -349,6 +372,7 @@ fn loop_turn( | |||
349 | task_sender.send(Task::Notify(not)).unwrap(); | 372 | task_sender.send(Task::Notify(not)).unwrap(); |
350 | } | 373 | } |
351 | } | 374 | } |
375 | |||
352 | CheckTask::Status(progress) => { | 376 | CheckTask::Status(progress) => { |
353 | let params = req::ProgressParams { | 377 | let params = req::ProgressParams { |
354 | token: req::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()), | 378 | token: req::ProgressToken::String("rustAnalyzer/cargoWatcher".to_string()), |
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index c0175c726..7a3030a51 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -13,7 +13,7 @@ use lsp_server::ErrorCode; | |||
13 | use lsp_types::Url; | 13 | use lsp_types::Url; |
14 | use parking_lot::RwLock; | 14 | use parking_lot::RwLock; |
15 | use ra_cargo_watch::{ | 15 | use ra_cargo_watch::{ |
16 | url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher, CheckWatcherSharedState, | 16 | url_from_path_with_drive_lowercasing, CheckOptions, CheckState, CheckWatcher, |
17 | }; | 17 | }; |
18 | use ra_ide::{ | 18 | use ra_ide::{ |
19 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FeatureFlags, FileId, LibraryData, | 19 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FeatureFlags, FileId, LibraryData, |
@@ -64,7 +64,7 @@ pub struct WorldSnapshot { | |||
64 | pub analysis: Analysis, | 64 | pub analysis: Analysis, |
65 | pub vfs: Arc<RwLock<Vfs>>, | 65 | pub vfs: Arc<RwLock<Vfs>>, |
66 | pub latest_requests: Arc<RwLock<LatestRequests>>, | 66 | pub latest_requests: Arc<RwLock<LatestRequests>>, |
67 | pub check_watcher: Arc<RwLock<CheckWatcherSharedState>>, | 67 | pub check_watcher: Arc<RwLock<CheckState>>, |
68 | } | 68 | } |
69 | 69 | ||
70 | impl WorldState { | 70 | impl WorldState { |
@@ -220,7 +220,7 @@ impl WorldState { | |||
220 | analysis: self.analysis_host.analysis(), | 220 | analysis: self.analysis_host.analysis(), |
221 | vfs: Arc::clone(&self.vfs), | 221 | vfs: Arc::clone(&self.vfs), |
222 | latest_requests: Arc::clone(&self.latest_requests), | 222 | latest_requests: Arc::clone(&self.latest_requests), |
223 | check_watcher: self.check_watcher.shared.clone(), | 223 | check_watcher: self.check_watcher.state.clone(), |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||