#pragma once #include #include #include #include #include #include #include #include #include #include #include namespace vls::semantic { namespace Documents = Void::LanguageServer::Documents; using DiagnosticSnapshot = std::shared_ptr; // GCC can emit literal filenames, including percent signs. These spellings are // supplied by the launcher and are compared exactly, without URL decoding. struct ArtifactName { std::string uri, base_uri; auto operator<=>(const ArtifactName &) const = default; }; struct DiagnosticArtifact { ArtifactName name; DiagnosticSnapshot snapshot; }; struct ReportedRegion { std::uint32_t first_line, first_column, last_line, end_column; }; enum class ColumnUnit { ascii_consensus, utf8_bytes, gcc_display }; enum class FirstLineBom { unknown, counted, skipped }; struct CoordinatePolicy { ColumnUnit unit{ColumnUnit::ascii_consensus}; unsigned tabstop{8}; FirstLineBom bom{FirstLineBom::unknown}; }; struct LocationRequest { const DiagnosticArtifact &artifact; ReportedRegion region; std::size_t result_index, location_index; bool related; }; struct DiagnosticJob { std::string invocation_id, input_view_id; DiagnosticSnapshot owner; std::vector artifacts; // The input owner accounts for unresolved includes and lookup dependencies. bool inputs_complete{}; // Return a policy only for a proven physical location in the immutable // inputs. A matching snippet cannot establish the origin of a #line remap. std::function(const LocationRequest &)> physical_origin; }; struct DiagnosticOutput { std::string_view invocation_id, input_view_id; std::optional exit_code; bool stream_complete{}; std::string_view sarif; }; enum class DiagnosticError { invalid_job, wrong_capture, incomplete_stream, failed_process, malformed_report, unsupported_report, wrong_owner, tool_failure, resource_limit }; enum class LocationGap { none, no_location, unknown_artifact, artifact_mismatch, incomplete_region, unproven_origin, ambiguous_column }; struct DiagnosticLocation { LocationGap gap{LocationGap::no_location}; DiagnosticSnapshot snapshot; std::optional range; }; struct RelatedLocation { std::string message; DiagnosticLocation location; }; enum class DiagnosticSeverity { error, warning, information, hint }; // One replacement from a compiler-suggested fix, in the owner snapshot's // negotiated coordinates. struct DiagnosticEdit { Documents::Range range; std::string replacement; }; struct DiagnosticFix { std::string description; std::vector edits; }; struct CompilerDiagnostic { DiagnosticSeverity severity; std::string message, rule; DiagnosticLocation location; std::vector related; // Bounded compiler-suggested fixes. An edit whose region cannot be proven // in the owner snapshot is dropped, never guessed. std::vector fixes; }; struct DiagnosticBatch { std::string invocation_id, input_view_id; DiagnosticSnapshot owner; std::vector diagnostics; // The publisher must still validate that this invocation is current. bool complete_for_owner{}; }; [[nodiscard]] std::expected decode_gcc_diagnostics(const DiagnosticJob &, const DiagnosticOutput &); } // namespace vls::semantic