Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/linkify/common/statCache.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IFileSystemService } from '../../../platform/filesystem/common/fileSystemService';
7
import { FileType } from '../../../platform/filesystem/common/fileTypes';
8
import { Uri } from '../../../vscodeTypes';
9
10
export interface IStatCache {
11
stat(uri: Uri): Promise<{ type: FileType } | undefined>;
12
}
13
14
export class StatCache implements IStatCache {
15
private readonly cache = new Map<string, Promise<{ type: FileType } | undefined>>();
16
17
constructor(
18
private readonly fileSystem: IFileSystemService,
19
) { }
20
21
stat(uri: Uri): Promise<{ type: FileType } | undefined> {
22
const key = uri.toString();
23
const existing = this.cache.get(key);
24
if (existing) {
25
return existing;
26
}
27
const result = this.fileSystem.stat(uri).then(s => s, () => undefined);
28
this.cache.set(key, result);
29
return result;
30
}
31
}
32
33