aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-14 19:32:05 +0100
committerDmitry <[email protected]>2020-08-14 19:32:05 +0100
commit178c3e135a2a249692f7784712492e7884ae0c00 (patch)
treeac6b769dbf7162150caa0c1624786a4dd79ff3be /crates/rust-analyzer/src/main_loop.rs
parent06ff8e6c760ff05f10e868b5d1f9d79e42fbb49c (diff)
parentc2594daf2974dbd4ce3d9b7ec72481764abaceb5 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs36
1 files changed, 29 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 438e965e0..66e04653a 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -5,12 +5,11 @@ use std::{
5 time::{Duration, Instant}, 5 time::{Duration, Instant},
6}; 6};
7 7
8use base_db::VfsPath;
8use crossbeam_channel::{select, Receiver}; 9use crossbeam_channel::{select, Receiver};
10use ide::{Canceled, FileId};
9use lsp_server::{Connection, Notification, Request, Response}; 11use lsp_server::{Connection, Notification, Request, Response};
10use lsp_types::notification::Notification as _; 12use lsp_types::notification::Notification as _;
11use ra_db::VfsPath;
12use ra_ide::{Canceled, FileId};
13use ra_prof::profile;
14 13
15use crate::{ 14use crate::{
16 config::Config, 15 config::Config,
@@ -22,7 +21,7 @@ use crate::{
22 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress}, 21 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress},
23 Result, 22 Result,
24}; 23};
25use ra_project_model::ProjectWorkspace; 24use project_model::ProjectWorkspace;
26use vfs::ChangeKind; 25use vfs::ChangeKind;
27 26
28pub fn main_loop(config: Config, connection: Connection) -> Result<()> { 27pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
@@ -173,7 +172,7 @@ impl GlobalState {
173 fn handle_event(&mut self, event: Event) -> Result<()> { 172 fn handle_event(&mut self, event: Event) -> Result<()> {
174 let loop_start = Instant::now(); 173 let loop_start = Instant::now();
175 // NOTE: don't count blocking select! call as a loop-turn time 174 // NOTE: don't count blocking select! call as a loop-turn time
176 let _p = profile("GlobalState::handle_event"); 175 let _p = profile::span("GlobalState::handle_event");
177 176
178 log::info!("handle_event({:?})", event); 177 log::info!("handle_event({:?})", event);
179 let queue_count = self.task_pool.handle.len(); 178 let queue_count = self.task_pool.handle.len();
@@ -204,7 +203,7 @@ impl GlobalState {
204 self.analysis_host.maybe_collect_garbage(); 203 self.analysis_host.maybe_collect_garbage();
205 } 204 }
206 Event::Vfs(mut task) => { 205 Event::Vfs(mut task) => {
207 let _p = profile("GlobalState::handle_event/vfs"); 206 let _p = profile::span("GlobalState::handle_event/vfs");
208 loop { 207 loop {
209 match task { 208 match task {
210 vfs::loader::Message::Loaded { files } => { 209 vfs::loader::Message::Loaded { files } => {
@@ -337,11 +336,34 @@ impl GlobalState {
337 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { 336 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
338 self.register_request(&req, request_received); 337 self.register_request(&req, request_received);
339 338
339 if self.shutdown_requested {
340 self.respond(Response::new_err(
341 req.id,
342 lsp_server::ErrorCode::InvalidRequest as i32,
343 "Shutdown already requested.".to_owned(),
344 ));
345
346 return Ok(());
347 }
348
349 if self.status == Status::Loading && req.method != "shutdown" {
350 self.respond(lsp_server::Response::new_err(
351 req.id,
352 // FIXME: i32 should impl From<ErrorCode> (from() guarantees lossless conversion)
353 lsp_server::ErrorCode::ContentModified as i32,
354 "Rust Analyzer is still loading...".to_owned(),
355 ));
356 return Ok(());
357 }
358
340 RequestDispatcher { req: Some(req), global_state: self } 359 RequestDispatcher { req: Some(req), global_state: self }
341 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))? 360 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
342 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? 361 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
343 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? 362 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
344 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))? 363 .on_sync::<lsp_types::request::Shutdown>(|s, ()| {
364 s.shutdown_requested = true;
365 Ok(())
366 })?
345 .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| { 367 .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
346 handlers::handle_selection_range(s.snapshot(), p) 368 handlers::handle_selection_range(s.snapshot(), p)
347 })? 369 })?