Consume a compiler-agnostic completion index
Under D-032, completion can now merge candidates from a documented, versioned index file produced by any external tool. The bounded core parses and selects the innermost covering scope, the server puts its items ahead of index-backed ones and takes isIncomplete from the scope's complete flag, and registered feature tests cover parsing, selection and bounds. A real stdio session returned the provided items first with isIncomplete false inside the scope and true outside.
This commit is contained in:
1 parent
236c3c5718
commit
4a029152e9
13 files changed
+336
-11
No files matched your search
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
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<Provided> 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::vector<Scope>, 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<Scope> &, std::string_view path, Position);
|
||||
|
||||
} // namespace vls::features::completion_source
|
||||
Reference in new issue
Block a user