Clear diagnostics during shutdown
This commit is contained in:
parent
9e1ecb29cd
commit
4e4af0540d
|
|
@ -184,6 +184,16 @@ impl LanguageServer for Backend {
|
|||
}
|
||||
|
||||
async fn shutdown(&self) -> Result<()> {
|
||||
let open_uris: Vec<_> = self
|
||||
.documents
|
||||
.write()
|
||||
.await
|
||||
.drain()
|
||||
.map(|(uri, _)| uri)
|
||||
.collect();
|
||||
for uri in open_uris {
|
||||
self.client.publish_diagnostics(uri, Vec::new(), None).await;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -1441,6 +1451,35 @@ mod tests {
|
|||
assert_eq!(observed_runner.inputs.lock().expect("input lock").len(), 1);
|
||||
}
|
||||
|
||||
/// Graceful shutdown clears every open URI before a client starts a new server.
|
||||
#[tokio::test]
|
||||
async fn shutdown_clears_open_document_diagnostics() {
|
||||
let runner = Arc::new(MockRunner::successful(EMPTY_DIAGNOSTICS));
|
||||
let (mut service, mut socket) =
|
||||
LspService::new(move |client| Backend::new(client, runner.clone(), Vec::new()));
|
||||
initialize(&mut service).await;
|
||||
let uri =
|
||||
tower_lsp::lsp_types::Url::parse("file:///tmp/example.vhd").expect("valid test URI");
|
||||
service.inner().documents.write().await.insert(
|
||||
uri.clone(),
|
||||
Document {
|
||||
text: "source".to_owned(),
|
||||
version: 1,
|
||||
diagnostics: Vec::new(),
|
||||
},
|
||||
);
|
||||
|
||||
let shutdown = tower_lsp::LanguageServer::shutdown(service.inner());
|
||||
let receive_clear = published_diagnostics(&mut socket);
|
||||
let (shutdown_result, cleared) = tokio::join!(shutdown, receive_clear);
|
||||
|
||||
shutdown_result.expect("shutdown succeeds");
|
||||
assert_eq!(cleared.uri, uri);
|
||||
assert!(cleared.diagnostics.is_empty());
|
||||
assert_eq!(cleared.version, None);
|
||||
assert!(service.inner().documents.read().await.is_empty());
|
||||
}
|
||||
|
||||
/// Runner failures become user-visible error notifications.
|
||||
#[tokio::test]
|
||||
async fn reports_runner_failures_to_the_client() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue