mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
Return InvalidRequest if Shutdown has been requested
From the LSP 3.16 spec: "If a server receives requests after a shutdown request those requests should error with InvalidRequest."
This commit is contained in:
parent
cef39c3efb
commit
cf6d14cee7
@ -73,6 +73,7 @@ pub(crate) struct GlobalState {
|
||||
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
|
||||
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||
pub(crate) shutdown_requested: bool,
|
||||
pub(crate) status: Status,
|
||||
pub(crate) source_root_config: SourceRootConfig,
|
||||
pub(crate) proc_macro_client: ProcMacroClient,
|
||||
@ -124,6 +125,7 @@ impl GlobalState {
|
||||
mem_docs: FxHashMap::default(),
|
||||
semantic_tokens_cache: Arc::new(Default::default()),
|
||||
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))),
|
||||
shutdown_requested: false,
|
||||
status: Status::default(),
|
||||
source_root_config: SourceRootConfig::default(),
|
||||
proc_macro_client: ProcMacroClient::dummy(),
|
||||
|
@ -337,6 +337,16 @@ impl GlobalState {
|
||||
fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
|
||||
self.register_request(&req, request_received);
|
||||
|
||||
if self.shutdown_requested {
|
||||
self.respond(Response::new_err(
|
||||
req.id,
|
||||
lsp_server::ErrorCode::InvalidRequest as i32,
|
||||
"Shutdown already requested.".to_owned(),
|
||||
));
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if self.status == Status::Loading && req.method != "shutdown" {
|
||||
self.respond(lsp_server::Response::new_err(
|
||||
req.id,
|
||||
@ -351,7 +361,10 @@ impl GlobalState {
|
||||
.on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
|
||||
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
|
||||
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
|
||||
.on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?
|
||||
.on_sync::<lsp_types::request::Shutdown>(|s, ()| {
|
||||
s.shutdown_requested = true;
|
||||
Ok(())
|
||||
})?
|
||||
.on_sync::<lsp_types::request::SelectionRangeRequest>(|s, p| {
|
||||
handlers::handle_selection_range(s.snapshot(), p)
|
||||
})?
|
||||
|
Loading…
Reference in New Issue
Block a user