[SAOC 2025] Improve error messages and LSP integration Weekly Update #5
This week I continued working on the LSP-style printing of diagnostics in dmd. I also made certain changes to the #PR 21979.
What I worked on
-
Added compiler flag "-verror-style=lsp" in dmd
Made changes in mars.d and cli.d to add a new compiler flag 'lsp' to -verror-style. -
Removed the ErrosinkLSP and shifted printLSPdiagnostic() in errors.d
Creating a new ErrorSink for LSP diagnostics was causing unneccessary complications. A simpler approach was to create a printLSPDiagnostic() function in errors.d and call it evrytime instead of printDiagnostic() if the lsp flag was activated (i.e. global.params.v.messageStyle == MessageStyle.lsp).
Challenges
- While the diagnostics are being printed in this format
{
"severity":"Error",
"filename":"file.d",
"line":37,
"column": 10,
"message": "missing semicolon ;"
}
The challenge I am facing is dmd currently calls the verror and verrorSupplemental functions separately i.e. the supplemental message for any diagnostic is called separately after and not along with the diagnostic. Since several error messages do not call for a supplemental message, understanding whether to close the JSON array and print the next diagnostic, or to wait for the printing of the supplemental message, is difficult.
{
"severity":"Error",
"filename":"file.d",
"line":37,
"column": 10,
"message": "missing semicolon ;",
"note":"may or may not be printed"
}
Next Steps
- Create a fail-compilation test for lsp.
- Work on the issue of printing of supplemental messages.
Permalink
Reply