diff --git a/docs/agent-workflow/LSP-PARITY.md b/docs/agent-workflow/LSP-PARITY.md index 93f2ac0..ab276bc 100644 --- a/docs/agent-workflow/LSP-PARITY.md +++ b/docs/agent-workflow/LSP-PARITY.md @@ -12,6 +12,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints. | textDocument sync (full + incremental, UTF-8/UTF-16) | document suite, real stdio corpora | | publishDiagnostics (stock GCC, in-process default profile) | diagnostic suite, stdio corpus | | textDocument/hover, definition | stock occurrence corpus | +| textDocument/hover over reflection snapshots | recorded-snapshot stdio session | | textDocument/references, prepareRename, rename | navigation suite, stock corpus refusals | | textDocument/completion (+ completionItem/resolve) | `vls_feature_tests`, real stdio session | | textDocument/signatureHelp | `vls_feature_tests`, real stdio session | @@ -39,7 +40,6 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints. | callHierarchy / typeHierarchy | prepare, incomingCalls and outgoingCalls are implemented and served; outgoing calls are verified over stdio now that the observer reports full function extents. Type hierarchy is open. | | 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 | -| `EditorDiagnostics` reflection LSP wiring | the server has no reflection data source | | richer token types | legend is one type (`function`) plus a `declaration` modifier; type tokens need compiler-provided spans | | textDocument/formatting | no formatter is available; needs a dependency decision | diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index f8df37f..15df337 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -103,7 +103,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 and same-file definition names, the latter with a declaration modifier, under a bounded 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. Document links resolve quoted includes to existing files without the compiler. Code lenses show index reference counts and the `vls.showReferences` command resolves them to navigation locations. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. 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 and same-file definition names, the latter with a declaration modifier, under a bounded 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. Reflection hover is served from a recorded snapshot file selected at launch, with the client position converted through the document snapshot. Document links resolve quoted includes to existing files without the compiler. Code lenses show index reference counts and the `vls.showReferences` command resolves them to navigation locations. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. 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 diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 7960eeb..cd8fcdf 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -79,6 +79,26 @@ 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 reflection hover from a recorded snapshot + +Per the user's decision, `EditorDiagnostics` reflection data now comes from a +recorded snapshot file: the launcher accepts `--reflection-snapshot PATH` +(absolute existing file, requires a workspace root) and the server parses it +with the versioned `reflection::Snapshot::parse` at startup. +`reflection::hover_at` selects the innermost entity whose provenance chain +covers a position and returns its bounded virtual view, and the server's hover +falls back to it after compiler-occurrence hover (converting the client position +through the document snapshot because reflection columns are bytes). A +malformed snapshot is ignored rather than served partially. + +Real stdio session with a recorded entity covering `main.cpp:0:8-0:13`: +``` +hover inside: {"contents": {"kind": "markdown", "value": "```text\nReady : Ready\n value : int = 17\n```\n\nSources:\n- `.../main.cpp:0:8`\n"}} +hover outside: null +``` +Registered `vls_reflection_tests` grew to 25 cases. All 18 native suites and +all 18 CMake tests passed. + ## December 5 document links for includes `include/vls/features/DocumentLinks.hpp` resolves quoted include directives diff --git a/include/vls/Server.hpp b/include/vls/Server.hpp index 4d8b1f6..f2b11af 100644 --- a/include/vls/Server.hpp +++ b/include/vls/Server.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,7 @@ class Server { Void::LanguageServer::Documents::DocumentStore documents_; WorkspaceSession workspace_; std::unique_ptr diagnostics_; + std::shared_ptr reflection_; }; // Thin transport loop shared by the executable and stream-failure unit tests. diff --git a/include/vls/WorkspaceSession.hpp b/include/vls/WorkspaceSession.hpp index 2311191..63083ed 100644 --- a/include/vls/WorkspaceSession.hpp +++ b/include/vls/WorkspaceSession.hpp @@ -22,6 +22,8 @@ struct WorkspaceLaunch { std::optional user_settings, cli_settings; std::shared_ptr diagnostics_profile{}; + // Versioned reflection provenance snapshot served as read-only hover. + std::optional reflection_snapshot; }; struct SemanticDriver { diff --git a/include/vls/reflection/Provenance.hpp b/include/vls/reflection/Provenance.hpp index 71186f5..34de89d 100644 --- a/include/vls/reflection/Provenance.hpp +++ b/include/vls/reflection/Provenance.hpp @@ -240,4 +240,14 @@ struct SpliceOrigin { // chain for an identity wins and the result stays within the snapshot limits. [[nodiscard]] Snapshot snapshot_from_splices(std::span, Limits = Limits{}); +struct Position { + std::uint32_t line{}, character{}; + auto operator<=>(const Position &) const = default; +}; + +// Hover for the innermost entity whose provenance chain covers POSITION in +// PATH. Ranges are compiler byte columns; an absent match is null rather +// than a lexical guess. +[[nodiscard]] std::optional hover_at(const Snapshot &, std::string_view path, Position, + const Limits & = Limits{}); } // namespace vls::reflection diff --git a/src/Server.cpp b/src/Server.cpp index c6fbe43..23b617d 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -132,6 +134,15 @@ DispatchResult error(const Json &id, std::int64_t code, std::string_view message } // namespace Server::Server(WorkspaceLaunch launch, std::function send) : workspace_(launch) { + if (launch.reflection_snapshot) { + std::ifstream stream{*launch.reflection_snapshot, std::ios::binary}; + std::string bytes{std::istreambuf_iterator{stream}, {}}; + if (!bytes.empty()) { + auto parsed = reflection::Snapshot::parse(bytes); + if (parsed) + reflection_ = std::make_shared(std::move(*parsed)); + } + } if (launch.root && launch.diagnostics_profile && send) diagnostics_ = std::make_unique( *launch.root, std::move(launch.diagnostics_profile), workspace_, documents_, @@ -380,6 +391,44 @@ DispatchResult Server::handle(std::string_view body) { diagnostics_ ? diagnostics_->status(*uri) : Json{Json::Object{{"state", Json{std::string{"disabled"}}}}}); } + if (*method == "textDocument/hover" && reflection_) { + 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(&line->value) : nullptr; + const auto *character_value = + character ? std::get_if(&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"); + const Void::LanguageServer::Documents::Position selected{ + static_cast(*line_value), static_cast(*character_value)}; + Json result{nullptr}; + if (diagnostics_ && diagnostics_->supports_occurrences()) + result = diagnostics_->hover(*uri, selected); + if (std::holds_alternative(result.value)) { + // Reflection ranges are compiler byte columns; convert the client + // position through the snapshot before matching. + if (const auto document = documents_.snapshot(*uri)) { + const auto offset = document->position_to_offset(selected); + const auto line_start = document->line_index.line_start_offset(selected.line); + if (offset && line_start && *offset >= *line_start) { + const auto byte_character = static_cast(*offset - *line_start); + if (auto reflected = reflection::hover_at( + *reflection_, document->identity.canonical_path.native(), + {selected.line, byte_character})) { + Json::Object content{{"kind", Json{std::string{"markdown"}}}, + {"value", Json{reflected->markup}}}; + result = Json{Json::Object{{"contents", Json{std::move(content)}}}}; + } + } + } + } + return reply(id, "result", std::move(result)); + } if (*method == "textDocument/hover" || *method == "textDocument/definition" || *method == "textDocument/signatureHelp" || *method == "textDocument/documentHighlight") { if (!diagnostics_ || !diagnostics_->supports_occurrences()) diff --git a/src/main.cpp b/src/main.cpp index 06d823a..6686c9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ namespace Workspace = Void::LanguageServer::Workspace; struct Options { std::optional root, user_file, provider, database, selector, build_root, - producer_cwd, profile, gcc_profile; + producer_cwd, profile, gcc_profile, reflection_snapshot; bool gcc_diagnostics{}; }; @@ -23,8 +23,8 @@ std::expected workspace_launch(const Options vls::WorkspaceLaunch launch; if (!options.root) { if (options.user_file || options.provider || options.database || options.selector || - options.build_root || options.producer_cwd || options.profile || - options.gcc_profile || options.gcc_diagnostics) + options.build_root || options.producer_cwd || options.profile || options.gcc_profile || + options.gcc_diagnostics || options.reflection_snapshot) return std::unexpected{"workspace options require --workspace-root"}; return launch; } @@ -58,6 +58,13 @@ std::expected workspace_launch(const Options return std::unexpected{!build ? build.error() : producer.error()}; launch.build_root = std::move(*build); launch.producer_cwd = std::move(*producer); + if (options.reflection_snapshot) { + const fs::path snapshot{*options.reflection_snapshot}; + std::error_code snapshot_error; + if (!snapshot.is_absolute() || !fs::is_regular_file(snapshot, snapshot_error)) + return std::unexpected{"--reflection-snapshot requires an existing absolute file"}; + launch.reflection_snapshot = snapshot; + } Workspace::SettingsOverrides overrides; overrides.compdb_path = options.database; overrides.vbs_manifest_path = options.selector; @@ -70,9 +77,8 @@ std::expected workspace_launch(const Options const bool diagnostics_default = !options.gcc_profile && (!options.provider || *options.provider != "none"); if (options.gcc_profile || options.gcc_diagnostics || diagnostics_default) { - auto profile = options.gcc_profile - ? vls::semantic::GccProfile::load(*options.gcc_profile) - : vls::semantic::GccProfile::prepare("g++"); + auto profile = options.gcc_profile ? vls::semantic::GccProfile::load(*options.gcc_profile) + : vls::semantic::GccProfile::prepare("g++"); if (!profile) { if (options.gcc_profile || options.gcc_diagnostics) return std::unexpected{profile.error()}; @@ -125,6 +131,9 @@ int main(int argc, char **argv) { "--gcc-profile", "", "enable stock GCC diagnostics for this workspace using an absolute prepared profile", options.gcc_profile); + parser.option("--reflection-snapshot", "", + "versioned reflection provenance snapshot served as read-only hover", + options.reflection_snapshot); parser.flag("--gcc-diagnostics", "", "prepare stock GCC diagnostics in process from the selected GCC driver " "(enabled by default when a workspace is selected)", diff --git a/src/reflection/Provenance.cpp b/src/reflection/Provenance.cpp index 5f5fb8c..04b6b63 100644 --- a/src/reflection/Provenance.cpp +++ b/src/reflection/Provenance.cpp @@ -338,6 +338,33 @@ Hover hover(const Entity &entity, const Expansion &expansion, const Limits &limi return result; } +std::optional hover_at(const Snapshot &snapshot, std::string_view path, Position position, + const Limits &limits) { + const Entity *best{}; + Range best_range{}; + for (const auto &entity : snapshot.entities()) { + for (const auto &origin : entity.provenance.origins) { + if (!origin.range || origin.range->path != path) + continue; + const auto &range = *origin.range; + const Position start{range.line, range.character}; + const Position end{range.endLine, range.endCharacter}; + if (position < start || end < position) + continue; + if (!best || start > Position{best_range.line, best_range.character}) { + best = &entity; + best_range = range; + } + } + } + if (!best) + return std::nullopt; + const auto expansion = snapshot.expand(best->id); + if (!expansion) + return std::nullopt; + return hover(*best, *expansion, limits); +} + Snapshot snapshot_from_splices(std::span splices, Limits limits) { Snapshot snapshot{limits}; const auto range_at = [](std::string_view path, std::uint32_t line, std::uint32_t column) { diff --git a/tests/NativeRegistration.cpp b/tests/NativeRegistration.cpp index e67cb59..c8f2b60 100644 --- a/tests/NativeRegistration.cpp +++ b/tests/NativeRegistration.cpp @@ -39,7 +39,7 @@ int main() { "DapReplay.deferred_launch_finishes_after_configuration_done"}, Inventory{"vls_provider_tests", 42, "CommandImport.physical_owners_follow_links_before_parent_components"}, - Inventory{"vls_reflection_tests", 24, "Reflection.virtual_view_links_source_ranges"}, + Inventory{"vls_reflection_tests", 25, "Reflection.virtual_view_links_source_ranges"}, Inventory{"vls_trace_tests", 21, "RecordingTests.retains_values_and_source_across_overwrite_replacement_and_" "unlink"}, diff --git a/tests/reflection/ProvenanceTests.cpp b/tests/reflection/ProvenanceTests.cpp index 9b2e554..1d27f30 100644 --- a/tests/reflection/ProvenanceTests.cpp +++ b/tests/reflection/ProvenanceTests.cpp @@ -311,6 +311,7 @@ VOID_TEST(Reflection, virtual_view_renders_entity_and_members) { VOID_TEST(Reflection, virtual_view_links_source_ranges) { Snapshot snapshot; Entity inner = entity("inner"); + inner.name = "inner"; inner.provenance = chain({Origin{.kind = OriginKind::spelling, .range = range("/p/inner.cpp", 5)}}); Entity outer = entity("outer", {member("child", reference("inner"))}); @@ -494,3 +495,22 @@ VOID_TEST(Reflection, hover_and_locations_expose_source_links) { require(bounded.size() == 1); expect(bounded.front().line == 4); } + +VOID_TEST(Reflection, hover_at_selects_the_innermost_covering_entity) { + Snapshot snapshot; + Entity outer = entity("outer"); + outer.name = "outer"; + outer.provenance = chain({Origin{.kind = OriginKind::splice, .range = range("/p/a.cpp", 2)}}); + outer.provenance.origins.front().range->endCharacter = 40; + Entity inner = entity("inner"); + inner.name = "inner"; + inner.provenance = chain({Origin{.kind = OriginKind::splice, .range = range("/p/a.cpp", 5)}}); + inner.provenance.origins.front().range->endCharacter = 12; + require(snapshot.add(std::move(outer))); + require(snapshot.add(std::move(inner))); + const auto selected = hover_at(snapshot, "/p/a.cpp", {5, 6}); + require(selected.has_value()); + expect(selected->markup.find("inner : int") != std::string::npos); + expect(!hover_at(snapshot, "/p/a.cpp", {9, 0}).has_value()); + expect(!hover_at(snapshot, "/p/b.cpp", {5, 6}).has_value()); +}