diff --git a/docs/agent-workflow/LSP-PARITY.md b/docs/agent-workflow/LSP-PARITY.md index d0832b0..d5af1b4 100644 --- a/docs/agent-workflow/LSP-PARITY.md +++ b/docs/agent-workflow/LSP-PARITY.md @@ -41,7 +41,7 @@ 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 | -| richer token types | legend is one type (`function`) plus a `declaration` modifier; type tokens need compiler-provided spans | +| richer token types | legend has `function` and `type` plus a `declaration` modifier; more types/modifiers need further compiler spans | ## Next slices diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 0761bc5..e0dc41b 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. Formatting is served through clang-format with the workspace style or the LSP options, bounded as a child process. 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. +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. Observer-reported class name spans are a second token type. 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. Formatting is served through clang-format with the workspace style or the LSP options, bounded as a child process. 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 4dde419..6211685 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -79,6 +79,17 @@ 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 type tokens in semantic tokens + +The legend now has a second token type, `type`, and the server emits it for each +observer-reported class name span that lies in the open document (from the +retained type facts). The canonical type itself still has no source span and is +not tokenized. Registered `vls_feature_tests` cover the legend index. A real +stdio session over the `Base`/`DerivedA`/`DerivedB` fixture decoded +`[(1, 7, 8, 1, 0), (2, 7, 8, 1, 0), (3, 9, 6, 0, 1), ...]` - the two class names +as type tokens and the definition names with the declaration modifier. All 18 +native suites and all 18 CMake tests passed. + ## December 5 type hierarchy over LSP Occurrences now carry their result type uid, decoded types are retained per diff --git a/include/vls/features/SemanticTokens.hpp b/include/vls/features/SemanticTokens.hpp index e7a8209..d5ff980 100644 --- a/include/vls/features/SemanticTokens.hpp +++ b/include/vls/features/SemanticTokens.hpp @@ -13,6 +13,8 @@ namespace vls::features::semantic_tokens { inline constexpr std::uint32_t function_type = 0; // Bit flag in Token::modifiers, matching the server's advertised legend. inline constexpr std::uint32_t declaration_modifier = 1; +// Second legend entry: a compiler-proven type name. +inline constexpr std::uint32_t type_type = 1; struct Token { std::uint32_t line{}, character{}, length{}; diff --git a/src/Server.cpp b/src/Server.cpp index 16a7a3c..bf8b13e 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -346,7 +346,8 @@ DispatchResult Server::handle(std::string_view body) { capabilities.emplace("inlayHintProvider", Json{true}); if (diagnostics_ && diagnostics_->supports_occurrences()) { Json::Object legend{ - {"tokenTypes", Json{Json::Array{Json{std::string{"function"}}}}}, + {"tokenTypes", + Json{Json::Array{Json{std::string{"function"}}, Json{std::string{"type"}}}}}, {"tokenModifiers", Json{Json::Array{Json{std::string{"declaration"}}}}}}; Json::Object semantic{{"legend", Json{std::move(legend)}}, {"full", Json{true}}}; capabilities.emplace("semanticTokensProvider", Json{std::move(semantic)}); diff --git a/src/semantic/EditorDiagnostics.cpp b/src/semantic/EditorDiagnostics.cpp index a7730dc..8a5c927 100644 --- a/src/semantic/EditorDiagnostics.cpp +++ b/src/semantic/EditorDiagnostics.cpp @@ -1311,6 +1311,7 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const { auto key = Documents::client_uri_key(uri); std::shared_ptr receipt; std::shared_ptr> facts; + std::shared_ptr> types; { std::lock_guard lock{s.mutex}; const auto i = key ? s.entries.find(*key) : s.entries.end(); @@ -1318,6 +1319,7 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const { return Json{Json::Object{{"data", Json{Json::Array{}}}}}; receipt = i->second.receipt; facts = i->second.occurrences; + types = i->second.types; } if (!receipt || !facts || !s.valid(*receipt)) return Json{Json::Object{{"data", Json{Json::Array{}}}}}; @@ -1347,6 +1349,16 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const { features::semantic_tokens::function_type, features::semantic_tokens::declaration_modifier}); } + if (types) + for (const auto &type : *types) { + if (type.self.path != snapshot->identity.canonical_path.native() || + type.self.range.start.line != type.self.range.end.line || + type.self.range.end.character <= type.self.range.start.character) + continue; + tokens.push_back({type.self.range.start.line, type.self.range.start.character, + type.self.range.end.character - type.self.range.start.character, + features::semantic_tokens::type_type, 0}); + } const auto normalized = features::semantic_tokens::normalize(tokens); Json::Array data; for (const auto value : features::semantic_tokens::encode(normalized)) diff --git a/tests/features/SemanticTokensTests.cpp b/tests/features/SemanticTokensTests.cpp index 7a91431..73594aa 100644 --- a/tests/features/SemanticTokensTests.cpp +++ b/tests/features/SemanticTokensTests.cpp @@ -67,3 +67,11 @@ VOID_TEST(SemanticTokens, an_overlapping_token_never_replaces_the_earlier_one) { require(result.size() == 1); expect(result.front().modifiers == 0); } + +VOID_TEST(SemanticTokens, type_tokens_keep_their_legend_index) { + const std::vector tokens{{0, 0, 4, function_type, 0}, {0, 6, 7, type_type, 0}}; + const auto result = normalize(tokens); + require(result.size() == 2); + expect(result[1].type == type_type); + expect(encode(result) == std::vector{0, 0, 4, 0, 0, 0, 6, 7, 1, 0}); +}