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

+21
View File
@@ -8,6 +8,7 @@
#include <vls/features/Formatting.hpp>
#include <vls/features/IndexNavigation.hpp>
#include <vls/features/InlayHints.hpp>
#include <vls/features/Outline.hpp>
#include <vls/features/SemanticTokens.hpp>
#include <vls/features/SignatureHelp.hpp>
#include <vls/features/TextStructure.hpp>
@@ -1150,6 +1151,26 @@ Json EditorDiagnostics::document_symbols(std::string_view uri) const {
}
Json::Array symbols;
std::set<std::tuple<std::string, int, std::uint32_t, std::uint32_t>> seen;
// Text-proven outline entries work without any compiler-specific observer.
if (const auto snapshot = s.documents.snapshot(uri))
for (const auto &symbol : features::outline::outline(snapshot->text)) {
if (!seen.emplace(symbol.name, static_cast<int>(symbol.kind), symbol.range.start.line,
symbol.range.start.character)
.second)
continue;
Json::Object entry;
entry.emplace("name", Json{symbol.name});
entry.emplace("kind", Json{static_cast<std::int64_t>(symbol.kind)});
entry.emplace("range", range_json(Documents::Range{
{symbol.range.start.line, symbol.range.start.character},
{symbol.range.end.line, symbol.range.end.character}}));
entry.emplace(
"selectionRange",
range_json(Documents::Range{
{symbol.selection_range.start.line, symbol.selection_range.start.character},
{symbol.selection_range.end.line, symbol.selection_range.end.character}}));
symbols.push_back(Json{std::move(entry)});
}
for (const auto &record : records.symbols) {
const auto &location = record.location;
if (!seen.emplace(record.name, static_cast<int>(record.kind), location.line,