@@ -64,6 +64,10 @@ class VsCodeDocument implements md.ITextDocument {
64
64
throw new Error ( 'Document has been closed' ) ;
65
65
}
66
66
67
+ hasInMemoryDoc ( ) : boolean {
68
+ return ! this . inMemoryDoc ;
69
+ }
70
+
67
71
isDetached ( ) : boolean {
68
72
return ! this . onDiskDoc && ! this . inMemoryDoc ;
69
73
}
@@ -166,12 +170,23 @@ export class VsCodeClientWorkspace implements md.IWorkspaceWithWatching {
166
170
if ( doc . isDetached ( ) ) {
167
171
// The document has been fully closed
168
172
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 ;
174
174
}
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 ) ;
175
190
} ) ;
176
191
177
192
connection . onDidChangeWatchedFiles ( async ( { changes } ) => {
0 commit comments