The semantic token legend gains a type entry, and the server emits it for each class name span reported by the observer when it lies in the open document. The canonical type itself is still not tokenized because it has no source span. Registered tests cover the legend index, and a real stdio session decoded the class names as type tokens beside the function and declaration tokens.
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
#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;
|
|
// Bit flag in Token::modifiers, matching the server's advertised legend.
|
|
inline constexpr std::uint32_t declaration_modifier = 1;
|
|
// Second legend entry: a compiler-proven type name.
|
|
inline constexpr std::uint32_t type_type = 1;
|
|
|
|
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
|