Skip to content

Commit

Permalink
Fix markdown server not updating documents properly on folder rename (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz authored Oct 26, 2022
1 parent 70998c0 commit 5f87632
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions extensions/markdown-language-features/server/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class VsCodeDocument implements md.ITextDocument {
throw new Error('Document has been closed');
}

hasInMemoryDoc(): boolean {
return !this.inMemoryDoc;
}

isDetached(): boolean {
return !this.onDiskDoc && !this.inMemoryDoc;
}
Expand Down Expand Up @@ -166,12 +170,23 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
if (doc.isDetached()) {
// The document has been fully closed
this.doDeleteDocument(uri);
} else {
// The document still exists on disk
// To be safe, tell the service that the document has changed because the
// in-memory doc contents may be different than the disk doc contents.
this._onDidChangeMarkdownDocument.fire(doc);
return;
}

// 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 (this._documentCache.get(uri) === doc && !doc.hasInMemoryDoc()) {
this.doDeleteDocument(uri);
return;
}
}

// The document still exists on disk
// To be safe, tell the service that the document has changed because the
// in-memory doc contents may be different than the disk doc contents.
this._onDidChangeMarkdownDocument.fire(doc);
});

connection.onDidChangeWatchedFiles(async ({ changes }) => {
Expand Down

0 comments on commit 5f87632

Please sign in to comment.