Distinguish definition tokens from declarations

The stock observer reports targetKind inside each proven target span,
the decoder carries it, and semantic tokens apply the legend's
definition modifier instead of always declaring. The observer
verifier validates the field and the definition span parser ignores it
as envelope metadata. A real stdio session showed modifier 2 on the
factory definitions.
This commit is contained in:
faumaray committed 2026-12-06 04:23:39 +03:00
1 parent 67ca5ea275
commit e4a68a3678
9 files changed
+41 -5

No files matched your search

+1 -1
View File
@@ -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. | | 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 | Neovim and VS Code both apply `changes` and versioned `documentChanges` | | Client-side application of server-issued workspace edits | Neovim and VS Code both apply `changes` and versioned `documentChanges` |
| 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 |
| richer token types | legend has `function` and `type` (class, base, definition names) plus a `declaration` modifier; more types need further compiler spans | | richer token types | legend has `function` and `type` (class, base, definition names) plus `declaration`/`definition` modifiers; more types need further compiler spans |
## Next slices ## Next slices
+15
View File
@@ -61,6 +61,21 @@ start coordinate only, so ranges are zero-width until an end is available.
LSP adapters and index/rename/debugging integration remain open. `vbs test` LSP adapters and index/rename/debugging integration remain open. `vbs test`
passed all 17 native suites; CMake passed the reflection and trace suites. passed all 17 native suites; CMake passed the reflection and trace suites.
## December 6 definition modifier from the observer target kind
The stock observer now emits `targetKind` ("definition" or "declaration") inside
each proven target span. The occurrence decoder carries it as
`target_is_definition`, and semantic tokens use the legend's `definition`
modifier for definition-name tokens instead of always `declaration`. The
observer verifier validates the field; real stdio session over the
`Base`/`DerivedA`/`DerivedB` fixture:
```
semanticTokens: [(0, 7, 4, 1, 0), (1, 7, 8, 1, 0), (2, 7, 8, 1, 0),
(3, 9, 6, 0, 2), (4, 9, 6, 0, 2), (5, 22, 6, 0, 0), (5, 41, 6, 0, 0)]
```
The two factory definitions now carry modifier 2. All 18 native suites and all
18 CMake tests passed.
## December 6 index snapshot schema 4 ## December 6 index snapshot schema 4
The symbol-index snapshot is now schema 4 and records `digestAlgorithm` inside The symbol-index snapshot is now schema 4 and records `digestAlgorithm` inside
@@ -874,7 +874,8 @@ void finish(void *, void *) {
std::fprintf(out, ",\"line\":%u,\"startByte\":%u,\"endByte\":%u},\"definition\":", std::fprintf(out, ",\"line\":%u,\"startByte\":%u,\"endByte\":%u},\"definition\":",
use.where.line, use.where.start, use.where.end); use.where.line, use.where.start, use.where.end);
if (known) { if (known) {
std::fputs("{\"path\":", out); std::fprintf(out, "{\"targetKind\":\"%s\",\"path\":",
body->definition ? "definition" : "declaration");
json_string(out, body->path); json_string(out, body->path);
std::fprintf(out, ",\"line\":%u,\"startByte\":%u,\"endByte\":%u", body->where.line, std::fprintf(out, ",\"line\":%u,\"startByte\":%u,\"endByte\":%u", body->where.line,
body->where.start, body->where.end); body->where.start, body->where.end);
+1
View File
@@ -13,6 +13,7 @@ namespace vls::features::semantic_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. // Bit flag in Token::modifiers, matching the server's advertised legend.
inline constexpr std::uint32_t declaration_modifier = 1; inline constexpr std::uint32_t declaration_modifier = 1;
inline constexpr std::uint32_t definition_modifier = 2;
// Second legend entry: a compiler-proven type name. // Second legend entry: a compiler-proven type name.
inline constexpr std::uint32_t type_type = 1; inline constexpr std::uint32_t type_type = 1;
+2
View File
@@ -24,6 +24,8 @@ struct Occurrence {
std::optional<Documents::Range> extent; std::optional<Documents::Range> extent;
// Uid of the reported class type of this call's result, when present. // Uid of the reported class type of this call's result, when present.
std::uint32_t result_type_uid{}; std::uint32_t result_type_uid{};
// The resolved target is a definition (not merely a declaration).
bool target_is_definition{};
[[nodiscard]] bool has_definition() const noexcept { return definition_file != nullptr; } [[nodiscard]] bool has_definition() const noexcept { return definition_file != nullptr; }
}; };
+2 -1
View File
@@ -362,7 +362,8 @@ DispatchResult Server::handle(std::string_view body) {
Json::Object legend{ Json::Object legend{
{"tokenTypes", {"tokenTypes",
Json{Json::Array{Json{std::string{"function"}}, Json{std::string{"type"}}}}}, Json{Json::Array{Json{std::string{"function"}}, Json{std::string{"type"}}}}},
{"tokenModifiers", Json{Json::Array{Json{std::string{"declaration"}}}}}}; {"tokenModifiers", Json{Json::Array{Json{std::string{"declaration"}},
Json{std::string{"definition"}}}}}};
Json::Object semantic{{"legend", Json{std::move(legend)}}, {"full", Json{true}}}; Json::Object semantic{{"legend", Json{std::move(legend)}}, {"full", Json{true}}};
capabilities.emplace("semanticTokensProvider", Json{std::move(semantic)}); capabilities.emplace("semanticTokensProvider", Json{std::move(semantic)});
} }
+3 -1
View File
@@ -1413,7 +1413,9 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
{occurrence.definition.start.line, occurrence.definition.start.character, {occurrence.definition.start.line, occurrence.definition.start.character,
occurrence.definition.end.character - occurrence.definition.start.character, occurrence.definition.end.character - occurrence.definition.start.character,
features::semantic_tokens::function_type, features::semantic_tokens::function_type,
features::semantic_tokens::declaration_modifier}); occurrence.target_is_definition
? features::semantic_tokens::definition_modifier
: features::semantic_tokens::declaration_modifier});
} }
if (types) if (types)
for (const auto &type : *types) { for (const auto &type : *types) {
+11 -1
View File
@@ -287,8 +287,18 @@ decode_occurrences(std::string_view report, std::string_view nonce,
occurrence.use_file = use->first; occurrence.use_file = use->first;
occurrence.use = use->second; occurrence.use = use->second;
const auto *definition = P::find_member(*fields, "definition"); const auto *definition = P::find_member(*fields, "definition");
const auto *definition_object = definition ? P::as_object(definition) : nullptr;
const auto *target_kind =
definition_object ? P::as_string(P::find_member(*definition_object, "targetKind"))
: nullptr;
if (definition && !std::holds_alternative<std::nullptr_t>(definition->value)) { if (definition && !std::holds_alternative<std::nullptr_t>(definition->value)) {
const auto definition_span = span(definition); if (target_kind && *target_kind != "definition" && *target_kind != "declaration")
return std::unexpected{OccurrenceError::invalid_report};
occurrence.target_is_definition = target_kind && *target_kind == "definition";
// targetKind is envelope metadata, not part of the byte span.
Json normalized{*definition};
std::get<Json::Object>(normalized.value).erase("targetKind");
const auto definition_span = span(&normalized);
if (!definition_span) if (!definition_span)
return std::unexpected{OccurrenceError::invalid_report}; return std::unexpected{OccurrenceError::invalid_report};
if (captured(capture, definition_span->path)) { if (captured(capture, definition_span->path)) {
@@ -61,6 +61,10 @@ def compile(compiler, observer, work, main, flags=()):
def read_span(span, name, label): def read_span(span, name, label):
if isinstance(span, dict) and "targetKind" in span:
check(span["targetKind"] in ("definition", "declaration"),
f"invalid {label} targetKind {span!r}")
span = {key: value for key, value in span.items() if key != "targetKind"}
check(isinstance(span, dict) check(isinstance(span, dict)
and set(span) in ({"path", "line", "startByte", "endByte"}, and set(span) in ({"path", "line", "startByte", "endByte"},
{"path", "line", "startByte", "endByte", "extent"}), {"path", "line", "startByte", "endByte", "extent"}),