Files
Language-Server/tests/features/CodeLensTests.cpp
T
faumaray 0bf5873069 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.
2026-12-05 17:50:38 +03:00

69 lines
2.6 KiB
C++

#include <vls/features/CodeLens.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
#include <vector>
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<Entry> 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<Entry> 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<Entry> 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<Entry> 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<Entry> 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");
}