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

+35
View File
@@ -0,0 +1,35 @@
#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <span>
#include <vector>
namespace vls::features::semantic_tokens {
// Indices into the legend the server advertises. Only tokens the stock
// observer can prove are represented; there are no keyword or guess tokens.
inline constexpr std::uint32_t function_type = 0;
struct Token {
std::uint32_t line{}, character{}, length{};
std::uint32_t type{function_type};
std::uint32_t modifiers{};
auto operator<=>(const Token &) const = default;
};
struct Limits {
std::size_t tokens{65536};
std::size_t length{4096};
};
// Sorts by position, drops empty or overlong tokens, duplicates and tokens
// that overlap an earlier one (the earlier token wins), and bounds the count.
[[nodiscard]] std::vector<Token> normalize(std::span<const Token>, const Limits & = Limits{});
// LSP delta encoding: [deltaLine, deltaStartChar, length, type, modifiers]
// per token. Input must already be normalized.
[[nodiscard]] std::vector<std::uint32_t> encode(std::span<const Token>);
} // namespace vls::features::semantic_tokens