A bounded core resolves quoted include directives from the document directory and reports the spelling range; the server advertises documentLinkProvider and serves textDocument/documentLink from snapshots, keeping only targets that exist on disk. Angle includes are skipped because their search roots are unknown. Registered feature tests cover resolution, indentation, line counting, skipping and bounds, and the exact-capability-set assertion was updated. A real stdio session linked extra.hpp and skipped <vector> and a missing file.
62 lines
2.3 KiB
C++
62 lines
2.3 KiB
C++
#include <vls/features/DocumentLinks.hpp>
|
|
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
using namespace vls::features::document_links;
|
|
using Void::Testing::expect;
|
|
using Void::Testing::require;
|
|
} // namespace
|
|
|
|
VOID_TEST(DocumentLinks, resolves_quoted_includes_from_the_document_directory) {
|
|
const std::string text = "#pragma once\n#include \"extra.hpp\"\nint x;\n";
|
|
const auto links = includes(text, "/project/main.cpp");
|
|
require(links.size() == 1);
|
|
expect(links.front().path == "/project/extra.hpp");
|
|
expect(links.front().range.start == Position{1, 10});
|
|
expect(links.front().range.end == Position{1, 19});
|
|
const auto nested = includes("#include \"sub/extra.hpp\"\n", "/project/main.cpp");
|
|
require(nested.size() == 1);
|
|
expect(nested.front().path == "/project/sub/extra.hpp");
|
|
}
|
|
|
|
VOID_TEST(DocumentLinks, skips_angle_includes_and_system_roots) {
|
|
const std::string text = "#include <vector>\n#include \"local.hpp\"\n";
|
|
const auto links = includes(text, "/project/main.cpp");
|
|
require(links.size() == 1);
|
|
expect(links.front().path == "/project/local.hpp");
|
|
}
|
|
|
|
VOID_TEST(DocumentLinks, keeps_absolute_spellings) {
|
|
const auto links = includes("#include \"/opt/inc/a.hpp\"\n", "/project/main.cpp");
|
|
require(links.size() == 1);
|
|
expect(links.front().path == "/opt/inc/a.hpp");
|
|
}
|
|
|
|
VOID_TEST(DocumentLinks, skips_unterminated_and_indented_forms) {
|
|
expect(includes("#include \"unterminated\n", "/project/main.cpp").empty());
|
|
const auto indented = includes(" #include \"a.hpp\"\n", "/project/main.cpp");
|
|
require(indented.size() == 1);
|
|
expect(indented.front().range.start.character == 12);
|
|
}
|
|
|
|
VOID_TEST(DocumentLinks, counts_lines_across_the_document) {
|
|
const std::string text = "int a;\n\n#include \"x.hpp\"\n";
|
|
const auto links = includes(text, "/project/main.cpp");
|
|
require(links.size() == 1);
|
|
expect(links.front().range.start.line == 2);
|
|
}
|
|
|
|
VOID_TEST(DocumentLinks, is_bounded) {
|
|
std::string text;
|
|
for (int line = 0; line != 4; ++line)
|
|
text += "#include \"a.hpp\"\n";
|
|
expect(includes(text, "/project/main.cpp", Limits{.links = 2}).size() == 2);
|
|
expect(includes(text, "/project/main.cpp", Limits{.scanBytes = 10}).empty());
|
|
expect(includes(text, "/project/main.cpp", Limits{.pathBytes = 4}).empty());
|
|
}
|