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.
70 lines
2.7 KiB
C++
70 lines
2.7 KiB
C++
#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());
|
|
}
|
|
|
|
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);
|
|
}
|