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:
Jeremy Kolb 2020-08-09 16:27:48 -04:00 committed by kjeremy
parent cef39c3efb
commit cf6d14cee7
2 changed files with 16 additions and 1 deletions

View File

@ -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(),

View File

@ -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)
})?