Serve reference code lenses and the showReferences command
A bounded core builds one lens per document position with its proven reference count. EditorDiagnostics counts index records by name and definition and serves textDocument/codeLens; workspace/executeCommand implements vls.showReferences via the navigation binding. Registered feature tests cover titles, arguments, deduplication and bounds. A real stdio session showed the one-reference lens at the fnv1a64 call and resolved it to the source location.
This commit is contained in:
1 parent
ec86a79a1a
commit
0bf5873069
12 files changed
+279
-5
No files matched your search
@@ -312,6 +312,14 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
}
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
capabilities.emplace("callHierarchyProvider", Json{true});
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences()) {
|
||||
capabilities.emplace("codeLensProvider",
|
||||
Json{Json::Object{{"resolveProvider", Json{false}}}});
|
||||
capabilities.emplace(
|
||||
"executeCommandProvider",
|
||||
Json{Json::Object{
|
||||
{"commands", Json{Json::Array{Json{std::string{"vls.showReferences"}}}}}}});
|
||||
}
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
capabilities.emplace("inlayHintProvider", Json{true});
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
@@ -434,6 +442,40 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
}
|
||||
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
|
||||
}
|
||||
if (*method == "textDocument/codeLens") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
|
||||
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri))
|
||||
return error(id, -32602, "Expected textDocument.uri");
|
||||
return reply(id, "result", diagnostics_->code_lenses(*uri));
|
||||
}
|
||||
if (*method == "workspace/executeCommand") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
const auto *command = as_string(member(params, "command"));
|
||||
const auto *arguments = as_array(member(params, "arguments"));
|
||||
if (!command || !arguments || arguments->size() != 2)
|
||||
return error(id, -32602, "Expected a command and two arguments");
|
||||
if (*command != "vls.showReferences")
|
||||
return error(id, -32601, "Unregistered command");
|
||||
const auto *uri = as_string(&(*arguments)[0]);
|
||||
const auto *position = as_object(&(*arguments)[1]);
|
||||
const auto line = position ? find_member(*position, "line") : nullptr;
|
||||
const auto character = position ? find_member(*position, "character") : nullptr;
|
||||
const auto *line_value = line ? std::get_if<std::int64_t>(&line->value) : nullptr;
|
||||
const auto *character_value =
|
||||
character ? std::get_if<std::int64_t>(&character->value) : nullptr;
|
||||
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri) || !line_value ||
|
||||
!character_value || *line_value < 0 || *character_value < 0 ||
|
||||
*line_value > Void::LanguageServer::Documents::kMaxPositionValue ||
|
||||
*character_value > Void::LanguageServer::Documents::kMaxPositionValue)
|
||||
return error(id, -32602, "Expected textDocument.uri and a bounded position");
|
||||
auto navigation =
|
||||
diagnostics_->references(*uri, {static_cast<std::uint32_t>(*line_value),
|
||||
static_cast<std::uint32_t>(*character_value)});
|
||||
return reply(id, "result", std::move(navigation.result));
|
||||
}
|
||||
if (*method == "textDocument/prepareCallHierarchy") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
|
||||
Reference in new issue
Block a user