Files
Language-Server/include/vls/features/Completion.hpp
T
faumaray da8003f6d4 Implement the VLS roadmap on the native VBS build
Native VBS and CMake builds of the server and every registered suite:
protocol and document sync, VBS/compdb providers, stock GCC diagnostics
(including in-process default profile preparation), the stock occurrence
observer and hover/definition, the bounded Scheduler, C++ module graph,
scan and artifact cache with real CMI production, the context-aware
symbol index with schema-2 snapshot migration, navigation and guarded
rename, reflection provenance with splice-origin extraction, index-backed
completion and signature help, live GCC worker control with a registered
DAP suite, and the Neovim and VS Code clients.

VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced
from the versioned patches and verified stepping reflection/template code
with projected values 17/34 and 41/82.
2026-12-05 14:06:50 +03:00

96 lines
3.1 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;
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