Persist record signatures and list observed overloads
SymbolRecord carries the optional compiler signature and the snapshot schema moves to 3; restore accepts schemas 1-3, verifies the digest for 3 and persists the upgrade. Registered index tests cover signature persistence, a schema-2 migration keeping records and oversized rejection. Signature help merges every observed signature for the name (document occurrences and index) with the compiler-selected one first; a real stdio session with two called overloads returned both labels. This is a candidate list, not overload resolution.
This commit is contained in:
1 parent
816c38da1e
commit
a5b9f34c9e
7 files changed
+113
-13
No files matched your search
@@ -24,8 +24,8 @@ using Json = P::Json;
|
||||
|
||||
namespace {
|
||||
constexpr std::size_t max_json_depth = 8;
|
||||
constexpr std::int64_t snapshot_schema = 2;
|
||||
constexpr std::int64_t legacy_snapshot_schema = 1;
|
||||
constexpr std::int64_t snapshot_schema = 3;
|
||||
constexpr std::int64_t oldest_snapshot_schema = 1;
|
||||
const char *backend_name = "vls-symbol-index";
|
||||
|
||||
bool plain(std::string_view text, std::size_t limit) {
|
||||
@@ -40,7 +40,9 @@ bool valid_location(const Location &location, const Limits &limits) {
|
||||
|
||||
bool valid_record(const SymbolRecord &record, const Limits &limits) {
|
||||
if (!plain(record.name, limits.nameBytes) || !valid_location(record.location, limits) ||
|
||||
record.references.size() > limits.referencesPerRecord)
|
||||
record.references.size() > limits.referencesPerRecord ||
|
||||
(record.signature &&
|
||||
(record.signature->empty() || record.signature->size() > limits.signatureBytes)))
|
||||
return false;
|
||||
if (record.definition && !valid_location(*record.definition, limits))
|
||||
return false;
|
||||
@@ -67,6 +69,8 @@ Json record_json(const SymbolRecord &record) {
|
||||
{"provenance", Json{record.provenance}}};
|
||||
if (record.definition)
|
||||
fields.emplace("definition", location_json(*record.definition));
|
||||
if (record.signature)
|
||||
fields.emplace("signature", Json{*record.signature});
|
||||
return Json{std::move(fields)};
|
||||
}
|
||||
|
||||
@@ -122,6 +126,12 @@ std::optional<SymbolRecord> read_record(const Json &value, const Limits &limits)
|
||||
return std::nullopt;
|
||||
record.definition = *parsed;
|
||||
}
|
||||
if (const auto *signature = P::find_member(*fields, "signature")) {
|
||||
auto parsed = text(signature, limits.signatureBytes);
|
||||
if (!parsed)
|
||||
return std::nullopt;
|
||||
record.signature = std::move(*parsed);
|
||||
}
|
||||
const auto *references = P::as_array(P::find_member(*fields, "references"));
|
||||
if (!references || references->size() > limits.referencesPerRecord)
|
||||
return std::nullopt;
|
||||
@@ -177,7 +187,7 @@ SnapshotStatus parse_snapshot(std::string_view bytes, const Limits &limits, Pars
|
||||
const auto *backend = P::as_string(P::find_member(*root, "backend"));
|
||||
const auto schema_value = schema ? std::get_if<std::int64_t>(&schema->value) : nullptr;
|
||||
if (!schema_value || !backend || *backend != backend_name ||
|
||||
(*schema_value != snapshot_schema && *schema_value != legacy_snapshot_schema))
|
||||
(*schema_value < oldest_snapshot_schema || *schema_value > snapshot_schema))
|
||||
return SnapshotStatus::incompatible;
|
||||
if (*schema_value == snapshot_schema) {
|
||||
const auto *digest = P::as_string(P::find_member(*root, "digest"));
|
||||
@@ -197,7 +207,7 @@ SnapshotStatus parse_snapshot(std::string_view bytes, const Limits &limits, Pars
|
||||
if (!generation_value || *generation_value < 0 || !contexts || !overlays)
|
||||
return SnapshotStatus::corrupt;
|
||||
out.generation = static_cast<std::uint64_t>(*generation_value);
|
||||
out.migrated = *schema_value == legacy_snapshot_schema;
|
||||
out.migrated = *schema_value != snapshot_schema;
|
||||
std::size_t total{};
|
||||
for (const auto &item : *contexts) {
|
||||
const auto *fields = P::as_object(&item);
|
||||
|
||||
@@ -396,6 +396,8 @@ struct EditorDiagnostics::State {
|
||||
record.definition =
|
||||
location_of(occurrence.definition, *occurrence.definition_file);
|
||||
record.provenance = "stock-observer";
|
||||
if (!occurrence.signature.empty())
|
||||
record.signature = occurrence.signature;
|
||||
facts.records.push_back(std::move(record));
|
||||
}
|
||||
symbols.publish(facts);
|
||||
@@ -1710,7 +1712,26 @@ Json EditorDiagnostics::signature_help(std::string_view uri, Documents::Position
|
||||
}
|
||||
if (!match)
|
||||
return Json{nullptr};
|
||||
const std::vector<std::string> signatures{match->signature};
|
||||
// The compiler-selected signature stays first; other observed overloads of
|
||||
// the same name follow as candidates. The index never proves visibility, so
|
||||
// this is not overload resolution.
|
||||
std::vector<std::string> signatures{match->signature};
|
||||
const auto consider = [&signatures](const std::string &candidate) {
|
||||
if (candidate.empty() || signatures.size() == 8)
|
||||
return;
|
||||
if (std::ranges::find(signatures, candidate) == signatures.end())
|
||||
signatures.push_back(candidate);
|
||||
};
|
||||
for (const auto &fact : *facts)
|
||||
if (fact.name == match->name)
|
||||
consider(fact.signature);
|
||||
{
|
||||
std::lock_guard lock{s.mutex};
|
||||
if (const auto generation = s.symbols.current())
|
||||
for (const auto &record : generation->symbols())
|
||||
if (record.name == match->name && record.signature)
|
||||
consider(*record.signature);
|
||||
}
|
||||
const auto help = features::signature::build(signatures, snapshot->text, *offset);
|
||||
if (help.signatures.empty())
|
||||
return Json{nullptr};
|
||||
|
||||
Reference in new issue
Block a user