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
This commit is contained in:
Matt Bierner
2022-10-27 12:49:05 -07:00
committed by GitHub
parent 0570a7678d
commit 3544aabd5a

View File

@@ -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<md.FileStat | undefined> {
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<md.FileStat | undefined> {
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][]> {