aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/global_state.rs2
-rw-r--r--crates/rust-analyzer/src/main_loop.rs15
2 files changed, 16 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 0e592ac1b..658a50d15 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -73,6 +73,7 @@ pub(crate) struct GlobalState {
73 pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>, 73 pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
74 pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>, 74 pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
75 pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, 75 pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
76 pub(crate) shutdown_requested: bool,
76 pub(crate) status: Status, 77 pub(crate) status: Status,
77 pub(crate) source_root_config: SourceRootConfig, 78 pub(crate) source_root_config: SourceRootConfig,
78 pub(crate) proc_macro_client: ProcMacroClient, 79 pub(crate) proc_macro_client: ProcMacroClient,
@@ -124,6 +125,7 @@ impl GlobalState {
124 mem_docs: FxHashMap::default(), 125 mem_docs: FxHashMap::default(),
125 semantic_tokens_cache: Arc::new(Default::default()), 126 semantic_tokens_cache: Arc::new(Default::default()),
126 vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), 127 vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
128 shutdown_requested: false,
127 status: Status::default(), 129 status: Status::default(),
128 source_root_config: SourceRootConfig::default(), 130 source_root_config: SourceRootConfig::default(),
129 proc_macro_client: ProcMacroClient::dummy(), 131 proc_macro_client: ProcMacroClient::dummy(),
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 0ac6434dd..e6cf46df2 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -337,6 +337,16 @@ impl GlobalState {
337 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { 337 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
338 self.register_request(&req, request_received); 338 self.register_request(&req, request_received);
339 339
340 if self.shutdown_requested {
341 self.respond(Response::new_err(
342 req.id,
343 lsp_server::ErrorCode::InvalidRequest as i32,
344 "Shutdown already requested.".to_owned(),
345 ));
346
347 return Ok(());
348 }
349
340 if self.status == Status::Loading && req.method != "shutdown" { 350 if self.status == Status::Loading && req.method != "shutdown" {
341 self.respond(lsp_server::Response::new_err( 351 self.respond(lsp_server::Response::new_err(
342 req.id, 352 req.id,
@@ -351,7 +361,10 @@ impl GlobalState {
351 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))? 361 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
352 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? 362 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
353 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? 363 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
354 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))? 364 .on_sync::<lsp_types::request::Shutdown>(|s, ()| {
365 s.shutdown_requested = true;
366 Ok(())
367 })?
355 .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| { 368 .on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
356 handlers::handle_selection_range(s.snapshot(), p) 369 handlers::handle_selection_range(s.snapshot(), p)
357 })? 370 })?