#pragma once #include #include #include #include #include #include #include #include namespace vls::features::completion_source { // Positions are LSP positions in the document's negotiated encoding, so any // producer can write them without knowing VLS internals. struct Position { std::uint32_t line{}, character{}; auto operator<=>(const Position &) const = default; }; struct Provided { std::string label; std::int64_t kind{1}; std::string detail; std::string insert_text; auto operator<=>(const Provided &) const = default; }; // One compiler-produced completion point: a position range with the // candidates visible there. COMPLETE means the producer proved the list is // exhaustive for the range (visibility proof is the producer's claim, carried // through unchanged). struct Scope { std::string path; Position start, end; bool complete{}; std::vector items; }; struct Limits { std::size_t scopes{1024}; std::size_t items{4096}; std::size_t itemsPerScope{256}; std::size_t pathBytes{4096}; std::size_t textBytes{1024}; std::size_t fileBytes{8 * 1024 * 1024}; }; // Parses the versioned completion index: // {"schema":1,"scopes":[{"path":...,"startLine":..,"startCharacter":.., // "endLine":..,"endCharacter":..,"complete":bool, // "items":[{"label":..,"kind":int?,"detail":?,"insertText":?}]}]} [[nodiscard]] std::expected, std::string> parse(std::string_view bytes, const Limits & = Limits{}); // The innermost scope covering the position, or null. [[nodiscard]] const Scope *at(const std::vector &, std::string_view path, Position); } // namespace vls::features::completion_source