Files
Language-Server/include/vls/features/SemanticTokens.hpp
T
faumaray e4a68a3678 Distinguish definition tokens from declarations
The stock observer reports targetKind inside each proven target span,
the decoder carries it, and semantic tokens apply the legend's
definition modifier instead of always declaring. The observer
verifier validates the field and the definition span parser ignores it
as envelope metadata. A real stdio session showed modifier 2 on the
factory definitions.
2026-12-06 04:23:39 +03:00

41 lines
1.4 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;
inline constexpr std::uint32_t definition_modifier = 2;
// 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