Add a compiler-independent document outline

A bounded scanner recognizes namespace, class/struct, enum and function
declarations at line starts from document text alone, skipping
preprocessor lines, comments and control statements. documentSymbol
merges it with observer-fed index records, so the generic path has a
real outline with no compiler-specific artifact. Registered feature
tests cover recognition, call exclusion, comments, ranges and bounds;
the generic stdio session returned main as a function symbol.
This commit is contained in:
faumaray committed 2026-12-06 01:25:53 +03:00
1 parent 5598371fcb
commit 103b38a291
8 files changed
+313 -3

No files matched your search

+1 -1
View File
@@ -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 features/CodeLensTests.cpp features/DocumentLinksTests.cpp features/FormattingTests.cpp features/TypeHierarchyTests.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 features/DocumentLinksTests.cpp features/FormattingTests.cpp features/TypeHierarchyTests.cpp features/OutlineTests.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)
+77
View File
@@ -0,0 +1,77 @@
#include <vls/features/Outline.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
#include <vector>
namespace {
using namespace vls::features::outline;
using Void::Testing::expect;
using Void::Testing::require;
std::vector<std::string> names(const std::vector<Symbol> &symbols) {
std::vector<std::string> result;
for (const auto &symbol : symbols)
result.push_back(symbol.name);
return result;
}
} // namespace
VOID_TEST(Outline, recognizes_namespaces_classes_and_enums) {
const std::string text = "namespace demo {\n"
"struct Point {\n"
" int x;\n"
"};\n"
"enum class Color { red };\n"
"class Widget;\n"
"}\n";
const auto symbols = outline(text);
expect(names(symbols) == std::vector<std::string>{"demo", "Point", "Color", "Widget"});
expect(symbols[0].kind == Kind::namespace_);
expect(symbols[1].kind == Kind::class_);
expect(symbols[2].kind == Kind::enum_);
expect(symbols[3].kind == Kind::class_);
}
VOID_TEST(Outline, distinguishes_functions_from_call_statements) {
const std::string text = "int compute(int value) { return value; }\n"
"void run() {\n"
" compute(1);\n"
" if (compute(2)) {}\n"
" auto x = compute(3);\n"
"}\n";
const auto symbols = outline(text);
expect(names(symbols) == std::vector<std::string>{"compute", "run"});
expect(symbols[0].kind == Kind::function);
}
VOID_TEST(Outline, skips_preprocessor_and_comments) {
const std::string text = "#define fake(x) x\n"
"// int commented();\n"
"/* void blocked();\n"
" int still_blocked(); */\n"
"int real();\n";
expect(names(outline(text)) == std::vector<std::string>{"real"});
}
VOID_TEST(Outline, ranges_cover_the_line_and_the_name) {
const std::string text = " int value(int a) { return a; }\n";
const auto symbols = outline(text);
require(symbols.size() == 1);
expect(symbols[0].range.start == Position{0, 0});
expect(symbols[0].range.end.character == text.size() - 1);
expect(symbols[0].selection_range.start == Position{0, 6});
expect(symbols[0].selection_range.end == Position{0, 11});
}
VOID_TEST(Outline, is_bounded) {
std::string text;
for (int line = 0; line != 20; ++line)
text += "int f" + std::to_string(line) + "();\n";
expect(outline(text).size() == 20);
expect(outline(text, Limits{.symbols = 3}).size() == 3);
expect(outline(" int " + std::string(300, 'x') + "();\n", Limits{.nameBytes = 8}).empty());
expect(outline(text, Limits{.scanBytes = 10}).size() == 1);
}