A bounded snapshot-only core (vls/features/TextStructure.hpp) builds nested selection chains (identifier, line, enclosing blocks, document) and foldable regions (brace blocks, comments, preprocessor pairs, include groups) while ignoring literals. The server advertises and serves textDocument/selectionRange with bounded positions and textDocument/foldingRange through EditorDiagnostics; registered vls_feature_tests cases cover both.
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <compare>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace vls::features::structure {
|
|
|
|
struct Position {
|
|
std::uint32_t line{}, character{};
|
|
auto operator<=>(const Position &) const = default;
|
|
};
|
|
|
|
struct Range {
|
|
Position start, end;
|
|
auto operator<=>(const Range &) const = default;
|
|
};
|
|
|
|
struct Folding {
|
|
std::uint32_t start_line{}, end_line{};
|
|
std::string_view kind; // "comment", "region", "imports" or empty
|
|
auto operator<=>(const Folding &) const = default;
|
|
};
|
|
|
|
struct Limits {
|
|
std::size_t selectionDepth{8};
|
|
std::size_t scanBytes{1024 * 1024};
|
|
std::size_t folds{4096};
|
|
std::size_t positions{256};
|
|
};
|
|
|
|
// Innermost first: the identifier at the position, its line, each enclosing
|
|
// brace block (only openings within the bounded window) and the whole
|
|
// document. Consecutive duplicates are removed.
|
|
[[nodiscard]] std::vector<Range> selection_chain(std::string_view text, Position,
|
|
const Limits & = Limits{});
|
|
|
|
// Multi-line brace blocks, block comments, grouped line comments, #if/#endif
|
|
// and #region/#endregion pairs, and include groups, in source order and
|
|
// bounded. Braces inside literals or comments never open a block.
|
|
[[nodiscard]] std::vector<Folding> folding_ranges(std::string_view text, const Limits & = Limits{});
|
|
|
|
} // namespace vls::features::structure
|