From 7cb1b9d9f00550ffa914432d7ce8ac85d62655b8 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 28 Oct 2022 17:08:21 -0700 Subject: [PATCH] Fix bugs with close of markdown docs (#164942) There are two bugs here: - Something in the lsp is converting a value from `undefined` to `null`. To fix this, I've updated us just to check for falsy values instead - The `hasInMemoryDoc` implementation was incorrect. It needs to verify that the value of `this.inMemoryDoc` is not null/undefined --- .../markdown-language-features/server/src/workspace.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extensions/markdown-language-features/server/src/workspace.ts b/extensions/markdown-language-features/server/src/workspace.ts index 865b9fcce1c..cec5b950a5d 100644 --- a/extensions/markdown-language-features/server/src/workspace.ts +++ b/extensions/markdown-language-features/server/src/workspace.ts @@ -65,7 +65,7 @@ class VsCodeDocument implements md.ITextDocument { } hasInMemoryDoc(): boolean { - return !this.inMemoryDoc; + return !!this.inMemoryDoc; } isDetached(): boolean { @@ -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.statBypassingCache(uri) === undefined) { + if (!(await this.statBypassingCache(uri))) { if (this._documentCache.get(uri) === doc && !doc.hasInMemoryDoc()) { this.doDeleteDocument(uri); return; @@ -355,7 +355,8 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching { if (this.documents.get(uri)) { return { isDirectory: false }; } - return this.connection.sendRequest(protocol.fs_stat, { uri }); + const fsResult = await this.connection.sendRequest(protocol.fs_stat, { uri }); + return fsResult ?? undefined; // Force convert null to undefined } async readDirectory(resource: URI): Promise<[string, md.FileStat][]> {