Open FStefanni opened 1 year ago
Agreed, this is important context for understanding a diagnostic. I would expect clangd to produce a "note" of the form "In file included from <filename>
" for every element of the include chain, similar to how the compiler would display the diagnostic on the command line.
(Transferred to the clangd repo as the issue is on the server side. The textDocument/publishDiagnostics
notification does not currently contain information about the intermediate elements of the include chain.)
Came here to report basically exactly this, except in my situation it's even worse:
Clangd points to the top level include as being where the problem is, so I have no idea where the actual error is!
IE, in main.cpp:
Clangd will report an error at line 1 "in file included from main.cpp".
To diagnose the error, I'm forced to extract the commandline and run under clang, which more helpfully reports the entire chain of errors.
Some notes on this for future reference:
DiagnosticConsumer
implementation (clang::TextDiagnosticPrinter
)
DiagnosticRenderer::emitIncludeStack
DiagnosticConsumer
implementation which does not do thisNote that the include chain entries are not represented in the clang API as "notes" (which are distinct diagnostics with the diagnostic level Note
), they're just lines printed as an implementation detail of printing a main diagnostic. To get them to show up in clients, the clangd DiagnosticConsumer
will likely need to turn them into distinct diagnostics with LSP DiagnosticSeverity.Information
.
Hi,
not sure if this is where to report this feature request. Basically, when there is an error into an included file, the message reports something like this:
This make the error not so trivial to fix, since it only report the header name where the error originates, but not all the includes hierarchy to arrive to that include file.
For example, this would be more useful:
This is especially useful in cases where we are maybe cross-compiling, or in complex setups where we have to specify to clangd custom include paths, and the error is basically that clangd comes up to see as included the wrong file (i.e., in the example exist two different otherHeader.h files, and the one causing the error is the wrong one).
Regards