Mark same-file definitions in semantic tokens

The server legend gains a declaration modifier, and EditorDiagnostics
emits the definition-name token with it when the definition lies in the
same document. No type token is emitted because the canonical type has
no source span. Registered tests cover modifier encoding and the
overlap rule; a real stdio session showed the modifier on both
definition names.
This commit is contained in:
faumaray committed 2026-12-05 18:27:17 +03:00
1 parent 2cced8363d
commit 816c38da1e
7 files changed
+54 -10

No files matched your search

+1 -1
View File
@@ -39,7 +39,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
| 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 |
| `EditorDiagnostics` reflection LSP wiring | the server has no reflection data source | | `EditorDiagnostics` reflection LSP wiring | the server has no reflection data source |
| semantic token modifiers / richer token types | legend is one type (`function`) from occurrences | | 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 | | textDocument/formatting | no formatter is available; needs a dependency decision |
## Next slices ## Next slices
+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. 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. 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 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
+16
View File
@@ -79,6 +79,22 @@ 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 declaration tokens in semantic tokens
The semantic-token slice now also emits the definition-name token when the
definition is in the same document, carrying the advertised `declaration`
modifier; the legend gained that modifier. The canonical type has no source
span, so no type token is emitted rather than one placed on unrelated text.
Registered `vls_feature_tests` cases cover modifier preservation, encoding and
the overlap rule (90 cases).
Real stdio session with `inner`/`outer` in one file:
```
semanticTokens: [(0, 4, 5, 1), (1, 4, 5, 1), (1, 21, 5, 0), (1, 31, 5, 0), (2, 20, 5, 0)]
```
The first two entries are the definition names with the declaration modifier.
All 18 native suites and all 18 CMake tests passed.
## December 5 return-type inlay hints ## December 5 return-type inlay hints
`include/vls/features/InlayHints.hpp` gained `call_end` (the offset past the `include/vls/features/InlayHints.hpp` gained `call_end` (the offset past the
+2
View File
@@ -11,6 +11,8 @@ namespace vls::features::semantic_tokens {
// Indices into the legend the server advertises. Only tokens the stock // Indices into the legend the server advertises. Only tokens the stock
// observer can prove are represented; there are no keyword or guess tokens. // observer can prove are represented; there are no keyword or guess tokens.
inline constexpr std::uint32_t function_type = 0; 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;
struct Token { struct Token {
std::uint32_t line{}, character{}, length{}; std::uint32_t line{}, character{}, length{};
+7 -8
View File
@@ -322,14 +322,13 @@ DispatchResult Server::handle(std::string_view body) {
} }
if (diagnostics_ && diagnostics_->supports_occurrences()) if (diagnostics_ && diagnostics_->supports_occurrences())
capabilities.emplace("inlayHintProvider", Json{true}); capabilities.emplace("inlayHintProvider", Json{true});
if (diagnostics_ && diagnostics_->supports_occurrences()) if (diagnostics_ && diagnostics_->supports_occurrences()) {
capabilities.emplace( Json::Object legend{
"semanticTokensProvider", {"tokenTypes", Json{Json::Array{Json{std::string{"function"}}}}},
Json{Json::Object{ {"tokenModifiers", Json{Json::Array{Json{std::string{"declaration"}}}}}};
{"legend", Json{Json::Object{ Json::Object semantic{{"legend", Json{std::move(legend)}}, {"full", Json{true}}};
{"tokenTypes", Json{Json::Array{Json{std::string{"function"}}}}}, capabilities.emplace("semanticTokensProvider", Json{std::move(semantic)});
{"tokenModifiers", Json{Json::Array{}}}}}}, }
{"full", Json{true}}}});
if (diagnostics_ && diagnostics_->supports_occurrences()) if (diagnostics_ && diagnostics_->supports_occurrences())
capabilities.emplace( capabilities.emplace(
"codeActionProvider", "codeActionProvider",
+9
View File
@@ -1289,6 +1289,15 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
continue; continue;
tokens.push_back({occurrence.use.start.line, occurrence.use.start.character, tokens.push_back({occurrence.use.start.line, occurrence.use.start.character,
occurrence.use.end.character - occurrence.use.start.character}); occurrence.use.end.character - occurrence.use.start.character});
// A definition in this same file is a declaration-name token too.
if (occurrence.has_definition() && occurrence.definition_file.get() == snapshot &&
occurrence.definition.start.line == occurrence.definition.end.line &&
occurrence.definition.end.character > occurrence.definition.start.character)
tokens.push_back(
{occurrence.definition.start.line, occurrence.definition.start.character,
occurrence.definition.end.character - occurrence.definition.start.character,
features::semantic_tokens::function_type,
features::semantic_tokens::declaration_modifier});
} }
const auto normalized = features::semantic_tokens::normalize(tokens); const auto normalized = features::semantic_tokens::normalize(tokens);
Json::Array data; Json::Array data;
+18
View File
@@ -49,3 +49,21 @@ VOID_TEST(SemanticTokens, bounds_count_and_length) {
const std::vector<Token> long_token{token(0, 0, 64)}; const std::vector<Token> long_token{token(0, 0, 64)};
expect(normalize(long_token, Limits{.length = 8}).empty()); expect(normalize(long_token, Limits{.length = 8}).empty());
} }
VOID_TEST(SemanticTokens, modifiers_are_preserved_and_encoded) {
const std::vector<Token> tokens{{0, 0, 1, function_type, declaration_modifier},
{0, 2, 1, function_type, 0}};
const auto result = normalize(tokens);
require(result.size() == 2);
expect(result[0].modifiers == declaration_modifier);
expect(result[1].modifiers == 0);
expect(encode(result) == std::vector<std::uint32_t>{0, 0, 1, 0, 1, 0, 2, 1, 0, 0});
}
VOID_TEST(SemanticTokens, an_overlapping_token_never_replaces_the_earlier_one) {
const std::vector<Token> tokens{{1, 4, 3, function_type, 0},
{1, 4, 3, function_type, declaration_modifier}};
const auto result = normalize(tokens);
require(result.size() == 1);
expect(result.front().modifiers == 0);
}