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
@@ -4,6 +4,7 @@
|
||||
#include <vls/features/DocumentSymbols.hpp>
|
||||
#include <vls/features/IndexNavigation.hpp>
|
||||
#include <vls/features/SignatureHelp.hpp>
|
||||
#include <vls/features/TextStructure.hpp>
|
||||
#include <vls/index/SymbolIndex.hpp>
|
||||
#include <vls/modules/ArtifactCache.hpp>
|
||||
#include <vls/modules/GccArtifacts.hpp>
|
||||
@@ -1053,6 +1054,44 @@ Json EditorDiagnostics::document_highlights(std::string_view uri,
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::selection_ranges(std::string_view uri,
|
||||
std::span<const Documents::Position> positions) const {
|
||||
const auto snapshot = state_->documents.snapshot(uri);
|
||||
if (!snapshot)
|
||||
return Json{nullptr};
|
||||
Json::Array result;
|
||||
for (const auto &position : positions) {
|
||||
const auto chain = features::structure::selection_chain(
|
||||
snapshot->text, {position.line, position.character});
|
||||
Json nested;
|
||||
for (auto entry = chain.rbegin(); entry != chain.rend(); ++entry) {
|
||||
Json::Object node{
|
||||
{"range", range_json(Documents::Range{{entry->start.line, entry->start.character},
|
||||
{entry->end.line, entry->end.character}})}};
|
||||
if (!std::holds_alternative<std::nullptr_t>(nested.value))
|
||||
node.emplace("parent", nested);
|
||||
nested = Json{std::move(node)};
|
||||
}
|
||||
result.push_back(nested);
|
||||
}
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
Json EditorDiagnostics::folding_ranges(std::string_view uri) const {
|
||||
const auto snapshot = state_->documents.snapshot(uri);
|
||||
if (!snapshot)
|
||||
return Json{nullptr};
|
||||
Json::Array result;
|
||||
for (const auto &fold : features::structure::folding_ranges(snapshot->text)) {
|
||||
Json::Object entry{{"startLine", Json{static_cast<std::int64_t>(fold.start_line)}},
|
||||
{"endLine", Json{static_cast<std::int64_t>(fold.end_line)}}};
|
||||
if (!fold.kind.empty())
|
||||
entry.emplace("kind", Json{std::string{fold.kind}});
|
||||
result.push_back(Json{std::move(entry)});
|
||||
}
|
||||
return Json{std::move(result)};
|
||||
}
|
||||
|
||||
void EditorDiagnostics::set_transactional_rename(bool supported) {
|
||||
std::lock_guard lock{state_->mutex};
|
||||
state_->transactional_rename = supported;
|
||||
|
||||
Reference in new issue
Block a user