SymbolIndex::find_by_path exposes one document's records with the same overlay shadowing and coverage as find. EditorDiagnostics maps them to textDocument/documentSymbol, and a bounded same-file highlight core (vls/features/DocumentSymbols.hpp) backs textDocument/documentHighlight from verified occurrence facts with the ambiguous-binding rule. Both are advertised and exercised over a real stdio session with the stock observer. Record the LSP parity matrix.
62 lines
2.5 KiB
C++
62 lines
2.5 KiB
C++
#include <vls/features/DocumentSymbols.hpp>
|
|
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <vector>
|
|
|
|
namespace {
|
|
using namespace vls::features::documents;
|
|
using Void::Testing::expect;
|
|
using Void::Testing::require;
|
|
|
|
Range range(std::uint32_t line, std::uint32_t character) {
|
|
return {{line, character}, {line, character + 4}};
|
|
}
|
|
|
|
Use use(std::string name, std::string path, Range span,
|
|
std::optional<Location> definition = std::nullopt) {
|
|
return {{std::move(name), std::move(definition)}, std::move(path), span};
|
|
}
|
|
|
|
Location definition(std::string path, std::uint32_t line) {
|
|
return {std::move(path), range(line, 0)};
|
|
}
|
|
} // namespace
|
|
|
|
VOID_TEST(DocumentSymbols, highlights_every_use_of_the_binding_at_the_position) {
|
|
const auto target = definition("/project/lib.cpp", 9);
|
|
const std::vector<Use> uses{use("f", "/project/a.cpp", range(1, 0), target),
|
|
use("f", "/project/a.cpp", range(3, 8), target),
|
|
use("f", "/project/b.cpp", range(2, 0), target),
|
|
use("g", "/project/a.cpp", range(5, 0))};
|
|
const auto result = highlights(uses, "/project/a.cpp", {1, 2});
|
|
require(result.size() == 2);
|
|
expect(result[0] == range(1, 0));
|
|
expect(result[1] == range(3, 8));
|
|
}
|
|
|
|
VOID_TEST(DocumentSymbols, no_unique_binding_means_no_highlights) {
|
|
const std::vector<Use> uses{use("f", "/project/a.cpp", range(1, 0)),
|
|
use("g", "/project/a.cpp", range(1, 0))};
|
|
expect(highlights(uses, "/project/a.cpp", {1, 1}).empty());
|
|
expect(highlights(uses, "/project/a.cpp", {9, 9}).empty());
|
|
expect(highlights(uses, "/project/other.cpp", {1, 1}).empty());
|
|
}
|
|
|
|
VOID_TEST(DocumentSymbols, highlights_deduplicate_and_bound) {
|
|
const auto target = definition("/project/lib.cpp", 9);
|
|
const std::vector<Use> uses{use("f", "/project/a.cpp", range(1, 0), target),
|
|
use("f", "/project/a.cpp", range(1, 0), target),
|
|
use("f", "/project/a.cpp", range(2, 0), target)};
|
|
expect(highlights(uses, "/project/a.cpp", {1, 1}).size() == 2);
|
|
expect(highlights(uses, "/project/a.cpp", {1, 1}, 1).size() == 1);
|
|
}
|
|
|
|
VOID_TEST(DocumentSymbols, same_spelling_without_a_shared_definition_is_ambiguous) {
|
|
const std::vector<Use> uses{
|
|
use("f", "/project/a.cpp", range(1, 0)),
|
|
use("f", "/project/a.cpp", range(1, 0), definition("/project/lib.cpp", 4))};
|
|
expect(highlights(uses, "/project/a.cpp", {1, 1}).empty());
|
|
}
|