Skip to content

Commit 58711bd

Browse files
bors[bot]kjeremy
andauthored
Merge #5696
5696: Return InvalidRequest if Shutdown has been requested r=kjeremy a=kjeremy From the LSP 3.16 spec: "If a server receives requests after a shutdown request those requests should error with InvalidRequest." Realized this behavior was missing while looking at #5693. Question on notification behavior is tracked at microsoft/language-server-protocol#1066 Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2 parents cef39c3 + cf6d14c commit 58711bd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/rust-analyzer/src/global_state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub(crate) struct GlobalState {
7373
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
7474
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
7575
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
76+
pub(crate) shutdown_requested: bool,
7677
pub(crate) status: Status,
7778
pub(crate) source_root_config: SourceRootConfig,
7879
pub(crate) proc_macro_client: ProcMacroClient,
@@ -124,6 +125,7 @@ impl GlobalState {
124125
mem_docs: FxHashMap::default(),
125126
semantic_tokens_cache: Arc::new(Default::default()),
126127
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
128+
shutdown_requested: false,
127129
status: Status::default(),
128130
source_root_config: SourceRootConfig::default(),
129131
proc_macro_client: ProcMacroClient::dummy(),

crates/rust-analyzer/src/main_loop.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,16 @@ impl GlobalState {
337337
fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
338338
self.register_request(&req, request_received);
339339

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+
340350
if self.status == Status::Loading && req.method != "shutdown" {
341351
self.respond(lsp_server::Response::new_err(
342352
req.id,
@@ -351,7 +361,10 @@ impl GlobalState {
351361
.on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
352362
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
353363
.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+
})?
355368
.on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
356369
handlers::handle_selection_range(s.snapshot(), p)
357370
})?

0 commit comments

Comments
 (0)