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.
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#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
|