aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index dda318e43..943d38943 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -19,6 +19,7 @@ use serde::{de::DeserializeOwned, Serialize};
19use threadpool::ThreadPool; 19use threadpool::ThreadPool;
20 20
21use crate::{ 21use crate::{
22 cargo_check::CheckTask,
22 main_loop::{ 23 main_loop::{
23 pending_requests::{PendingRequest, PendingRequests}, 24 pending_requests::{PendingRequest, PendingRequests},
24 subscriptions::Subscriptions, 25 subscriptions::Subscriptions,
@@ -176,7 +177,8 @@ pub fn main_loop(
176 Ok(task) => Event::Vfs(task), 177 Ok(task) => Event::Vfs(task),
177 Err(RecvError) => Err("vfs died")?, 178 Err(RecvError) => Err("vfs died")?,
178 }, 179 },
179 recv(libdata_receiver) -> data => Event::Lib(data.unwrap()) 180 recv(libdata_receiver) -> data => Event::Lib(data.unwrap()),
181 recv(world_state.check_watcher.task_recv) -> task => Event::CheckWatcher(task.unwrap())
180 }; 182 };
181 if let Event::Msg(Message::Request(req)) = &event { 183 if let Event::Msg(Message::Request(req)) = &event {
182 if connection.handle_shutdown(&req)? { 184 if connection.handle_shutdown(&req)? {
@@ -222,6 +224,7 @@ enum Event {
222 Task(Task), 224 Task(Task),
223 Vfs(VfsTask), 225 Vfs(VfsTask),
224 Lib(LibraryData), 226 Lib(LibraryData),
227 CheckWatcher(CheckTask),
225} 228}
226 229
227impl fmt::Debug for Event { 230impl fmt::Debug for Event {
@@ -259,6 +262,7 @@ impl fmt::Debug for Event {
259 Event::Task(it) => fmt::Debug::fmt(it, f), 262 Event::Task(it) => fmt::Debug::fmt(it, f),
260 Event::Vfs(it) => fmt::Debug::fmt(it, f), 263 Event::Vfs(it) => fmt::Debug::fmt(it, f),
261 Event::Lib(it) => fmt::Debug::fmt(it, f), 264 Event::Lib(it) => fmt::Debug::fmt(it, f),
265 Event::CheckWatcher(it) => fmt::Debug::fmt(it, f),
262 } 266 }
263 } 267 }
264} 268}
@@ -318,6 +322,20 @@ fn loop_turn(
318 world_state.maybe_collect_garbage(); 322 world_state.maybe_collect_garbage();
319 loop_state.in_flight_libraries -= 1; 323 loop_state.in_flight_libraries -= 1;
320 } 324 }
325 Event::CheckWatcher(task) => match task {
326 CheckTask::Update(uri) => {
327 // We manually send a diagnostic update when the watcher asks
328 // us to, to avoid the issue of having to change the file to
329 // receive updated diagnostics.
330 let path = uri.to_file_path().map_err(|()| format!("invalid uri: {}", uri))?;
331 if let Some(file_id) = world_state.vfs.read().path2file(&path) {
332 let params =
333 handlers::publish_diagnostics(&world_state.snapshot(), FileId(file_id.0))?;
334 let not = notification_new::<req::PublishDiagnostics>(params);
335 task_sender.send(Task::Notify(not)).unwrap();
336 }
337 }
338 },
321 Event::Msg(msg) => match msg { 339 Event::Msg(msg) => match msg {
322 Message::Request(req) => on_request( 340 Message::Request(req) => on_request(
323 world_state, 341 world_state,
@@ -517,6 +535,13 @@ fn on_notification(
517 } 535 }
518 Err(not) => not, 536 Err(not) => not,
519 }; 537 };
538 let not = match notification_cast::<req::DidSaveTextDocument>(not) {
539 Ok(_params) => {
540 state.check_watcher.update();
541 return Ok(());
542 }
543 Err(not) => not,
544 };
520 let not = match notification_cast::<req::DidCloseTextDocument>(not) { 545 let not = match notification_cast::<req::DidCloseTextDocument>(not) {
521 Ok(params) => { 546 Ok(params) => {
522 let uri = params.text_document.uri; 547 let uri = params.text_document.uri;