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:
1 parent
624c24d028
commit
946b1a005e
15 files changed
+418
-10
No files matched your search
@@ -266,6 +266,11 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
capabilities.emplace("selectionRangeProvider", Json{true});
|
||||
capabilities.emplace("foldingRangeProvider", Json{true});
|
||||
}
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
capabilities.emplace(
|
||||
"codeActionProvider",
|
||||
Json{Json::Object{
|
||||
{"codeActionKinds", Json{Json::Array{Json{std::string{"quickfix"}}}}}}});
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences()) {
|
||||
capabilities.emplace("hoverProvider", Json{true});
|
||||
capabilities.emplace("definitionProvider", Json{true});
|
||||
@@ -373,6 +378,32 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
}
|
||||
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
|
||||
}
|
||||
if (*method == "textDocument/codeAction") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
|
||||
const auto *range = member(params, "range");
|
||||
const auto *start = member(range, "start");
|
||||
const auto *end = member(range, "end");
|
||||
const auto coordinate = [](const Json *value,
|
||||
std::string_view key) -> std::optional<std::uint32_t> {
|
||||
const auto *field = member(value, key);
|
||||
const auto *number = field ? std::get_if<std::int64_t>(&field->value) : nullptr;
|
||||
if (!number || *number < 0 ||
|
||||
*number > Void::LanguageServer::Documents::kMaxPositionValue)
|
||||
return std::nullopt;
|
||||
return static_cast<std::uint32_t>(*number);
|
||||
};
|
||||
const auto start_line = coordinate(start, "line"),
|
||||
start_character = coordinate(start, "character");
|
||||
const auto end_line = coordinate(end, "line"), end_character = coordinate(end, "character");
|
||||
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri) || !start_line ||
|
||||
!start_character || !end_line || !end_character)
|
||||
return error(id, -32602, "Expected textDocument.uri and a bounded range");
|
||||
return reply(id, "result",
|
||||
diagnostics_->code_actions(
|
||||
*uri, {{*start_line, *start_character}, {*end_line, *end_character}}));
|
||||
}
|
||||
if (*method == "textDocument/documentSymbol") {
|
||||
if (!diagnostics_)
|
||||
return error(id, -32601, "Method not found");
|
||||
|
||||
Reference in new issue
Block a user