Skip to content

Commit 401ac00

Browse files
committed
feat: cache the result of the stat method to avoid redundant calls
1 parent 18c4455 commit 401ac00

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/integrations/diagnostics/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export async function diagnosticsToProblemsString(
7676
cwd: string,
7777
): Promise<string> {
7878
const documents = new Map<vscode.Uri, vscode.TextDocument>()
79+
const fileStats = new Map<vscode.Uri, vscode.FileStat>()
7980
let result = ""
8081
for (const [uri, fileDiagnostics] of diagnostics) {
8182
const problems = fileDiagnostics
@@ -104,7 +105,11 @@ export async function diagnosticsToProblemsString(
104105
const line = diagnostic.range.start.line + 1 // VSCode lines are 0-indexed
105106
const source = diagnostic.source ? `${diagnostic.source} ` : ""
106107
try {
107-
const fileStat = await vscode.workspace.fs.stat(uri)
108+
let fileStat = fileStats.get(uri)
109+
if (!fileStat) {
110+
fileStat = await vscode.workspace.fs.stat(uri)
111+
fileStats.set(uri, fileStat)
112+
}
108113
if (fileStat.type === vscode.FileType.File) {
109114
const document = documents.get(uri) || (await vscode.workspace.openTextDocument(uri))
110115
documents.set(uri, document)

0 commit comments

Comments
 (0)