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:
faumaray committed 2026-12-05 17:03:48 +03:00
1 parent cec4e7d717
commit a098e45dc9
9 files changed
+178 -2

No files matched your search

+1 -1
View File
@@ -34,7 +34,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
| Compiler-native completion with visibility proof | index-backed completion is explicitly incomplete | | Compiler-native completion with visibility proof | index-backed completion is explicitly incomplete |
| Overload-set signature help | only the selected occurrence's signature is available | | Overload-set signature help | only the selected occurrence's signature is available |
| textDocument/formatting | needs a plan | | textDocument/formatting | needs a plan |
| callHierarchy / typeHierarchy | callHierarchy prepare + incomingCalls are implemented and verified over stdio; type hierarchy and outgoing calls are open | | callHierarchy / typeHierarchy | prepare, incomingCalls and outgoingCalls are implemented and served; outgoing results need full function extents from the compiler (the observed span is the declarator only). Type hierarchy is open. |
| textDocument/codeLens, executeCommand | command surface not designed | | textDocument/codeLens, executeCommand | command surface not designed |
| Client-side application of server-issued workspace edits | rename and code actions return edits the clients apply directly | | Client-side application of server-issued workspace edits | rename and code actions return edits the clients apply directly |
| Applying multi-file renames through client buffers | plans can be ready; application is client work | | Applying multi-file renames through client buffers | plans can be ready; application is client work |
+1 -1
View File
@@ -102,7 +102,7 @@ ingests occurrence facts after each analysis and the server answers
Hash.hpp definition through it. Real persistence migrations and cross-file Hash.hpp definition through it. Real persistence migrations and cross-file
rename coverage remain open. rename coverage remain open.
Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences with a bounded one-type legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Compiler-native completion with visibility proof and deferred detail resolution remain open. Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences with a bounded one-type legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served too, but the observer's declarator-only definition span limits attribution to the core tests for now. Compiler-native completion with visibility proof and deferred detail resolution remain open.
The reflection provenance representation (roadmap 12 first slice) is The reflection provenance representation (roadmap 12 first slice) is
implemented as a bounded library with a registered suite: innermost-first implemented as a bounded library with a registered suite: innermost-first
+14
View File
@@ -79,6 +79,20 @@ the upgraded snapshot (keeping `snapshot.prev.json`) and rewrites a legacy
about 25-30s in a Debug build (it passed VBS at ~27s); the full CMake run then about 25-30s in a Debug build (it passed VBS at ~27s); the full CMake run then
passed 18/18. passed 18/18.
## December 5 outgoing call hierarchy
`callHierarchy/outgoingCalls` is wired through
`EditorDiagnostics::call_hierarchy_outgoing` to the core `outgoing`, which
attributes each resolved call to the innermost known definition containing it
and groups the results by callee definition. Registered `vls_feature_tests`
cases cover grouping, innermost attribution, unresolved-callee omission and
bounds. A real stdio session with nested calls
(`int outer() { return inner() + inner(); }`) prepared `outer` and reported its
incoming call, but outgoing was empty: the observer's definition span is the
declarator only (`outer` at 1:4-1:9), so a call in the body cannot be attributed
to it without guessing. Extending the compiler to report full function extents
is the prerequisite for real outgoing results.
## December 5 call hierarchy over LSP ## December 5 call hierarchy over LSP
`EditorDiagnostics::call_hierarchy_prepare` turns a covering occurrence with a `EditorDiagnostics::call_hierarchy_prepare` turns a covering occurrence with a
+14
View File
@@ -60,4 +60,18 @@ struct Limits {
std::span<const Definition> known, std::span<const Definition> known,
const Definition &target, const Limits & = Limits{}); const Definition &target, const Limits & = Limits{});
struct Outgoing {
Definition to;
std::vector<Range> from_ranges;
auto operator<=>(const Outgoing &) const = default;
};
// Calls made inside CALLER, grouped by their resolved callee definition.
// A call is attributed to the innermost known definition containing it in the
// same file, so calls inside nested functions are not reported for CALLER.
// Calls without a resolved callee are omitted: an item must point somewhere.
[[nodiscard]] std::vector<Outgoing> outgoing(std::span<const Call>,
std::span<const Definition> known,
const Definition &caller, const Limits & = Limits{});
} // namespace vls::features::call_hierarchy } // namespace vls::features::call_hierarchy
@@ -72,6 +72,9 @@ class EditorDiagnostics {
// Incoming calls of a prepared item, grouped by enclosing definition. // Incoming calls of a prepared item, grouped by enclosing definition.
[[nodiscard]] Void::LanguageServer::Protocol::Json [[nodiscard]] Void::LanguageServer::Protocol::Json
call_hierarchy_incoming(const Void::LanguageServer::Protocol::Json &item) const; call_hierarchy_incoming(const Void::LanguageServer::Protocol::Json &item) const;
// Calls made inside a prepared item's function.
[[nodiscard]] Void::LanguageServer::Protocol::Json
call_hierarchy_outgoing(const Void::LanguageServer::Protocol::Json &item) const;
// Parameter-type hints from the compiler signature, within the range. // Parameter-type hints from the compiler signature, within the range.
[[nodiscard]] Void::LanguageServer::Protocol::Json inlay_hints(std::string_view uri, [[nodiscard]] Void::LanguageServer::Protocol::Json inlay_hints(std::string_view uri,
Documents::Range range) const; Documents::Range range) const;
+8
View File
@@ -454,6 +454,14 @@ DispatchResult Server::handle(std::string_view body) {
*uri, {static_cast<std::uint32_t>(*line_value), *uri, {static_cast<std::uint32_t>(*line_value),
static_cast<std::uint32_t>(*character_value)})); static_cast<std::uint32_t>(*character_value)}));
} }
if (*method == "callHierarchy/outgoingCalls") {
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_outgoing(*item));
}
if (*method == "callHierarchy/incomingCalls") { if (*method == "callHierarchy/incomingCalls") {
if (!diagnostics_ || !diagnostics_->supports_occurrences()) if (!diagnostics_ || !diagnostics_->supports_occurrences())
return error(id, -32601, "Method not found"); return error(id, -32601, "Method not found");
+36
View File
@@ -64,4 +64,40 @@ std::vector<Incoming> incoming(std::span<const Call> calls, std::span<const Defi
return result; return result;
} }
std::vector<Outgoing> outgoing(std::span<const Call> calls, std::span<const Definition> known,
const Definition &caller, const Limits &limits) {
std::map<std::tuple<std::string, std::string, Range>, Outgoing> grouped;
std::size_t total_ranges{};
for (const auto &call : calls) {
if (!call.callee_definition)
continue;
const Definition *enclosing{};
for (const auto &definition : known) {
if (definition.path != call.path || !contains(definition.range, call.range))
continue;
if (!enclosing || definition.range.start > enclosing->range.start)
enclosing = &definition;
}
if (!enclosing || *enclosing != caller)
continue;
auto &slot = grouped[{call.callee_definition->name, call.callee_definition->path,
call.callee_definition->range}];
if (slot.to.name.empty())
slot.to = *call.callee_definition;
if (slot.from_ranges.size() < limits.ranges && total_ranges < limits.ranges &&
std::ranges::find(slot.from_ranges, call.range) == slot.from_ranges.end()) {
slot.from_ranges.push_back(call.range);
++total_ranges;
}
}
std::vector<Outgoing> result;
for (auto &[key, entry] : grouped) {
if (result.size() == limits.callers)
break;
std::ranges::sort(entry.from_ranges);
result.push_back(std::move(entry));
}
return result;
}
} // namespace vls::features::call_hierarchy } // namespace vls::features::call_hierarchy
+65
View File
@@ -1503,6 +1503,71 @@ Json EditorDiagnostics::call_hierarchy_incoming(const Json &item) const {
return Json{std::move(result)}; 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 { Json EditorDiagnostics::hover(std::string_view uri, Documents::Position position) const {
auto &s = *state_; auto &s = *state_;
auto key = Documents::client_uri_key(uri); auto key = Documents::client_uri_key(uri);
+36
View File
@@ -88,3 +88,39 @@ VOID_TEST(CallHierarchy, callers_and_ranges_are_bounded) {
ranges += entry.from_ranges.size(); ranges += entry.from_ranges.size();
expect(ranges == 1); expect(ranges == 1);
} }
VOID_TEST(CallHierarchy, outgoing_reports_calls_inside_the_caller) {
const auto inner = definition("inner", "/p/a.cpp", range(1));
const std::vector<Definition> known{definition("outer", "/p/a.cpp", {{0, 0}, {20, 0}}), inner};
const std::vector<Call> calls{call("inner", inner, "/p/a.cpp", range(6)),
call("inner", inner, "/p/a.cpp", range(7))};
const auto result = outgoing(calls, known, known.front());
require(result.size() == 1);
expect(result.front().to == inner);
require(result.front().from_ranges.size() == 2);
expect(result.front().from_ranges[0] == range(6));
}
VOID_TEST(CallHierarchy, outgoing_attributes_nested_calls_to_the_innermost_definition) {
const auto inner = definition("inner", "/p/a.cpp", range(1));
const auto nested = definition("nested", "/p/a.cpp", {{5, 0}, {9, 0}});
const std::vector<Definition> known{definition("outer", "/p/a.cpp", {{0, 0}, {20, 0}}), nested,
inner};
const std::vector<Call> calls{call("inner", inner, "/p/a.cpp", range(6)),
call("inner", inner, "/p/a.cpp", range(15))};
const auto outer_result = outgoing(calls, known, known.front());
require(outer_result.size() == 1);
expect(outer_result.front().from_ranges == std::vector<Range>{range(15)});
const auto nested_result = outgoing(calls, known, nested);
require(nested_result.size() == 1);
expect(nested_result.front().from_ranges == std::vector<Range>{range(6)});
}
VOID_TEST(CallHierarchy, outgoing_skips_unresolved_callees_and_bounds_groups) {
const auto inner = definition("inner", "/p/a.cpp", range(1));
const std::vector<Definition> known{definition("outer", "/p/a.cpp", {{0, 0}, {20, 0}})};
const std::vector<Call> calls{{"missing", std::nullopt, "/p/a.cpp", range(6)},
call("inner", inner, "/p/a.cpp", range(7))};
require(outgoing(calls, known, known.front()).size() == 1);
expect(outgoing(calls, known, known.front(), Limits{.callers = 0}).empty());
}