Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.DocumentSymbolParams;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.FileDelete;
import org.eclipse.lsp4j.FileRename;
import org.eclipse.lsp4j.FoldingRange;
import org.eclipse.lsp4j.FoldingRangeRequestParams;
Expand Down Expand Up @@ -335,14 +336,21 @@ public void didClose(DidCloseTextDocumentParams params) {
throw new ResponseErrorException(unknownFileError(loc, params));
}
facts(loc).close(loc);
exec.execute(() -> {
// If the closed file no longer exists (e.g., if an untitled file is closed without ever having been saved),
// we mimic a delete event to ensure all diagnostics are cleared.
if (!URIResolverRegistry.getInstance().exists(loc)) {
didDeleteFiles(new DeleteFilesParams(List.of(new FileDelete(params.getTextDocument().getUri()))));
}
});
}

@Override
public void didDeleteFiles(DeleteFilesParams params) {
exec.submit(() -> {
// if a file is deleted, and we were tracking it, we remove our diagnostics
for (var f : params.getFiles()) {
if (isLanguageRegistered(URIUtil.assumeCorrectLocation(f.getUri()))) {
if (isLanguageRegistered(Locations.toLoc(f.getUri()))) {
availableClient().publishDiagnostics(new PublishDiagnosticsParams(f.getUri(), List.of()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.eclipse.lsp4j.DocumentSymbolParams;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.FileCreate;
import org.eclipse.lsp4j.FileDelete;
import org.eclipse.lsp4j.FoldingRange;
import org.eclipse.lsp4j.FoldingRangeRequestParams;
import org.eclipse.lsp4j.Hover;
Expand Down Expand Up @@ -283,10 +284,17 @@ public void didChange(DidChangeTextDocumentParams params) {
@Override
public void didClose(DidCloseTextDocumentParams params) {
logger.debug("Close: {}", params.getTextDocument());
if (documents.remove(Locations.toLoc(params.getTextDocument())) == null) {
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InternalError,
"Unknown file: " + Locations.toLoc(params.getTextDocument()), params));
var loc = Locations.toLoc(params.getTextDocument());
if (documents.remove(loc) == null) {
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InternalError, "Unknown file: " + loc, params));
}
exec.execute(() -> {
// If the closed file no longer exists (e.g., if an untitled file is closed without ever having been saved),
// we mimic a delete event to ensure all diagnostics are cleared.
if (!URIResolverRegistry.getInstance().exists(loc)) {
didDeleteFiles(new DeleteFilesParams(List.of(new FileDelete(params.getTextDocument().getUri()))));
}
});
}

@Override
Expand Down
Loading