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
+36
-4
@@ -136,6 +136,15 @@ DispatchResult error(const Json &id, std::int64_t code, std::string_view message
|
||||
} // namespace
|
||||
|
||||
Server::Server(WorkspaceLaunch launch, std::function<bool(std::string)> send) : workspace_(launch) {
|
||||
if (launch.completion_index) {
|
||||
std::ifstream stream{*launch.completion_index, std::ios::binary};
|
||||
std::string bytes{std::istreambuf_iterator<char>{stream}, {}};
|
||||
if (!bytes.empty()) {
|
||||
auto parsed = features::completion_source::parse(bytes);
|
||||
if (parsed)
|
||||
completion_scopes_ = std::move(*parsed);
|
||||
}
|
||||
}
|
||||
if (launch.reflection_snapshot) {
|
||||
std::ifstream stream{*launch.reflection_snapshot, std::ios::binary};
|
||||
std::string bytes{std::istreambuf_iterator<char>{stream}, {}};
|
||||
@@ -733,10 +742,33 @@ DispatchResult Server::handle(std::string_view body) {
|
||||
*line_value > Void::LanguageServer::Documents::kMaxPositionValue ||
|
||||
*character_value > Void::LanguageServer::Documents::kMaxPositionValue)
|
||||
return error(id, -32602, "Expected textDocument.uri and a bounded position");
|
||||
return reply(
|
||||
id, "result",
|
||||
diagnostics_->completion(*uri, {static_cast<std::uint32_t>(*line_value),
|
||||
static_cast<std::uint32_t>(*character_value)}));
|
||||
const Void::LanguageServer::Documents::Position selected{
|
||||
static_cast<std::uint32_t>(*line_value), static_cast<std::uint32_t>(*character_value)};
|
||||
auto result = diagnostics_->completion(*uri, selected);
|
||||
const auto identity = Void::LanguageServer::Documents::normalize_uri(*uri);
|
||||
if (!completion_scopes_.empty() && identity && identity->is_file_uri) {
|
||||
if (const auto *scope = features::completion_source::at(
|
||||
completion_scopes_, identity->canonical_path.native(),
|
||||
{selected.line, selected.character})) {
|
||||
auto &fields = std::get<Json::Object>(result.value);
|
||||
Json::Array merged;
|
||||
for (const auto &provided : scope->items) {
|
||||
Json::Object item{{"label", Json{provided.label}},
|
||||
{"kind", Json{provided.kind}}};
|
||||
if (!provided.detail.empty())
|
||||
item.emplace("detail", Json{provided.detail});
|
||||
if (!provided.insert_text.empty())
|
||||
item.emplace("insertText", Json{provided.insert_text});
|
||||
merged.push_back(Json{std::move(item)});
|
||||
}
|
||||
if (const auto *existing = as_array(find_member(fields, "items")))
|
||||
for (const auto &entry : *existing)
|
||||
merged.push_back(entry);
|
||||
fields.insert_or_assign("items", Json{std::move(merged)});
|
||||
fields.insert_or_assign("isIncomplete", Json{!scope->complete});
|
||||
}
|
||||
}
|
||||
return reply(id, "result", std::move(result));
|
||||
}
|
||||
if (*method == "textDocument/references" || *method == "textDocument/prepareRename" ||
|
||||
*method == "textDocument/rename") {
|
||||
|
||||
Reference in new issue
Block a user