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.
38 lines
1.2 KiB
C++
38 lines
1.2 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;
|
|
|
|
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
|