Skip to content

Commit 5f87632

Browse files
authored
Fix markdown server not updating documents properly on folder rename (microsoft#164752)
Fixes microsoft#164562
1 parent 70998c0 commit 5f87632

File tree

1 file changed

+20
-5
lines changed
  • extensions/markdown-language-features/server/src

1 file changed

+20
-5
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class VsCodeDocument implements md.ITextDocument {
6464
throw new Error('Document has been closed');
6565
}
6666

67+
hasInMemoryDoc(): boolean {
68+
return !this.inMemoryDoc;
69+
}
70+
6771
isDetached(): boolean {
6872
return !this.onDiskDoc && !this.inMemoryDoc;
6973
}
@@ -166,12 +170,23 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
166170
if (doc.isDetached()) {
167171
// The document has been fully closed
168172
this.doDeleteDocument(uri);
169-
} else {
170-
// The document still exists on disk
171-
// To be safe, tell the service that the document has changed because the
172-
// in-memory doc contents may be different than the disk doc contents.
173-
this._onDidChangeMarkdownDocument.fire(doc);
173+
return;
174174
}
175+
176+
// Check that if file has been deleted on disk.
177+
// This can happen when directories are renamed / moved. VS Code's file system watcher does not
178+
// notify us when this happens.
179+
if (await this.stat(uri) === undefined) {
180+
if (this._documentCache.get(uri) === doc && !doc.hasInMemoryDoc()) {
181+
this.doDeleteDocument(uri);
182+
return;
183+
}
184+
}
185+
186+
// The document still exists on disk
187+
// To be safe, tell the service that the document has changed because the
188+
// in-memory doc contents may be different than the disk doc contents.
189+
this._onDidChangeMarkdownDocument.fire(doc);
175190
});
176191

177192
connection.onDidChangeWatchedFiles(async ({ changes }) => {

0 commit comments

Comments
 (0)