The bounded inlay-hint core now matches a call's closing parenthesis (nested calls, literals and comments aware) and places a type hint labelled with the compiler's canonical type. EditorDiagnostics emits it for every occurrence independently of parameter signatures. Registered tests cover nested matching, placement, skipped cases and bounds; a real stdio session showed both the parameter and return hints at the fnv1a64 call.
60 lines
2.3 KiB
C++
60 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <compare>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace vls::features::inlay_hints {
|
|
|
|
struct Position {
|
|
std::uint32_t line{}, character{};
|
|
auto operator<=>(const Position &) const = default;
|
|
};
|
|
struct Range {
|
|
Position start, end;
|
|
auto operator<=>(const Range &) const = default;
|
|
};
|
|
struct Hint {
|
|
Position position;
|
|
std::string label;
|
|
std::uint32_t kind{}; // LSP InlayHintKind: 2 is Parameter
|
|
bool padding_left{}, padding_right{};
|
|
auto operator<=>(const Hint &) const = default;
|
|
};
|
|
|
|
struct Limits {
|
|
std::size_t arguments{16};
|
|
std::size_t hints{256};
|
|
std::size_t labelBytes{128};
|
|
};
|
|
|
|
// Byte offsets of the top-level argument starts of the call whose '(' follows
|
|
// CALLEE_END. Nested brackets, literals and comments do not split arguments.
|
|
[[nodiscard]] std::vector<std::size_t>
|
|
argument_starts(std::string_view text, std::size_t callee_end, const Limits & = Limits{});
|
|
|
|
// One parameter-type hint before each argument, taken from the compiler
|
|
// signature for that position. Hints outside the requested range are skipped;
|
|
// a signature without that parameter contributes nothing.
|
|
[[nodiscard]] std::vector<Hint> parameter_hints(std::span<const std::string> signatures,
|
|
std::string_view text, std::size_t callee_end,
|
|
Range requested, const Limits & = Limits{});
|
|
|
|
// Offset just past the matching ')' of the call whose '(' follows CALLEE_END.
|
|
[[nodiscard]] std::optional<std::size_t> call_end(std::string_view text, std::size_t callee_end,
|
|
const Limits & = Limits{});
|
|
|
|
// A return-type hint after the call's closing parenthesis, labelled with the
|
|
// compiler's canonical type. Absent when the type is empty, the call is
|
|
// unterminated or the position is outside the requested range.
|
|
[[nodiscard]] std::optional<Hint> return_type_hint(std::string_view text, std::size_t callee_end,
|
|
std::string_view canonical_type, Range requested,
|
|
const Limits & = Limits{});
|
|
|
|
} // namespace vls::features::inlay_hints
|