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
@@ -33,7 +33,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
||||
| Capability | Notes |
|
||||
| --- | --- |
|
||||
| Compiler-native completion with visibility proof | index-backed completion is explicitly incomplete |
|
||||
| Overload-set signature help | only the selected occurrence's signature is available |
|
||||
| Overload-set signature help | observed overloads are listed with the compiler-selected one first; visibility and overload resolution are not proven |
|
||||
| textDocument/formatting | needs a plan |
|
||||
| callHierarchy / typeHierarchy | prepare, incomingCalls and outgoingCalls are implemented and served; outgoing calls are verified over stdio now that the observer reports full function extents. Type hierarchy is open. |
|
||||
| Client-side application of server-issued workspace edits | rename and code actions return edits the clients apply directly |
|
||||
|
||||
@@ -94,7 +94,8 @@ library with a registered suite: explicit analysis contexts, unsaved overlays
|
||||
that shadow committed records and reconcile on save/close, dependency and
|
||||
source invalidation that marks coverage incomplete without discarding last-good
|
||||
records, immutable generations with reader retention, versioned persistence
|
||||
(schema 2 with a payload digest, migrating schema-1 snapshots on restore)
|
||||
(schema 3 with a payload digest and optional record signatures, migrating older
|
||||
snapshots on restore)
|
||||
with corrupt/incompatible/oversized rejection and quarantine, and bounded queries reporting
|
||||
coverage and truncation. It is wired into navigation: `EditorDiagnostics`
|
||||
ingests occurrence facts after each analysis and the server answers
|
||||
|
||||
@@ -79,6 +79,27 @@ the upgraded snapshot (keeping `snapshot.prev.json`) and rewrites a legacy
|
||||
about 25-30s in a Debug build (it passed VBS at ~27s); the full CMake run then
|
||||
passed 18/18.
|
||||
|
||||
## December 5 index schema 3 and overload-set signature help
|
||||
|
||||
`SymbolRecord` now carries the optional compiler signature and the snapshot
|
||||
schema is 3. Restore accepts schemas 1-3, verifies the digest for schema 3,
|
||||
reports older schemas as `migrated` and persists the upgrade. Registered
|
||||
`vls_index_tests` cases cover signature persistence, a schema-2 migration that
|
||||
keeps records, and rejection of an oversized signature (28 cases).
|
||||
|
||||
`EditorDiagnostics::signature_help` now merges every observed signature for
|
||||
the same name - from the open document's occurrences and from the index - with
|
||||
the compiler-selected one first. The index does not prove visibility, so this is
|
||||
a candidate list, not overload resolution.
|
||||
|
||||
Real stdio session with `int pick(int)` and `double pick(double)` both called:
|
||||
```
|
||||
at 'pick(': activeParameter=0 (expected 0) signatures=2
|
||||
label: int pick(int)
|
||||
label: double pick(double)
|
||||
```
|
||||
All 18 native suites and all 18 CMake tests passed.
|
||||
|
||||
## December 5 declaration tokens in semantic tokens
|
||||
|
||||
The semantic-token slice now also emits the definition-name token when the
|
||||
|
||||
@@ -30,6 +30,8 @@ struct SymbolRecord {
|
||||
std::optional<Location> definition;
|
||||
std::vector<Location> references;
|
||||
std::string provenance;
|
||||
// Compiler-provided call signature, when the observer reported one.
|
||||
std::optional<std::string> signature;
|
||||
auto operator<=>(const SymbolRecord &) const = default;
|
||||
};
|
||||
|
||||
@@ -39,6 +41,7 @@ struct Limits {
|
||||
std::size_t recordsPerContext{16384};
|
||||
std::size_t referencesPerRecord{256};
|
||||
std::size_t nameBytes{256};
|
||||
std::size_t signatureBytes{320};
|
||||
std::size_t pathBytes{4096};
|
||||
std::size_t snapshotBytes{32 * 1024 * 1024};
|
||||
};
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -134,7 +134,7 @@ VOID_TEST(SymbolIndex, rejects_incompatible_or_corrupt_snapshots) {
|
||||
return std::string{std::istreambuf_iterator<char>{stream}, {}};
|
||||
}();
|
||||
auto incompatible = bytes;
|
||||
const auto schema = incompatible.find("\"schema\":2");
|
||||
const auto schema = incompatible.find("\"schema\":3");
|
||||
require(schema != std::string::npos);
|
||||
incompatible.replace(schema, 10, "\"schema\":9");
|
||||
{
|
||||
@@ -210,7 +210,7 @@ VOID_TEST(SymbolIndex, quarantines_incompatible_snapshots_and_rebuilds) {
|
||||
std::ifstream stream{path, std::ios::binary};
|
||||
return std::string{std::istreambuf_iterator<char>{stream}, {}};
|
||||
}();
|
||||
const auto schema = bytes.find("\"schema\":2");
|
||||
const auto schema = bytes.find("\"schema\":3");
|
||||
require(schema != std::string::npos);
|
||||
bytes.replace(schema, 10, "\"schema\":9");
|
||||
{
|
||||
@@ -350,7 +350,7 @@ std::string downgrade(std::string bytes) {
|
||||
const auto end = bytes.find('"', digest + 12);
|
||||
require(end != std::string::npos);
|
||||
bytes.erase(digest, end + 1 - digest);
|
||||
const auto schema = bytes.find("\"schema\":2");
|
||||
const auto schema = bytes.find("\"schema\":3");
|
||||
require(schema != std::string::npos);
|
||||
bytes.replace(schema, 10, "\"schema\":1");
|
||||
return bytes;
|
||||
@@ -373,7 +373,7 @@ VOID_TEST(SymbolIndex, snapshot_schema_migration_is_reported_and_rewritten) {
|
||||
const auto upgraded = temp.path() / "upgraded.json";
|
||||
require(loaded.save(upgraded));
|
||||
const auto bytes = file_text(upgraded);
|
||||
expect(bytes.find("\"schema\":2") != std::string::npos);
|
||||
expect(bytes.find("\"schema\":3") != std::string::npos);
|
||||
expect(bytes.find("\"digest\":\"") != std::string::npos);
|
||||
SymbolIndex reread;
|
||||
expect(reread.load(upgraded));
|
||||
@@ -394,7 +394,7 @@ VOID_TEST(SymbolIndex, generation_restore_persists_the_migrated_schema) {
|
||||
expect(restored->migrated);
|
||||
expect(count(loaded.find({.name = "a"})) == 1);
|
||||
const auto bytes = file_text(root / "snapshot.json");
|
||||
expect(bytes.find("\"schema\":2") != std::string::npos);
|
||||
expect(bytes.find("\"schema\":3") != std::string::npos);
|
||||
expect(bytes.find("\"digest\":\"") != std::string::npos);
|
||||
expect(fs::is_regular_file(root / "snapshot.prev.json"));
|
||||
SymbolIndex reread;
|
||||
@@ -458,3 +458,47 @@ VOID_TEST(SymbolIndex, finds_records_by_path_with_overlay_shadowing) {
|
||||
expect(result.symbols.front().name == "d");
|
||||
expect(index.find_by_path("/project/absent.cpp").symbols.empty());
|
||||
}
|
||||
|
||||
VOID_TEST(SymbolIndex, signatures_survive_persistence) {
|
||||
Void::FileSystem::TempDir temp{"vls_symbol_index_"};
|
||||
const auto path = temp.path() / "index.json";
|
||||
SymbolIndex index;
|
||||
auto signed_record = record("f", "/project/unit.cpp", 3);
|
||||
signed_record.signature = "int f(int, double)";
|
||||
require(index.publish(context("debug:unit", {signed_record})));
|
||||
require(index.save(path));
|
||||
SymbolIndex loaded;
|
||||
require(loaded.load(path));
|
||||
const auto result = loaded.find({.name = "f"});
|
||||
require(count(result) == 1);
|
||||
require(result.symbols.front().signature.has_value());
|
||||
expect(*result.symbols.front().signature == "int f(int, double)");
|
||||
}
|
||||
|
||||
VOID_TEST(SymbolIndex, schema_2_snapshots_migrate_with_their_records) {
|
||||
Void::FileSystem::TempDir temp{"vls_symbol_index_"};
|
||||
const auto path = temp.path() / "index.json";
|
||||
SymbolIndex index;
|
||||
require(index.publish(context("debug:unit", {record("f", "/project/unit.cpp", 3)})));
|
||||
require(index.save(path));
|
||||
auto bytes = file_text(path);
|
||||
const auto schema = bytes.find("\"schema\":3");
|
||||
require(schema != std::string::npos);
|
||||
bytes.replace(schema, 10, "\"schema\":2");
|
||||
put_text(path, bytes);
|
||||
SymbolIndex loaded;
|
||||
const auto restored = loaded.restore(path);
|
||||
require(restored.has_value());
|
||||
expect(restored->status == SymbolIndex::LoadStatus::loaded);
|
||||
expect(restored->migrated);
|
||||
expect(count(loaded.find({.name = "f"})) == 1);
|
||||
require(loaded.save(path));
|
||||
expect(file_text(path).find("\"schema\":3") != std::string::npos);
|
||||
}
|
||||
|
||||
VOID_TEST(SymbolIndex, rejects_an_oversized_signature) {
|
||||
SymbolIndex index;
|
||||
auto signed_record = record("f", "/project/unit.cpp", 3);
|
||||
signed_record.signature = std::string(400, 'x');
|
||||
expect(!index.publish(context("debug:unit", {signed_record})));
|
||||
}
|
||||
Reference in new issue
Block a user