mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:34:42 +01:00
Improve mapping of Clang diagnostics into Carbon diagnostics (#5894)
Instead of taking the complete text of the Clang diagnostic and using it as the message portion of a Carbon diagnostic, generate the individual pieces separately and pass them into the Carbon diagnostic infrastructure. * Clang's context lines are generated by running a custom "diagnostic renderer" and tracking which lines it wants to print as context for a given source location. When mapping from a C++ source location back to a Carbon location, the Carbon `Loc` structure is now fully populated, including filling in the context line and the column number. * Clang's snippet is generated by running a custom diagnostic renderer that is a cut-down version of the full text diagnostic renderer that only prints a snippet. This is then attached to the Carbon diagnostic manually as an override for the snippet we'd usually create. We no longer repeat the file location twice on each diagnostic, and no longer produce a bogus "in import" line for all locations coming from clang that point arbitrarily to the first C++ import in the Carbon file. The `[diagnostic kind]` marker is now displayed at the end of the diagnostic message, not on a line of its own after the snippet.
This commit is contained in:
@@ -17,12 +17,6 @@ static auto FollowImportRef(
|
||||
auto import_ir_inst = cursor_ir->import_ir_insts().Get(import_ir_inst_id);
|
||||
if (import_ir_inst.ir_id() == ImportIRId::Cpp) {
|
||||
CARBON_CHECK(cursor_ir->import_cpps().size() > 0);
|
||||
// TODO: Decompose the Clang source location to determine which C++ import
|
||||
// made this location available, and use the location of that import instead
|
||||
// of arbitrarily using the first C++ import.
|
||||
absolute_node_ids.push_back(
|
||||
AbsoluteNodeId(cursor_ir->check_ir_id(),
|
||||
cursor_ir->import_cpps().values().begin()->node_id));
|
||||
absolute_node_ids.push_back(
|
||||
AbsoluteNodeId(import_ir_inst.clang_source_loc_id()));
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user