Candidates carry a local flag set from the index record path, and the deterministic sort key orders local candidates before remote ones within the same kind. Registered feature tests cover the ranking.
98 lines
3.2 KiB
C++
98 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include <compare>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace vls::features::completion {
|
|
|
|
// Candidate origin is explicit: this slice ranks workspace symbols from the
|
|
// analysis index and never claims compiler-native completion.
|
|
enum class Kind { unknown, function, type, variable, field, namespace_, module, keyword };
|
|
|
|
struct Limits {
|
|
std::size_t candidates{200};
|
|
std::size_t labelBytes{256};
|
|
std::size_t detailBytes{512};
|
|
std::size_t provenanceBytes{128};
|
|
};
|
|
|
|
// Stable identity of one completion candidate across a later resolve request.
|
|
struct Identity {
|
|
std::string name;
|
|
std::string path;
|
|
std::uint32_t line{}, character{};
|
|
auto operator<=>(const Identity &) const = default;
|
|
};
|
|
|
|
struct Candidate {
|
|
std::string label;
|
|
Kind kind{Kind::unknown};
|
|
std::string detail;
|
|
std::string provenance;
|
|
Identity identity;
|
|
// The candidate is declared in the requesting document.
|
|
bool local{};
|
|
auto operator<=>(const Candidate &) const = default;
|
|
};
|
|
|
|
struct Item {
|
|
std::string label;
|
|
Kind kind{Kind::unknown};
|
|
std::string detail;
|
|
std::string provenance;
|
|
std::string sort_text;
|
|
Identity identity;
|
|
// Byte offsets of the identifier prefix the item replaces.
|
|
std::size_t replacement_start{}, replacement_end{};
|
|
auto operator<=>(const Item &) const = default;
|
|
};
|
|
|
|
struct Result {
|
|
std::vector<Item> items;
|
|
// True until compiler-native completion exists; index candidates are not
|
|
// authoritative for visibility or accessibility.
|
|
bool incomplete{true};
|
|
std::string backend{"symbol-index"};
|
|
};
|
|
|
|
// Longest ASCII identifier prefix ending at the byte offset. Empty when the
|
|
// preceding text is not an identifier or the prefix starts with a digit.
|
|
[[nodiscard]] std::string_view prefix_at(std::string_view text, std::size_t offset);
|
|
|
|
// Filters candidates whose label starts with the prefix, deduplicates by label
|
|
// and kind, ranks deterministically (kind priority, shorter label, label) and
|
|
// bounds every field. The replacement range covers the prefix.
|
|
[[nodiscard]] Result complete(std::span<const Candidate>, std::string_view text, std::size_t offset,
|
|
const Limits & = Limits{});
|
|
|
|
// A candidate as the current index generation reports it.
|
|
struct Detail {
|
|
Identity identity;
|
|
Kind kind{Kind::unknown};
|
|
std::string detail;
|
|
std::string provenance;
|
|
auto operator<=>(const Detail &) const = default;
|
|
};
|
|
|
|
struct Resolved {
|
|
enum class Status { resolved, stale, unknown };
|
|
Status status{Status::unknown};
|
|
std::string documentation;
|
|
std::string detail;
|
|
};
|
|
|
|
// Resolves a captured candidate identity against the current generation.
|
|
// A changed generation is stale and an absent identity is unknown; neither
|
|
// ever returns details for a different entity. Documentation is bounded and
|
|
// fenced so that editor rendering cannot be escaped by the content.
|
|
[[nodiscard]] Resolved resolve(const Identity &, std::uint64_t captured_generation,
|
|
std::uint64_t current_generation, std::span<const Detail>,
|
|
const Limits & = Limits{});
|
|
|
|
} // namespace vls::features::completion
|