Refactor writeTemporaryDiagnosticFile out of add[NoLanguage]Diagnostic

This commit is contained in:
Michael B. Gale
2026-10-12 16:15:55 +01:00
committed by GitHub
parent 684b314334
commit 7b81a06f3e
2 changed files with 35 additions and 16 deletions

View File

@@ -175,11 +175,7 @@ export function addDiagnostic(
);
// Write the diagnostic to a temporary location.
const tempDiagnosticsPath = getTempDiagnosticPath(config.tempDir, language);
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
// Track the temporary file.
temporaryDiagnostics.push({ path: diagnosticPath, language });
writeTemporaryDiagnosticFile(config.tempDir, language, diagnostic);
}
}
@@ -197,14 +193,32 @@ export function addNoLanguageDiagnostic(
diagnostic,
);
} else {
const tempDiagnosticsPath = getTempDiagnosticPath(getTemporaryDirectory());
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
// Track the temporary file.
temporaryDiagnostics.push({ path: diagnosticPath });
// Write the diagnostic to a temporary location.
writeTemporaryDiagnosticFile(
getTemporaryDirectory(),
undefined,
diagnostic,
);
}
}
/**
* Writes {@link diagnostic} for an optional {@link language} to a subdirectory of {@link tempDir}
* and tracks it as a diagnostic that was written to a temporary location.
*/
function writeTemporaryDiagnosticFile(
tempDir: string,
language: Language | undefined,
diagnostic: DiagnosticMessage,
) {
// Write the diagnostic to a temporary location.
const tempDiagnosticsPath = getTempDiagnosticPath(tempDir, language);
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
// Track the temporary file.
temporaryDiagnostics.push({ path: diagnosticPath, language });
}
/**
* Writes {@link diagnostic} to a file in {@link diagnosticsPath}.
*/