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:
1 parent
946b1a005e
commit
12a71ff692
12 files changed
+220
-8
No files matched your search
@@ -0,0 +1,51 @@
|
||||
#include <vls/features/SemanticTokens.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace vls::features::semantic_tokens;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
Token token(std::uint32_t line, std::uint32_t character, std::uint32_t length) {
|
||||
return {line, character, length};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(SemanticTokens, normalizes_order_and_deltas) {
|
||||
const std::vector<Token> tokens{token(2, 4, 3), token(0, 8, 2), token(0, 2, 4)};
|
||||
const auto sorted = normalize(tokens);
|
||||
require(sorted.size() == 3);
|
||||
expect(sorted[0] == token(0, 2, 4));
|
||||
expect(sorted[1] == token(0, 8, 2));
|
||||
expect(sorted[2] == token(2, 4, 3));
|
||||
expect(encode(sorted) ==
|
||||
std::vector<std::uint32_t>{0, 2, 4, 0, 0, 0, 6, 2, 0, 0, 2, 4, 3, 0, 0});
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticTokens, drops_empty_duplicate_and_overlapping_tokens) {
|
||||
const std::vector<Token> tokens{token(1, 0, 0), token(1, 5, 4), token(1, 5, 4), token(1, 7, 2),
|
||||
token(1, 9, 2)};
|
||||
const auto result = normalize(tokens);
|
||||
require(result.size() == 2);
|
||||
expect(result[0] == token(1, 5, 4));
|
||||
expect(result[1] == token(1, 9, 2));
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticTokens, the_same_span_on_different_lines_is_distinct) {
|
||||
const std::vector<Token> tokens{token(0, 3, 2), token(1, 3, 2)};
|
||||
const auto result = normalize(tokens);
|
||||
expect(result.size() == 2);
|
||||
expect(encode(result) == std::vector<std::uint32_t>{0, 3, 2, 0, 0, 1, 3, 2, 0, 0});
|
||||
}
|
||||
|
||||
VOID_TEST(SemanticTokens, bounds_count_and_length) {
|
||||
const std::vector<Token> tokens{token(0, 0, 1), token(0, 2, 1), token(0, 4, 1)};
|
||||
expect(normalize(tokens, Limits{.tokens = 2}).size() == 2);
|
||||
expect(normalize(tokens, Limits{.tokens = 2, .length = 1}).size() == 2);
|
||||
const std::vector<Token> long_token{token(0, 0, 64)};
|
||||
expect(normalize(long_token, Limits{.length = 8}).empty());
|
||||
}
|
||||
Reference in new issue
Block a user