From 0bf5873069ff76e6cdfc543aac9fe3a472b222e4 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 17:50:38 +0300 Subject: [PATCH] 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. --- CMakeLists.txt | 2 +- build.cpp | 3 +- docs/agent-workflow/LSP-PARITY.md | 2 +- docs/agent-workflow/STATE.md | 2 +- docs/agent-workflow/VERIFICATION.md | 19 ++++++ include/vls/features/CodeLens.hpp | 47 +++++++++++++++ include/vls/semantic/EditorDiagnostics.hpp | 2 + src/Server.cpp | 42 +++++++++++++ src/features/CodeLens.cpp | 43 ++++++++++++++ src/semantic/EditorDiagnostics.cpp | 52 +++++++++++++++++ tests/CMakeLists.txt | 2 +- tests/features/CodeLensTests.cpp | 68 ++++++++++++++++++++++ 12 files changed, 279 insertions(+), 5 deletions(-) create mode 100644 include/vls/features/CodeLens.hpp create mode 100644 src/features/CodeLens.cpp create mode 100644 tests/features/CodeLensTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 56b3b35..65830dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ add_library(vls_protocol STATIC src/Protocol/Framing.cpp src/Protocol/Json.cpp src/Build/ProviderFile.cpp src/Build/CommandImport.cpp src/Build/VbsProvider.cpp src/Build/CompdbProvider.cpp src/DocumentSync.cpp src/WorkspaceSession.cpp src/Server.cpp src/semantic/Diagnostics.cpp src/semantic/SourceCatalog.cpp src/semantic/StockCompiler.cpp src/semantic/EditorDiagnostics.cpp src/semantic/Occurrences.cpp src/scheduler/Scheduler.cpp - src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp) + src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/features/CodeLens.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp) target_include_directories(vls_protocol PUBLIC "${PROJECT_SOURCE_DIR}/include") target_link_libraries(vls_protocol PUBLIC Void::Data PRIVATE Void::Unicode Void::Text Void::Crypto Void::System) target_compile_options(vls_protocol PUBLIC -freflection PRIVATE -Wall -Wextra -Wpedantic) diff --git a/build.cpp b/build.cpp index 1e4e4d0..ba83fa5 100644 --- a/build.cpp +++ b/build.cpp @@ -77,6 +77,7 @@ void build(Void::Build::Project &project) { "src/features/FileOperations.cpp", "src/features/IncludeUpdate.cpp", "src/features/CallHierarchy.cpp", + "src/features/CodeLens.cpp", "src/debug/live/LiveSession.cpp", "src/modules/ModuleWorkQueue.cpp", "src/modules/GccScan.cpp", @@ -159,7 +160,7 @@ void build(Void::Build::Project &project) { "tests/features/TextStructureTests.cpp", "tests/features/CodeActionsTests.cpp", "tests/features/SemanticTokensTests.cpp", "tests/features/InlayHintsTests.cpp", "tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp", - "tests/features/CallHierarchyTests.cpp"}); + "tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.cpp"}); auto live_worker = project.executable("vls_live_worker_fixture"); live_worker.cxx_standard(CxxStandard::Cxx26) .sources({"tests/debug/LiveWorkerFixture.cpp"}) diff --git a/docs/agent-workflow/LSP-PARITY.md b/docs/agent-workflow/LSP-PARITY.md index 28903b7..678e4c1 100644 --- a/docs/agent-workflow/LSP-PARITY.md +++ b/docs/agent-workflow/LSP-PARITY.md @@ -21,6 +21,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints. | textDocument/codeAction (quickfix) | `vls_feature_tests` + `vls_diagnostic_tests`, real stdio session | | textDocument/semanticTokens/full | `vls_feature_tests`, real stdio session | | textDocument/inlayHint (parameter types) | `vls_feature_tests`, real stdio session | +| textDocument/codeLens + workspace/executeCommand (`vls.showReferences`) | `vls_feature_tests`, real stdio session | | workspace/symbol | stock occurrence corpus | | workspace fileOperations (didCreate/didRename/didDelete) | `vls_feature_tests`, real stdio session | | workspace/willRenameFiles (include updates) | `vls_feature_tests`, real stdio session | @@ -35,7 +36,6 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints. | Overload-set signature help | only the selected occurrence's signature is available | | 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. | -| textDocument/codeLens, executeCommand | command surface not designed | | Client-side application of server-issued workspace edits | rename and code actions return edits the clients apply directly | | Applying multi-file renames through client buffers | plans can be ready; application is client work | | `EditorDiagnostics` reflection LSP wiring | the server has no reflection data source | diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 008a7bd..b2f2676 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -102,7 +102,7 @@ ingests occurrence facts after each analysis and the server answers Hash.hpp definition through it. Real persistence migrations and cross-file rename coverage remain open. -Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences with a bounded one-type legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. Compiler-native completion with visibility proof and deferred detail resolution remain open. +Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences with a bounded one-type legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Code lenses show index reference counts and the `vls.showReferences` command resolves them to navigation locations. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. Compiler-native completion with visibility proof and deferred detail resolution remain open. The reflection provenance representation (roadmap 12 first slice) is implemented as a bounded library with a registered suite: innermost-first diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 38a3826..9988d7f 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -79,6 +79,25 @@ 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 code lenses and the reference command + +`include/vls/features/CodeLens.hpp` builds one bounded lens per unique +document position, titled with the proven reference count and carrying +{path, line, character} arguments. `EditorDiagnostics::code_lenses` counts +records by (name, definition location) from the current index generation and +serves `textDocument/codeLens`; `workspace/executeCommand` implements +`vls.showReferences`, resolving the arguments through the navigation binding +and returning the reference locations. Both are advertised and bounded. + +Real stdio session with the stock observer: +``` +codeLens: [({'character': 33, 'line': 18}, '1 reference')] +executeCommand: [{"range": {"end": {"character": 40, "line": 18}, "start": {"character": 33, "line": 18}}, + "uri": "file:///.../DocumentSnapshot.cpp"}] +unknown command error: -32602 +``` +All 18 native suites and all 18 CMake tests passed. + ## December 5 full function extents from the stock observer The stock occurrence observer now reports an optional `extent` inside each diff --git a/include/vls/features/CodeLens.hpp b/include/vls/features/CodeLens.hpp new file mode 100644 index 0000000..ba955e9 --- /dev/null +++ b/include/vls/features/CodeLens.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace vls::features::code_lens { + +struct Position { + std::uint32_t line{}, character{}; + auto operator<=>(const Position &) const = default; +}; +struct Range { + Position start, end; + auto operator<=>(const Range &) const = default; +}; + +// One outline symbol with its proven reference count. +struct Entry { + std::string name; + std::string path; + Range range; + std::size_t references{}; +}; + +struct Lens { + Range range; + std::string title; + std::vector arguments; + auto operator<=>(const Lens &) const = default; +}; + +struct Limits { + std::size_t lenses{512}; + std::size_t nameBytes{256}; + std::size_t titleBytes{128}; +}; + +// One lens per unique (path, range), titled with the reference count and +// carrying {path, line, character} arguments so a client can resolve it through +// workspace/executeCommand. Entries are ordered by position and bounded. +[[nodiscard]] std::vector build(std::span, const Limits & = Limits{}); + +} // namespace vls::features::code_lens diff --git a/include/vls/semantic/EditorDiagnostics.hpp b/include/vls/semantic/EditorDiagnostics.hpp index 73869d3..d6897b0 100644 --- a/include/vls/semantic/EditorDiagnostics.hpp +++ b/include/vls/semantic/EditorDiagnostics.hpp @@ -60,6 +60,8 @@ class EditorDiagnostics { selection_ranges(std::string_view uri, std::span) const; // Foldable brace blocks, comments, regions and include groups. [[nodiscard]] Void::LanguageServer::Protocol::Json folding_ranges(std::string_view uri) const; + // Reference-count lenses for the records the index holds for one document. + [[nodiscard]] Void::LanguageServer::Protocol::Json code_lenses(std::string_view uri) const; // Quick fixes suggested by the compiler for diagnostics overlapping the // requested range. Only fixes proven in the owner snapshot are offered. [[nodiscard]] Void::LanguageServer::Protocol::Json code_actions(std::string_view uri, diff --git a/src/Server.cpp b/src/Server.cpp index 3e0d243..05af953 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -312,6 +312,14 @@ DispatchResult Server::handle(std::string_view body) { } if (diagnostics_ && diagnostics_->supports_occurrences()) capabilities.emplace("callHierarchyProvider", Json{true}); + if (diagnostics_ && diagnostics_->supports_occurrences()) { + capabilities.emplace("codeLensProvider", + Json{Json::Object{{"resolveProvider", Json{false}}}}); + capabilities.emplace( + "executeCommandProvider", + Json{Json::Object{ + {"commands", Json{Json::Array{Json{std::string{"vls.showReferences"}}}}}}}); + } if (diagnostics_ && diagnostics_->supports_occurrences()) capabilities.emplace("inlayHintProvider", Json{true}); if (diagnostics_ && diagnostics_->supports_occurrences()) @@ -434,6 +442,40 @@ DispatchResult Server::handle(std::string_view body) { } return reply(id, "result", diagnostics_->selection_ranges(*uri, selected)); } + if (*method == "textDocument/codeLens") { + if (!diagnostics_ || !diagnostics_->supports_occurrences()) + return error(id, -32601, "Method not found"); + const auto *uri = as_string(member(member(params, "textDocument"), "uri")); + if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri)) + return error(id, -32602, "Expected textDocument.uri"); + return reply(id, "result", diagnostics_->code_lenses(*uri)); + } + if (*method == "workspace/executeCommand") { + if (!diagnostics_ || !diagnostics_->supports_occurrences()) + return error(id, -32601, "Method not found"); + const auto *command = as_string(member(params, "command")); + const auto *arguments = as_array(member(params, "arguments")); + if (!command || !arguments || arguments->size() != 2) + return error(id, -32602, "Expected a command and two arguments"); + if (*command != "vls.showReferences") + return error(id, -32601, "Unregistered command"); + const auto *uri = as_string(&(*arguments)[0]); + const auto *position = as_object(&(*arguments)[1]); + const auto line = position ? find_member(*position, "line") : nullptr; + const auto character = position ? find_member(*position, "character") : nullptr; + const auto *line_value = line ? std::get_if(&line->value) : nullptr; + const auto *character_value = + character ? std::get_if(&character->value) : nullptr; + if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri) || !line_value || + !character_value || *line_value < 0 || *character_value < 0 || + *line_value > Void::LanguageServer::Documents::kMaxPositionValue || + *character_value > Void::LanguageServer::Documents::kMaxPositionValue) + return error(id, -32602, "Expected textDocument.uri and a bounded position"); + auto navigation = + diagnostics_->references(*uri, {static_cast(*line_value), + static_cast(*character_value)}); + return reply(id, "result", std::move(navigation.result)); + } if (*method == "textDocument/prepareCallHierarchy") { if (!diagnostics_ || !diagnostics_->supports_occurrences()) return error(id, -32601, "Method not found"); diff --git a/src/features/CodeLens.cpp b/src/features/CodeLens.cpp new file mode 100644 index 0000000..209debd --- /dev/null +++ b/src/features/CodeLens.cpp @@ -0,0 +1,43 @@ +#include + +#include +#include +#include +#include + +namespace vls::features::code_lens { +namespace { + +std::string title(std::size_t references) { + return std::to_string(references) + (references == 1 ? " reference" : " references"); +} + +} // namespace + +std::vector build(std::span entries, const Limits &limits) { + std::vector result; + std::set> seen; + for (const auto &entry : entries) { + if (entry.path.empty() || entry.name.empty() || entry.name.size() > limits.nameBytes || + entry.range.end < entry.range.start) + continue; + if (!seen.emplace(entry.path, entry.range).second) + continue; + auto text = title(entry.references); + if (text.size() > limits.titleBytes) + text.resize(limits.titleBytes); + result.push_back({entry.range, + std::move(text), + {entry.path, std::to_string(entry.range.start.line), + std::to_string(entry.range.start.character)}}); + } + std::ranges::sort(result, [](const Lens &left, const Lens &right) { + return std::tie(left.range.start, left.range.end) < + std::tie(right.range.start, right.range.end); + }); + if (result.size() > limits.lenses) + result.resize(limits.lenses); + return result; +} + +} // namespace vls::features::code_lens diff --git a/src/semantic/EditorDiagnostics.cpp b/src/semantic/EditorDiagnostics.cpp index 5e6a38f..39ec043 100644 --- a/src/semantic/EditorDiagnostics.cpp +++ b/src/semantic/EditorDiagnostics.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -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::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 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); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2972861..137a103 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,7 +22,7 @@ vls_test_suite(vls_scheduler_tests scheduler/SchedulerTests.cpp) vls_test_suite(vls_index_tests index/SymbolIndexTests.cpp) vls_test_suite(vls_navigation_tests navigation/NavigationTests.cpp) vls_test_suite(vls_reflection_tests reflection/ProvenanceTests.cpp) -vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp) +vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp features/CodeLensTests.cpp) vls_test_suite(vls_live_tests debug/LiveSessionTests.cpp debug/LiveDapTests.cpp) target_link_libraries(vls_live_tests PRIVATE Void::System) add_dependencies(vls_live_tests vls_live_worker_fixture vls-dap) diff --git a/tests/features/CodeLensTests.cpp b/tests/features/CodeLensTests.cpp new file mode 100644 index 0000000..dccc3f2 --- /dev/null +++ b/tests/features/CodeLensTests.cpp @@ -0,0 +1,68 @@ +#include + +#include +#include + +#include +#include + +namespace { +using namespace vls::features::code_lens; +using Void::Testing::expect; +using Void::Testing::require; + +Range range(std::uint32_t line) { return {{line, 0}, {line, 4}}; } +} // namespace + +VOID_TEST(CodeLens, titles_singular_and_plural_counts) { + const std::vector entries{{"a", "/p/a.cpp", range(1), 1}, + {"b", "/p/a.cpp", range(2), 0}, + {"c", "/p/a.cpp", range(3), 3}}; + const auto lenses = build(entries); + require(lenses.size() == 3); + expect(lenses[0].title == "1 reference"); + expect(lenses[1].title == "0 references"); + expect(lenses[2].title == "3 references"); +} + +VOID_TEST(CodeLens, arguments_carry_the_path_and_start) { + const std::vector entries{{"a", "/p/a.cpp", {{4, 2}, {4, 9}}, 2}}; + const auto lenses = build(entries); + require(lenses.size() == 1); + require(lenses.front().arguments.size() == 3); + expect(lenses.front().arguments[0] == "/p/a.cpp"); + expect(lenses.front().arguments[1] == "4"); + expect(lenses.front().arguments[2] == "2"); +} + +VOID_TEST(CodeLens, deduplicates_by_path_and_range) { + const std::vector entries{{"a", "/p/a.cpp", range(1), 1}, + {"a", "/p/a.cpp", range(1), 5}, + {"a", "/p/b.cpp", range(1), 2}}; + const auto lenses = build(entries); + require(lenses.size() == 2); + expect(lenses[0].title == "1 reference"); +} + +VOID_TEST(CodeLens, is_sorted_and_bounded) { + const std::vector entries{{"c", "/p/a.cpp", range(9), 1}, + {"a", "/p/a.cpp", range(1), 1}, + {"b", "/p/a.cpp", range(5), 1}}; + const auto lenses = build(entries, Limits{.lenses = 2}); + require(lenses.size() == 2); + expect(lenses[0].range.start.line == 1); + expect(lenses[1].range.start.line == 5); +} + +VOID_TEST(CodeLens, rejects_malformed_and_bounds_fields) { + const std::vector entries{{"", "/p/a.cpp", range(1), 1}, + {"a", "", range(2), 1}, + {"b", "/p/a.cpp", {{3, 4}, {3, 1}}, 1}, + {"c", "/p/a.cpp", range(4), 1}}; + const auto lenses = build(entries); + require(lenses.size() == 1); + expect(lenses.front().title == "1 reference"); + const auto bounded = build(entries, Limits{.titleBytes = 4}); + require(!bounded.empty()); + expect(bounded.front().title == "1 re"); +}