Skip to content

Commit 104d981

Browse files
committed
Refactor writeTemporaryDiagnosticFile out of add[NoLanguage]Diagnostic
1 parent ac89bf9 commit 104d981

2 files changed

Lines changed: 35 additions & 16 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/diagnostics.ts‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ export function addDiagnostic(
175175
);
176176

177177
// Write the diagnostic to a temporary location.
178-
const tempDiagnosticsPath = getTempDiagnosticPath(config.tempDir, language);
179-
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
180-
181-
// Track the temporary file.
182-
temporaryDiagnostics.push({ path: diagnosticPath, language });
178+
writeTemporaryDiagnosticFile(config.tempDir, language, diagnostic);
183179
}
184180
}
185181

@@ -197,14 +193,32 @@ export function addNoLanguageDiagnostic(
197193
diagnostic,
198194
);
199195
} else {
200-
const tempDiagnosticsPath = getTempDiagnosticPath(getTemporaryDirectory());
201-
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
202-
203-
// Track the temporary file.
204-
temporaryDiagnostics.push({ path: diagnosticPath });
196+
// Write the diagnostic to a temporary location.
197+
writeTemporaryDiagnosticFile(
198+
getTemporaryDirectory(),
199+
undefined,
200+
diagnostic,
201+
);
205202
}
206203
}
207204

205+
/**
206+
* Writes {@link diagnostic} for an optional {@link language} to a subdirectory of {@link tempDir}
207+
* and tracks it as a diagnostic that was written to a temporary location.
208+
*/
209+
function writeTemporaryDiagnosticFile(
210+
tempDir: string,
211+
language: Language | undefined,
212+
diagnostic: DiagnosticMessage,
213+
) {
214+
// Write the diagnostic to a temporary location.
215+
const tempDiagnosticsPath = getTempDiagnosticPath(tempDir, language);
216+
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
217+
218+
// Track the temporary file.
219+
temporaryDiagnostics.push({ path: diagnosticPath, language });
220+
}
221+
208222
/**
209223
* Writes {@link diagnostic} to a file in {@link diagnosticsPath}.
210224
*/

0 commit comments

Comments
 (0)