Summary
This week, I focused on DMD’s diagnostic and error reporting infrastructure as part of enabling Language Server Protocol (LSP) integration. The main goal was to produce structured diagnostic data in JSON format that can be easily consumed by editors or tools such as serve-d
and code-d
.
1. Studied DMD’s Diagnostic System
- Understood how
ErrorSink
acts as an abstraction layer for all compiler messages (error
,warning
,deprecation
, etc.). - Traced how diagnostics propagate from parsing and semantic analysis to the sink layer.
2. Analysed Existing Tooling
- Examined D’s existing ecosystem components:
serve-d
andcode-d
for LSP support. - Studied
sarif.d
andjson.d
in the DMD codebase. - Found that
sarif.d
is designed for static analysis report generation, not for real-time LSP diagnostics.
3. Implemented errorsinkjson.d
- Created a new module
errorsinkjson.d
defining the classErrorSinkJson
. ErrorSinkJson
inherits fromErrorSink
and overrides all relevant virtual methods.- Each diagnostic is serialized into JSON with fields like:
{ "type": "error", "file": "main.d", "line": 42, "column": 5, }