Skip to content

Commit 84b2a99

Browse files
authored
Fix FileSystemProvider mtime caching (#770)
1 parent 2044f4b commit 84b2a99

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
8888
const name = item.Name;
8989
const fullName = folder === "" ? name : csp ? folder + name : folder + "/" + name;
9090
if (item.Type === "10" || item.Type === "9") {
91-
parent.entries.set(name, new Directory(name, fullName));
91+
if (!parent.entries.has(name)) {
92+
parent.entries.set(name, new Directory(name, fullName));
93+
}
9294
return [name, vscode.FileType.Directory];
9395
} else {
9496
return [name, vscode.FileType.File];
@@ -131,7 +133,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
131133
}
132134

133135
public async readFile(uri: vscode.Uri): Promise<Uint8Array> {
134-
return this._lookupAsFile(uri).then((file: File) => {
136+
// Use _lookup() instead of _lookupAsFile() so we send
137+
// our cached mtime with the GET /doc request if we have it
138+
return this._lookup(uri).then((file: File) => {
135139
// Update cache entry
136140
const uniqueId = `${workspaceFolderOfUri(uri)}:${file.fileName}`;
137141
workspaceState.update(`${uniqueId}:mtime`, file.mtime);
@@ -180,7 +184,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
180184
return;
181185
}
182186
const api = new AtelierAPI(uri);
183-
return this._lookupAsFile(uri).then(
187+
// Use _lookup() instead of _lookupAsFile() so we send
188+
// our cached mtime with the GET /doc request if we have it
189+
return this._lookup(uri).then(
184190
() => {
185191
// Weirdly, if the file exists on the server we don't actually write its content here.
186192
// Instead we simply return as though we wrote it successfully.
@@ -311,7 +317,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
311317
child = entry.entries.get(part);
312318
// If the last element of path is dotted and is one we haven't already cached as a directory
313319
// then it is assumed to be a file.
314-
if (!part.includes(".") || i + 1 < parts.length) {
320+
if ((!part.includes(".") || i + 1 < parts.length) && !child) {
315321
const fullName = entry.name === "" ? part : entry.fullName + "/" + part;
316322
child = new Directory(part, fullName);
317323
entry.entries.set(part, child);

0 commit comments

Comments
 (0)