#include #include #include #include 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 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 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 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 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 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()); }