Serve call hierarchy from stock call facts
prepareCallHierarchy returns the callee definition as one item, and callHierarchy/incomingCalls groups resolved call sites by the innermost compiler-proven enclosing definition, falling back to an explicit file-level caller. The server advertises callHierarchyProvider. A real stdio session with the stock observer prepared fnv1a64 (Hash.hpp) and reported one incoming call from DocumentSnapshot.cpp.
This commit is contained in:
1 parent
555ccecd65
commit
cec4e7d717
6 files changed
+166
-2
No files matched your search
@@ -310,6 +310,8 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
capabilities.emplace("selectionRangeProvider", Json{true});
|
||||
capabilities.emplace("foldingRangeProvider", Json{true});
|
||||
}
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
capabilities.emplace("callHierarchyProvider", Json{true});
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
capabilities.emplace("inlayHintProvider", Json{true});
|
||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||
@@ -432,6 +434,34 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
}
|
||||
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
|
||||
}
|
||||
if (*method == "textDocument/prepareCallHierarchy") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
|
||||
const auto *position = member(params, "position");
|
||||
const auto *line = position ? member(position, "line") : nullptr;
|
||||
const auto *character = position ? 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");
|
||||
return reply(id, "result",
|
||||
diagnostics_->call_hierarchy_prepare(
|
||||
*uri, {static_cast<std::uint32_t>(*line_value),
|
||||
static_cast<std::uint32_t>(*character_value)}));
|
||||
}
|
||||
if (*method == "callHierarchy/incomingCalls") {
|
||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||
return error(id, -32601, "Method not found");
|
||||
const auto *item = member(params, "item");
|
||||
if (!item)
|
||||
return error(id, -32602, "Expected a call hierarchy item");
|
||||
return reply(id, "result", diagnostics_->call_hierarchy_incoming(*item));
|
||||
}
|
||||
if (*method == "workspace/willRenameFiles") {
|
||||
if (!diagnostics_)
|
||||
return error(id, -32601, "Method not found");
|
||||
|
||||
Reference in new issue
Block a user