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
@@ -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 |
|
||||
| Overload-set signature help | only the selected occurrence's signature is available |
|
||||
| textDocument/formatting | needs a plan |
|
||||
| callHierarchy / typeHierarchy | incoming-call core is implemented and tested (`vls_features::call_hierarchy`); server wiring and type hierarchy are open |
|
||||
| callHierarchy / typeHierarchy | callHierarchy prepare + incomingCalls are implemented and verified over stdio; type hierarchy and outgoing calls are open |
|
||||
| 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 |
|
||||
| Applying multi-file renames through client buffers | plans can be ready; application is client work |
|
||||
|
||||
@@ -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
|
||||
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. 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. Compiler-native completion with visibility proof and deferred detail resolution remain open.
|
||||
|
||||
The reflection provenance representation (roadmap 12 first slice) is
|
||||
implemented as a bounded library with a registered suite: innermost-first
|
||||
|
||||
@@ -79,6 +79,25 @@ 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
|
||||
passed 18/18.
|
||||
|
||||
## December 5 call hierarchy over LSP
|
||||
|
||||
`EditorDiagnostics::call_hierarchy_prepare` turns a covering occurrence with a
|
||||
definition into one `CallHierarchyItem` (callee name, definition URI and range,
|
||||
data carrying the full definition span). `call_hierarchy_incoming` feeds every
|
||||
known occurrence and definition into the bounded core
|
||||
(`vls/features/CallHierarchy.hpp`) and renders `CallHierarchyIncomingCall`
|
||||
entries grouped by the innermost enclosing definition, or explicitly at file
|
||||
level (kind File) when none contains the call. The server advertises
|
||||
`callHierarchyProvider` and serves `textDocument/prepareCallHierarchy` and
|
||||
`callHierarchy/incomingCalls`.
|
||||
|
||||
Real stdio session with the stock observer at the `fnv1a64(text)` call:
|
||||
```
|
||||
prepareCallHierarchy: 1 first: [('fnv1a64', 'Hash.hpp')]
|
||||
incomingCalls: 1 first: [('DocumentSnapshot.cpp', 1, 1)]
|
||||
```
|
||||
All 18 native suites and all 18 CMake tests passed.
|
||||
|
||||
## December 5 include updates on file rename
|
||||
|
||||
`include/vls/features/IncludeUpdate.hpp` finds quoted include directives that
|
||||
|
||||
@@ -66,6 +66,12 @@ class EditorDiagnostics {
|
||||
Documents::Range range) const;
|
||||
// Semantic tokens for the document's proven occurrences, delta-encoded.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json semantic_tokens(std::string_view uri) const;
|
||||
// Call hierarchy at a call position: the callee definition as one item.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
call_hierarchy_prepare(std::string_view uri, Documents::Position position) const;
|
||||
// Incoming calls of a prepared item, grouped by enclosing definition.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
call_hierarchy_incoming(const Void::LanguageServer::Protocol::Json &item) const;
|
||||
// Parameter-type hints from the compiler signature, within the range.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json inlay_hints(std::string_view uri,
|
||||
Documents::Range range) const;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <vls/semantic/EditorDiagnostics.hpp>
|
||||
|
||||
#include <vls/features/CallHierarchy.hpp>
|
||||
#include <vls/features/CodeActions.hpp>
|
||||
#include <vls/features/Completion.hpp>
|
||||
#include <vls/features/DocumentSymbols.hpp>
|
||||
@@ -1394,6 +1395,114 @@ EditorDiagnostics::NavigationReply EditorDiagnostics::rename(std::string_view ur
|
||||
return {Json{Json::Object{{"changes", Json{std::move(changes)}}}}, std::nullopt};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::call_hierarchy_prepare(std::string_view uri,
|
||||
Documents::Position position) const {
|
||||
auto &s = *state_;
|
||||
auto key = Documents::client_uri_key(uri);
|
||||
std::shared_ptr<const Receipt> receipt;
|
||||
std::shared_ptr<const std::vector<Occurrence>> facts;
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
const auto i = key ? s.entries.find(*key) : s.entries.end();
|
||||
if (i == s.entries.end())
|
||||
return Json{Json::Array{}};
|
||||
receipt = i->second.receipt;
|
||||
facts = i->second.occurrences;
|
||||
}
|
||||
if (!receipt || !facts || !s.valid(*receipt))
|
||||
return Json{Json::Array{}};
|
||||
const auto *match = covering(*receipt, *facts, *key, position);
|
||||
if (!match || !match->has_definition())
|
||||
return Json{Json::Array{}};
|
||||
const auto &target = *match->definition_file;
|
||||
const auto target_uri = target.identity.is_file_uri
|
||||
? target.identity.canonical_uri
|
||||
: Documents::path_to_file_uri(target.identity.canonical_path);
|
||||
const auto range = range_json(match->definition);
|
||||
Json::Array items;
|
||||
items.push_back(Json{Json::Object{
|
||||
{"name", Json{match->name}},
|
||||
{"kind", Json{std::int64_t{12}}},
|
||||
{"uri", Json{target_uri}},
|
||||
{"range", range},
|
||||
{"selectionRange", range},
|
||||
{"data",
|
||||
Json{Json::Object{
|
||||
{"name", Json{match->name}},
|
||||
{"path", Json{target.identity.canonical_path.native()}},
|
||||
{"line", Json{static_cast<std::int64_t>(match->definition.start.line)}},
|
||||
{"character", Json{static_cast<std::int64_t>(match->definition.start.character)}},
|
||||
{"endLine", Json{static_cast<std::int64_t>(match->definition.end.line)}},
|
||||
{"endCharacter",
|
||||
Json{static_cast<std::int64_t>(match->definition.end.character)}}}}}}});
|
||||
return Json{std::move(items)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::call_hierarchy_incoming(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 target{
|
||||
*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::incoming(calls, known, target);
|
||||
Json::Array result;
|
||||
for (const auto &caller : grouped) {
|
||||
Json::Array ranges;
|
||||
for (const auto &range : caller.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{{caller.range.start.line, caller.range.start.character},
|
||||
{caller.range.end.line, caller.range.end.character}});
|
||||
Json::Object from{{"name", Json{caller.name}},
|
||||
{"kind", Json{std::int64_t{caller.resolved_definition ? 12 : 1}}},
|
||||
{"uri", Json{Documents::path_to_file_uri(caller.path)}},
|
||||
{"range", span},
|
||||
{"selectionRange", span}};
|
||||
result.push_back(Json{Json::Object{{"from", Json{std::move(from)}},
|
||||
{"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