diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop.rs')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 55 |
1 files changed, 13 insertions, 42 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 26b6fe54a..a51299851 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -25,10 +25,7 @@ use crate::{ | |||
25 | }; | 25 | }; |
26 | 26 | ||
27 | #[derive(Debug, Fail)] | 27 | #[derive(Debug, Fail)] |
28 | #[fail( | 28 | #[fail(display = "Language Server request failed with {}. ({})", code, message)] |
29 | display = "Language Server request failed with {}. ({})", | ||
30 | code, message | ||
31 | )] | ||
32 | pub struct LspError { | 29 | pub struct LspError { |
33 | pub code: i32, | 30 | pub code: i32, |
34 | pub message: String, | 31 | pub message: String, |
@@ -69,9 +66,7 @@ pub fn main_loop( | |||
69 | } | 66 | } |
70 | }; | 67 | }; |
71 | ws_worker.shutdown(); | 68 | ws_worker.shutdown(); |
72 | ws_watcher | 69 | ws_watcher.shutdown().map_err(|_| format_err!("ws watcher died"))?; |
73 | .shutdown() | ||
74 | .map_err(|_| format_err!("ws watcher died"))?; | ||
75 | let mut state = ServerWorldState::new(ws_root.clone(), workspaces); | 70 | let mut state = ServerWorldState::new(ws_root.clone(), workspaces); |
76 | 71 | ||
77 | log::info!("server initialized, serving requests"); | 72 | log::info!("server initialized, serving requests"); |
@@ -92,9 +87,7 @@ pub fn main_loop( | |||
92 | ); | 87 | ); |
93 | 88 | ||
94 | log::info!("waiting for tasks to finish..."); | 89 | log::info!("waiting for tasks to finish..."); |
95 | task_receiver | 90 | task_receiver.into_iter().for_each(|task| on_task(task, msg_sender, &mut pending_requests)); |
96 | .into_iter() | ||
97 | .for_each(|task| on_task(task, msg_sender, &mut pending_requests)); | ||
98 | log::info!("...tasks have finished"); | 91 | log::info!("...tasks have finished"); |
99 | log::info!("joining threadpool..."); | 92 | log::info!("joining threadpool..."); |
100 | drop(pool); | 93 | drop(pool); |
@@ -119,9 +112,7 @@ enum Event { | |||
119 | impl fmt::Debug for Event { | 112 | impl fmt::Debug for Event { |
120 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 113 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
121 | let debug_verbose_not = |not: &RawNotification, f: &mut fmt::Formatter| { | 114 | let debug_verbose_not = |not: &RawNotification, f: &mut fmt::Formatter| { |
122 | f.debug_struct("RawNotification") | 115 | f.debug_struct("RawNotification").field("method", ¬.method).finish() |
123 | .field("method", ¬.method) | ||
124 | .finish() | ||
125 | }; | 116 | }; |
126 | 117 | ||
127 | match self { | 118 | match self { |
@@ -287,13 +278,7 @@ fn on_request( | |||
287 | sender: &Sender<Task>, | 278 | sender: &Sender<Task>, |
288 | req: RawRequest, | 279 | req: RawRequest, |
289 | ) -> Result<Option<RawRequest>> { | 280 | ) -> Result<Option<RawRequest>> { |
290 | let mut pool_dispatcher = PoolDispatcher { | 281 | let mut pool_dispatcher = PoolDispatcher { req: Some(req), res: None, pool, world, sender }; |
291 | req: Some(req), | ||
292 | res: None, | ||
293 | pool, | ||
294 | world, | ||
295 | sender, | ||
296 | }; | ||
297 | let req = pool_dispatcher | 282 | let req = pool_dispatcher |
298 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? | 283 | .on::<req::AnalyzerStatus>(handlers::handle_analyzer_status)? |
299 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? | 284 | .on::<req::SyntaxTree>(handlers::handle_syntax_tree)? |
@@ -362,13 +347,9 @@ fn on_notification( | |||
362 | let not = match not.cast::<req::DidOpenTextDocument>() { | 347 | let not = match not.cast::<req::DidOpenTextDocument>() { |
363 | Ok(params) => { | 348 | Ok(params) => { |
364 | let uri = params.text_document.uri; | 349 | let uri = params.text_document.uri; |
365 | let path = uri | 350 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; |
366 | .to_file_path() | 351 | if let Some(file_id) = |
367 | .map_err(|()| format_err!("invalid uri: {}", uri))?; | 352 | state.vfs.write().add_file_overlay(&path, params.text_document.text) |
368 | if let Some(file_id) = state | ||
369 | .vfs | ||
370 | .write() | ||
371 | .add_file_overlay(&path, params.text_document.text) | ||
372 | { | 353 | { |
373 | subs.add_sub(FileId(file_id.0.into())); | 354 | subs.add_sub(FileId(file_id.0.into())); |
374 | } | 355 | } |
@@ -379,14 +360,9 @@ fn on_notification( | |||
379 | let not = match not.cast::<req::DidChangeTextDocument>() { | 360 | let not = match not.cast::<req::DidChangeTextDocument>() { |
380 | Ok(mut params) => { | 361 | Ok(mut params) => { |
381 | let uri = params.text_document.uri; | 362 | let uri = params.text_document.uri; |
382 | let path = uri | 363 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; |
383 | .to_file_path() | 364 | let text = |
384 | .map_err(|()| format_err!("invalid uri: {}", uri))?; | 365 | params.content_changes.pop().ok_or_else(|| format_err!("empty changes"))?.text; |
385 | let text = params | ||
386 | .content_changes | ||
387 | .pop() | ||
388 | .ok_or_else(|| format_err!("empty changes"))? | ||
389 | .text; | ||
390 | state.vfs.write().change_file_overlay(path.as_path(), text); | 366 | state.vfs.write().change_file_overlay(path.as_path(), text); |
391 | return Ok(()); | 367 | return Ok(()); |
392 | } | 368 | } |
@@ -395,16 +371,11 @@ fn on_notification( | |||
395 | let not = match not.cast::<req::DidCloseTextDocument>() { | 371 | let not = match not.cast::<req::DidCloseTextDocument>() { |
396 | Ok(params) => { | 372 | Ok(params) => { |
397 | let uri = params.text_document.uri; | 373 | let uri = params.text_document.uri; |
398 | let path = uri | 374 | let path = uri.to_file_path().map_err(|()| format_err!("invalid uri: {}", uri))?; |
399 | .to_file_path() | ||
400 | .map_err(|()| format_err!("invalid uri: {}", uri))?; | ||
401 | if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) { | 375 | if let Some(file_id) = state.vfs.write().remove_file_overlay(path.as_path()) { |
402 | subs.remove_sub(FileId(file_id.0.into())); | 376 | subs.remove_sub(FileId(file_id.0.into())); |
403 | } | 377 | } |
404 | let params = req::PublishDiagnosticsParams { | 378 | let params = req::PublishDiagnosticsParams { uri, diagnostics: Vec::new() }; |
405 | uri, | ||
406 | diagnostics: Vec::new(), | ||
407 | }; | ||
408 | let not = RawNotification::new::<req::PublishDiagnostics>(¶ms); | 379 | let not = RawNotification::new::<req::PublishDiagnostics>(¶ms); |
409 | msg_sender.send(RawMessage::Notification(not)).unwrap(); | 380 | msg_sender.send(RawMessage::Notification(not)).unwrap(); |
410 | return Ok(()); | 381 | return Ok(()); |