Skip to content

Commit 3544aab

Browse files
authored
Fix markdown document deleting (microsoft#164829)
Fixes microsoft#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
1 parent 0570a76 commit 3544aab

File tree

1 file changed

+11
-3
lines changed
  • extensions/markdown-language-features/server/src

1 file changed

+11
-3
lines changed

extensions/markdown-language-features/server/src/workspace.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
176176
// Check that if file has been deleted on disk.
177177
// This can happen when directories are renamed / moved. VS Code's file system watcher does not
178178
// notify us when this happens.
179-
if (await this.stat(uri) === undefined) {
179+
if (await this.statBypassingCache(uri) === undefined) {
180180
if (this._documentCache.get(uri) === doc && !doc.hasInMemoryDoc()) {
181181
this.doDeleteDocument(uri);
182182
return;
@@ -344,10 +344,18 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
344344

345345
async stat(resource: URI): Promise<md.FileStat | undefined> {
346346
this.logger.log(md.LogLevel.Trace, 'VsCodeClientWorkspace: stat', `${resource}`);
347-
if (this._documentCache.has(resource) || this.documents.get(resource.toString())) {
347+
if (this._documentCache.has(resource)) {
348348
return { isDirectory: false };
349349
}
350-
return this.connection.sendRequest(protocol.fs_stat, { uri: resource.toString() });
350+
return this.statBypassingCache(resource);
351+
}
352+
353+
private async statBypassingCache(resource: URI): Promise<md.FileStat | undefined> {
354+
const uri = resource.toString();
355+
if (this.documents.get(uri)) {
356+
return { isDirectory: false };
357+
}
358+
return this.connection.sendRequest(protocol.fs_stat, { uri });
351359
}
352360

353361
async readDirectory(resource: URI): Promise<[string, md.FileStat][]> {

0 commit comments

Comments
 (0)