From 3544aabd5a2b0da2cd3a6f3fa3f00759aa9d9709 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 27 Oct 2022 12:49:05 -0700 Subject: [PATCH] Fix markdown document deleting (#164829) Fixes #164562 My previous fix was incorrect as it checked if the document existed by still consulting our `_documentCache`. When we are deleting/renaming an opened md document, it should pretty much always exist in our cache The fix is to instead treat `this.documents` and the file system as the source of truth when determining if the doc should be deleted or not --- .../server/src/workspace.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/extensions/markdown-language-features/server/src/workspace.ts b/extensions/markdown-language-features/server/src/workspace.ts index a41329fe7a8..865b9fcce1c 100644 --- a/extensions/markdown-language-features/server/src/workspace.ts +++ b/extensions/markdown-language-features/server/src/workspace.ts @@ -176,7 +176,7 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching { // Check that if file has been deleted on disk. // This can happen when directories are renamed / moved. VS Code's file system watcher does not // notify us when this happens. - if (await this.stat(uri) === undefined) { + if (await this.statBypassingCache(uri) === undefined) { if (this._documentCache.get(uri) === doc && !doc.hasInMemoryDoc()) { this.doDeleteDocument(uri); return; @@ -344,10 +344,18 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching { async stat(resource: URI): Promise { this.logger.log(md.LogLevel.Trace, 'VsCodeClientWorkspace: stat', `${resource}`); - if (this._documentCache.has(resource) || this.documents.get(resource.toString())) { + if (this._documentCache.has(resource)) { return { isDirectory: false }; } - return this.connection.sendRequest(protocol.fs_stat, { uri: resource.toString() }); + return this.statBypassingCache(resource); + } + + private async statBypassingCache(resource: URI): Promise { + const uri = resource.toString(); + if (this.documents.get(uri)) { + return { isDirectory: false }; + } + return this.connection.sendRequest(protocol.fs_stat, { uri }); } async readDirectory(resource: URI): Promise<[string, md.FileStat][]> {