Serve semantic tokens from stock occurrences

A bounded core normalizes occurrence tokens (sorted, deduplicated,
overlap-free, capped) and delta-encodes them. EditorDiagnostics emits
one function token per proven call occurrence in the owner snapshot,
and the server advertises a one-type legend and serves
textDocument/semanticTokens/full. Registered tests cover
normalization, encoding, overlap and bounds; a real stdio session
decoded the fnv1a64 callee token.
This commit is contained in:
faumaray committed 2026-12-05 15:19:42 +03:00
1 parent 946b1a005e
commit 12a71ff692
12 files changed
+220 -8

No files matched your search

+40
View File
@@ -4,6 +4,7 @@
#include <vls/features/Completion.hpp>
#include <vls/features/DocumentSymbols.hpp>
#include <vls/features/IndexNavigation.hpp>
#include <vls/features/SemanticTokens.hpp>
#include <vls/features/SignatureHelp.hpp>
#include <vls/features/TextStructure.hpp>
#include <vls/index/SymbolIndex.hpp>
@@ -1159,6 +1160,45 @@ Json EditorDiagnostics::code_actions(std::string_view uri, Documents::Range rang
return Json{std::move(actions)};
}
Json EditorDiagnostics::semantic_tokens(std::string_view uri) 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::Object{{"data", Json{Json::Array{}}}}};
receipt = i->second.receipt;
facts = i->second.occurrences;
}
if (!receipt || !facts || !s.valid(*receipt))
return Json{Json::Object{{"data", Json{Json::Array{}}}}};
const Documents::DocumentSnapshot *snapshot = nullptr;
for (const auto &entry : receipt->capture->entries())
if (entry.snapshot && entry.snapshot->identity.canonical_uri == *key) {
snapshot = entry.snapshot.get();
break;
}
if (!snapshot)
return Json{Json::Object{{"data", Json{Json::Array{}}}}};
std::vector<features::semantic_tokens::Token> tokens;
for (const auto &occurrence : *facts) {
if (occurrence.use_file.get() != snapshot ||
occurrence.use.start.line != occurrence.use.end.line ||
occurrence.use.end.character <= occurrence.use.start.character)
continue;
tokens.push_back({occurrence.use.start.line, occurrence.use.start.character,
occurrence.use.end.character - occurrence.use.start.character});
}
const auto normalized = features::semantic_tokens::normalize(tokens);
Json::Array data;
for (const auto value : features::semantic_tokens::encode(normalized))
data.push_back(Json{static_cast<std::int64_t>(value)});
return Json{Json::Object{{"data", Json{std::move(data)}}}};
}
void EditorDiagnostics::set_transactional_rename(bool supported) {
std::lock_guard lock{state_->mutex};
state_->transactional_rename = supported;