Serve outgoing call hierarchy
callHierarchy/outgoingCalls groups calls attributed to the prepared function's innermost enclosing definition by callee, with registered core tests for grouping, innermost attribution, unresolved-callee omission and bounds. Real stdio evidence shows the observer reports only the declarator span, so body calls cannot be attributed without guessing; the matrix records that limitation.
This commit is contained in:
1 parent
cec4e7d717
commit
a098e45dc9
9 files changed
+178
-2
No files matched your search
@@ -1503,6 +1503,71 @@ Json EditorDiagnostics::call_hierarchy_incoming(const Json &item) const {
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::call_hierarchy_outgoing(const Json &item) const {
|
||||
auto &s = *state_;
|
||||
const auto *fields = P::as_object(&item);
|
||||
const auto *data = fields ? P::as_object(P::find_member(*fields, "data")) : nullptr;
|
||||
const auto *name = data ? P::as_string(P::find_member(*data, "name")) : nullptr;
|
||||
const auto *path = data ? P::as_string(P::find_member(*data, "path")) : nullptr;
|
||||
const auto line = data ? P::as_int64(P::find_member(*data, "line")) : std::nullopt;
|
||||
const auto character = data ? P::as_int64(P::find_member(*data, "character")) : std::nullopt;
|
||||
const auto end_line = data ? P::as_int64(P::find_member(*data, "endLine")) : std::nullopt;
|
||||
const auto end_character =
|
||||
data ? P::as_int64(P::find_member(*data, "endCharacter")) : std::nullopt;
|
||||
if (!name || !path || !line || !character || !end_line || !end_character)
|
||||
return Json{Json::Array{}};
|
||||
const features::call_hierarchy::Definition caller{
|
||||
*name,
|
||||
*path,
|
||||
{{static_cast<std::uint32_t>(*line), static_cast<std::uint32_t>(*character)},
|
||||
{static_cast<std::uint32_t>(*end_line), static_cast<std::uint32_t>(*end_character)}}};
|
||||
std::vector<features::call_hierarchy::Call> calls;
|
||||
std::vector<features::call_hierarchy::Definition> known;
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
for (const auto &[key, entry] : s.entries) {
|
||||
if (!entry.occurrences)
|
||||
continue;
|
||||
for (const auto &occurrence : *entry.occurrences) {
|
||||
features::call_hierarchy::Call call;
|
||||
call.callee = occurrence.name;
|
||||
call.path = occurrence.use_file->identity.canonical_path.native();
|
||||
call.range = {{occurrence.use.start.line, occurrence.use.start.character},
|
||||
{occurrence.use.end.line, occurrence.use.end.character}};
|
||||
if (occurrence.has_definition()) {
|
||||
features::call_hierarchy::Definition definition{
|
||||
occurrence.name,
|
||||
occurrence.definition_file->identity.canonical_path.native(),
|
||||
{{occurrence.definition.start.line, occurrence.definition.start.character},
|
||||
{occurrence.definition.end.line, occurrence.definition.end.character}}};
|
||||
call.callee_definition = definition;
|
||||
known.push_back(std::move(definition));
|
||||
}
|
||||
calls.push_back(std::move(call));
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto grouped = features::call_hierarchy::outgoing(calls, known, caller);
|
||||
Json::Array result;
|
||||
for (const auto &callee : grouped) {
|
||||
Json::Array ranges;
|
||||
for (const auto &range : callee.from_ranges)
|
||||
ranges.push_back(range_json(Documents::Range{{range.start.line, range.start.character},
|
||||
{range.end.line, range.end.character}}));
|
||||
const auto span = range_json(
|
||||
Documents::Range{{callee.to.range.start.line, callee.to.range.start.character},
|
||||
{callee.to.range.end.line, callee.to.range.end.character}});
|
||||
Json::Object to{{"name", Json{callee.to.name}},
|
||||
{"kind", Json{std::int64_t{12}}},
|
||||
{"uri", Json{Documents::path_to_file_uri(callee.to.path)}},
|
||||
{"range", span},
|
||||
{"selectionRange", span}};
|
||||
result.push_back(Json{
|
||||
Json::Object{{"to", Json{std::move(to)}}, {"fromRanges", Json{std::move(ranges)}}}});
|
||||
}
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::hover(std::string_view uri, Documents::Position position) const {
|
||||
auto &s = *state_;
|
||||
auto key = Documents::client_uri_key(uri);
|
||||
|
||||
Reference in new issue
Block a user