Serve selection and folding ranges over LSP
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.
This commit is contained in:
1 parent
8ca3dcbf74
commit
624c24d028
12 files changed
+601
-8
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#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
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <vls/semantic/StockCompiler.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <span>
|
||||
|
||||
namespace vls::semantic {
|
||||
|
||||
@@ -42,6 +43,11 @@ class EditorDiagnostics {
|
||||
// Same-binding uses within the document, or an empty list.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
document_highlights(std::string_view uri, Documents::Position position) const;
|
||||
// Nested selection chains (token, line, blocks, document) per position.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json
|
||||
selection_ranges(std::string_view uri, std::span<const Documents::Position>) const;
|
||||
// Foldable brace blocks, comments, regions and include groups.
|
||||
[[nodiscard]] Void::LanguageServer::Protocol::Json folding_ranges(std::string_view uri) const;
|
||||
|
||||
struct NavigationReply {
|
||||
Void::LanguageServer::Protocol::Json result;
|
||||
|
||||
Reference in new issue
Block a user