Serve reference code lenses and the showReferences command

A bounded core builds one lens per document position with its proven
reference count. EditorDiagnostics counts index records by name and
definition and serves textDocument/codeLens; workspace/executeCommand
implements vls.showReferences via the navigation binding. Registered
feature tests cover titles, arguments, deduplication and bounds. A
real stdio session showed the one-reference lens at the fnv1a64 call
and resolved it to the source location.
This commit is contained in:
faumaray committed 2026-12-05 17:50:38 +03:00
1 parent ec86a79a1a
commit 0bf5873069
12 files changed
+279 -5

No files matched your search

+52
View File
@@ -2,6 +2,7 @@
#include <vls/features/CallHierarchy.hpp>
#include <vls/features/CodeActions.hpp>
#include <vls/features/CodeLens.hpp>
#include <vls/features/Completion.hpp>
#include <vls/features/DocumentSymbols.hpp>
#include <vls/features/IndexNavigation.hpp>
@@ -1038,6 +1039,57 @@ Json EditorDiagnostics::completion_resolve(const Json &item) const {
return Json{std::move(enriched)};
}
Json EditorDiagnostics::code_lenses(std::string_view uri) const {
auto &s = *state_;
const auto identity = Documents::normalize_uri(uri);
if (!identity || !identity->is_file_uri)
return Json{nullptr};
const auto path = identity->canonical_path.native();
index::Result records;
std::map<std::tuple<std::string, std::string, std::uint32_t, std::uint32_t>, std::size_t>
counts;
{
std::lock_guard lock{s.mutex};
records = s.symbols.find_by_path(path);
if (const auto generation = s.symbols.current())
for (const auto &record : generation->symbols()) {
const auto &where = record.definition ? *record.definition : record.location;
++counts[{record.name, where.path, where.line, where.character}];
}
}
std::vector<features::code_lens::Entry> entries;
for (const auto &record : records.symbols) {
const auto &where = record.definition ? *record.definition : record.location;
const auto found = counts.find({record.name, where.path, where.line, where.character});
entries.push_back({{record.name},
record.location.path,
{{record.location.line, record.location.character},
{record.location.endLine, record.location.endCharacter}},
found == counts.end() ? 0 : found->second});
}
const auto lenses = features::code_lens::build(entries);
Json::Array result;
for (const auto &lens : lenses) {
const auto &arguments = lens.arguments;
if (arguments.size() != 3)
continue;
result.push_back(Json{Json::Object{
{"range",
range_json(Documents::Range{{lens.range.start.line, lens.range.start.character},
{lens.range.end.line, lens.range.end.character}})},
{"command",
Json{Json::Object{
{"title", Json{lens.title}},
{"command", Json{std::string{"vls.showReferences"}}},
{"arguments",
Json{Json::Array{
Json{Documents::path_to_file_uri(arguments[0])},
Json{Json::Object{{"line", Json{std::stoll(arguments[1])}},
{"character", Json{std::stoll(arguments[2])}}}}}}}}}}}});
}
return Json{std::move(result)};
}
Json EditorDiagnostics::document_symbols(std::string_view uri) const {
auto &s = *state_;
const auto identity = Documents::normalize_uri(uri);