Offer compiler quick fixes as code actions

Decode GCC SARIF fixes into bounded diagnostic edits through the same
physical-origin policy as locations; unprovable regions are dropped. A
bounded projection filters fixes to the requested range, deduplicates
and bounds them, and textDocument/codeAction serves them from retained
published diagnostics. Registered tests cover the SARIF binding and the
projection; a real stdio session returned the compiler's
Replace 'valu' with 'value' quickfix.
This commit is contained in:
faumaray committed 2026-12-05 15:03:21 +03:00
1 parent 624c24d028
commit 946b1a005e
15 files changed
+418 -10

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <vector>
namespace vls::features::code_actions {
struct Position {
std::uint32_t line{}, character{};
auto operator<=>(const Position &) const = default;
};
struct Range {
Position start, end;
auto operator<=>(const Range &) const = default;
};
struct Edit {
Range range;
std::string replacement;
auto operator<=>(const Edit &) const = default;
};
// One compiler-suggested fix: its title, the file it edits and its edits.
struct Fix {
std::string title;
std::string path;
std::vector<Edit> edits;
};
struct Action {
std::string title;
std::string path;
std::vector<Edit> edits;
auto operator<=>(const Action &) const = default;
};
struct Limits {
std::size_t actions{64};
std::size_t edits{8};
std::size_t titleBytes{256};
std::size_t editBytes{4096};
};
// Keeps fixes with at least one edit intersecting the requested range, drops
// empty or malformed fixes, deduplicates identical edits and actions, and
// bounds every field. Order is the input order.
[[nodiscard]] std::vector<Action> actions(std::span<const Fix>, Range requested,
const Limits & = Limits{});
} // namespace vls::features::code_actions
+13
View File
@@ -90,11 +90,24 @@ struct RelatedLocation {
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<DiagnosticEdit> edits;
};
struct CompilerDiagnostic {
DiagnosticSeverity severity;
std::string message, rule;
DiagnosticLocation location;
std::vector<RelatedLocation> related;
// Bounded compiler-suggested fixes. An edit whose region cannot be proven
// in the owner snapshot is dropped, never guessed.
std::vector<DiagnosticFix> fixes;
};
struct DiagnosticBatch {
std::string invocation_id, input_view_id;
@@ -48,6 +48,10 @@ class EditorDiagnostics {
selection_ranges(std::string_view uri, std::span<const Documents::Position>) const;
// Foldable brace blocks, comments, regions and include groups.
[[nodiscard]] Void::LanguageServer::Protocol::Json folding_ranges(std::string_view uri) const;
// Quick fixes suggested by the compiler for diagnostics overlapping the
// requested range. Only fixes proven in the owner snapshot are offered.
[[nodiscard]] Void::LanguageServer::Protocol::Json code_actions(std::string_view uri,
Documents::Range range) const;
struct NavigationReply {
Void::LanguageServer::Protocol::Json result;