Native API: formatDiagnosticsWithColorAndContext drops related information without a file location
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 75/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- node.js, typescript
- Bereich
- api
Rechercherichtung
Der Fehler steckt in packages/typescript/src/api/diagnosticFormatter.ts, wo der Aufruf flattenDiagnosticMessage(related, ...) innerhalb eines if (related.fileName && related.startPosition)-Zweigs steht. Führe das Reproduktionsskript aus dem Issue aus, um zu bestätigen, dass der zugehörige Text fehlt. Fertig ist es, wenn der zugehörige Text bei Diagnosen ohne Ortsangabe erscheint, während die Überschrift für den Ort und der Quellkontext weiterhin von einer Datei abhängen. Füge einen Regressionstest neben den bestehenden Tests des Formatters hinzu.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
🔎 Search Terms
formatDiagnosticsWithColorAndContext, relatedInformation, fileless diagnostic, missing related diagnostic text, diagnosticFormatter
🕗 Version & Regression Information
Reproduced against main at 6161772c1370bdd4a82f808e6823bd755eb1870d using Node.js v24.14.0. The same conditional is still present on current main.
The TypeScript 6.0.3 implementation outputs related diagnostic text outside the if (file) branch; the native API implementation only outputs it inside the location branch.
⏯ Playground Link
Not applicable: this exercises the diagnostic formatting API.
💻 Code
Save as repro.mts at the repository root and run node repro.mts with Node.js 24. This calls the formatter directly with a diagnostic containing a related message without a file location.
import { formatDiagnosticsWithColorAndContext } from "./packages/typescript/src/api/diagnosticFormatter.ts";
const host = {
getCurrentDirectory: () => "/project",
getCanonicalFileName: (name: string) => name,
getNewLine: () => "\n",
};
const output = formatDiagnosticsWithColorAndContext([{
category: 1,
code: 2322,
pos: 0,
end: 0,
text: "Primary error.",
relatedInformation: [{
category: 3,
code: 9999,
pos: 0,
end: 0,
text: "This related explanation must remain visible.",
}],
}], host);
console.log(JSON.stringify(output.replace(/\x1b\[[0-9;]*m/g, "")));
🙁 Actual behavior
The related explanation disappears:
"error TS2322: Primary error.\n"
Adding fileName: "/project/a.ts" and startPosition: { line: 0, character: 0 } to the related diagnostic makes its text appear.
🙂 Expected behavior
The related explanation should be included even when it has no file location. Only the location heading and source context depend on a location.
Additional information about the issue
In diagnosticFormatter.ts, the call to flattenDiagnosticMessage(related, ...) is inside if (related.fileName && related.startPosition). This also drops message chains on locationless related diagnostics.
The diagnostic response type permits omitted file names and positions. In the 6.0.3 formatter, related message text is emitted independently of the file check.
The reproduction uses constructed diagnostic objects to isolate the formatter behavior. Existing formatter tests cover related information with a location.
I would be happy to submit a focused fix and regression tests once this is triaged.
- Vorherrschende Sprache
- Go
- Sterne
- 112k
- Forks
- 15.4k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 126
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/TypeScript
-
Won't Fix
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
microsoft/TypeScript#65107 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'Evtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
microsoft/TypeScript#64758 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Evtl. vergeben @rajnish-verma-22172 hat das vor 12 Tagen übernommen. OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
microsoft/TypeScript#64742 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsEvtl. vergeben @dmety hat das vor 26 Tagen übernommen. OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
microsoft/TypeScript#64661 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmedEvtl. vergeben @RyanCavanaugh hat das vor 27 Tagen übernommen. OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
microsoft/TypeScript#64618 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in microsoft/TypeScript
Ähnliche Issues
-
[BUG] serviceenvupdater filter does not update KUBERNETES_SERVICE_HOST/PORT in init containersEvtl. vergeben @RaphaelFakhri hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
openyurtio/openyurt#2845 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
enhancement good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
fix(scan): validate and normalize output format in validate-contractEvtl. vergeben @WKr1shna hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100