Publish empty diagnostics on close (#4954)

Without this, diagnostics will linger after closing a file.

This refactors towards a pattern of putting outgoing calls as methods on
`Context`. I'm mixed on this, mainly thinking it's an improvement on
using `outgoing` directly (because it shares the name and structure),
might want to move it to a side-class later that is _only_ LSP wrappers.

I could also make inheritance private on OutgoingMessages and these
kinds of methods public there, but I'm hesitant to adopt that approach
versus a type separation.
This commit is contained in:
Jon Ross-Perkins
2025-02-15 00:09:20 +00:00
committed by GitHub
parent f038aead4c
commit d4f15ab26e
5 changed files with 33 additions and 7 deletions
@@ -58,7 +58,11 @@ auto HandleDidCloseTextDocument(
return;
}
if (!context.files().Erase(filename)) {
if (context.files().Erase(filename)) {
// Clear diagnostics when the document closes. Otherwise, any diagnostics
// will linger.
context.PublishDiagnostics({.uri = params.textDocument.uri});
} else {
CARBON_DIAGNOSTIC(LanguageServerCloseUnknownFile, Warning,
"tried closing unknown file; ignoring request");
context.file_emitter().Emit(filename, LanguageServerCloseUnknownFile);