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 https://github.com/microsoft/language-server-protocol/issues/1066

Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
This commit is contained in:
bors[bot] 2020-08-10 15:14:02 +00:00 committed by GitHub
commit 58711bda3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)
})?