Files
Language-Server/include/vls/features/Outline.hpp
T
faumaray 103b38a291 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.
2026-12-06 01:25:53 +03:00

46 lines
1.3 KiB
C++

#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
namespace vls::features::outline {
struct Position {
std::uint32_t line{}, character{};
auto operator<=>(const Position &) const = default;
};
struct Range {
Position start, end;
auto operator<=>(const Range &) const = default;
};
// LSP SymbolKind subset this generic outline can prove from text alone.
enum class Kind { namespace_ = 3, class_ = 5, method = 6, function = 12, enum_ = 10 };
struct Symbol {
std::string name;
Kind kind{Kind::function};
Range range; // the declaration line
Range selection_range; // the name
auto operator<=>(const Symbol &) const = default;
};
struct Limits {
std::size_t symbols{4096};
std::size_t nameBytes{256};
std::size_t scanBytes{8 * 1024 * 1024};
std::size_t lineBytes{64 * 1024};
};
// A conservative, compiler-independent outline: namespace, class/struct,
// enum and function declarations recognized at the start of a physical line.
// Preprocessor lines, comments and control statements are skipped, and a
// call statement without a type prefix is never reported as a function.
[[nodiscard]] std::vector<Symbol> outline(std::string_view text, const Limits & = Limits{});
} // namespace vls::features::outline