Fix markdown server deleting documents on close if they still exist on disk (#160859)

This commit is contained in:
Matt Bierner 2022-09-14 09:16:39 -07:00 committed by GitHub
parent b488cc378b
commit 2cf7468289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,11 +61,18 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
}
});
documents.onDidClose(e => {
documents.onDidClose(async e => {
const uri = URI.parse(e.document.uri);
this._documentCache.delete(uri);
if (this.isRelevantMarkdownDocument(e.document)) {
if (!this.isRelevantMarkdownDocument(e.document)) {
return;
}
// When the document has closed, the file on disk may still exist.
// In this case, we want to replace the existing entry with the one from disk
const doc = await this.openMarkdownDocumentFromFs(uri);
if (!doc) {
this._onDidDeleteMarkdownDocument.fire(uri);
}
});
@ -179,6 +186,10 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
return matchingDocument;
}
return this.openMarkdownDocumentFromFs(resource);
}
private async openMarkdownDocumentFromFs(resource: URI): Promise<md.ITextDocument | undefined> {
if (!looksLikeMarkdownPath(this.config, resource)) {
return undefined;
}