Serve document symbols and highlights over LSP

SymbolIndex::find_by_path exposes one document's records with the same
overlay shadowing and coverage as find. EditorDiagnostics maps them to
textDocument/documentSymbol, and a bounded same-file highlight core
(vls/features/DocumentSymbols.hpp) backs textDocument/documentHighlight
from verified occurrence facts with the ambiguous-binding rule. Both are
advertised and exercised over a real stdio session with the stock
observer. Record the LSP parity matrix.
This commit is contained in:
faumaray committed 2026-12-05 14:21:26 +03:00
1 parent da8003f6d4
commit 8ca3dcbf74
16 files changed
+366 -8

No files matched your search

+1 -1
View File
@@ -30,7 +30,7 @@ add_library(vls_protocol STATIC src/Protocol/Framing.cpp src/Protocol/Json.cpp
src/Build/ProviderFile.cpp src/Build/CommandImport.cpp src/Build/VbsProvider.cpp src/Build/ProviderFile.cpp src/Build/CommandImport.cpp src/Build/VbsProvider.cpp
src/Build/CompdbProvider.cpp src/DocumentSync.cpp src/WorkspaceSession.cpp src/Server.cpp src/Build/CompdbProvider.cpp src/DocumentSync.cpp src/WorkspaceSession.cpp src/Server.cpp
src/semantic/Diagnostics.cpp src/semantic/SourceCatalog.cpp src/semantic/StockCompiler.cpp src/semantic/EditorDiagnostics.cpp src/semantic/Occurrences.cpp src/scheduler/Scheduler.cpp src/semantic/Diagnostics.cpp src/semantic/SourceCatalog.cpp src/semantic/StockCompiler.cpp src/semantic/EditorDiagnostics.cpp src/semantic/Occurrences.cpp src/scheduler/Scheduler.cpp
src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp) src/modules/ModuleGraph.cpp src/modules/ArtifactCache.cpp src/modules/GccArtifacts.cpp src/modules/ScheduledArtifacts.cpp src/index/SymbolIndex.cpp src/navigation/Navigation.cpp src/reflection/Provenance.cpp src/features/Completion.cpp src/features/IndexNavigation.cpp src/features/SignatureHelp.cpp src/features/DocumentSymbols.cpp src/debug/live/LiveSession.cpp src/modules/ModuleWorkQueue.cpp src/modules/GccScan.cpp src/modules/ScanCommand.cpp)
target_include_directories(vls_protocol PUBLIC "${PROJECT_SOURCE_DIR}/include") target_include_directories(vls_protocol PUBLIC "${PROJECT_SOURCE_DIR}/include")
target_link_libraries(vls_protocol PUBLIC Void::Data PRIVATE Void::Unicode Void::Text Void::Crypto Void::System) target_link_libraries(vls_protocol PUBLIC Void::Data PRIVATE Void::Unicode Void::Text Void::Crypto Void::System)
target_compile_options(vls_protocol PUBLIC -freflection PRIVATE -Wall -Wextra -Wpedantic) target_compile_options(vls_protocol PUBLIC -freflection PRIVATE -Wall -Wextra -Wpedantic)
+5 -3
View File
@@ -69,6 +69,7 @@ void build(Void::Build::Project &project) {
"src/features/Completion.cpp", "src/features/Completion.cpp",
"src/features/IndexNavigation.cpp", "src/features/IndexNavigation.cpp",
"src/features/SignatureHelp.cpp", "src/features/SignatureHelp.cpp",
"src/features/DocumentSymbols.cpp",
"src/debug/live/LiveSession.cpp", "src/debug/live/LiveSession.cpp",
"src/modules/ModuleWorkQueue.cpp", "src/modules/ModuleWorkQueue.cpp",
"src/modules/GccScan.cpp", "src/modules/GccScan.cpp",
@@ -144,9 +145,10 @@ void build(Void::Build::Project &project) {
auto index_tests = suite("vls_index_tests", {"tests/index/SymbolIndexTests.cpp"}); auto index_tests = suite("vls_index_tests", {"tests/index/SymbolIndexTests.cpp"});
auto navigation_tests = suite("vls_navigation_tests", {"tests/navigation/NavigationTests.cpp"}); auto navigation_tests = suite("vls_navigation_tests", {"tests/navigation/NavigationTests.cpp"});
auto reflection_tests = suite("vls_reflection_tests", {"tests/reflection/ProvenanceTests.cpp"}); auto reflection_tests = suite("vls_reflection_tests", {"tests/reflection/ProvenanceTests.cpp"});
auto feature_tests = suite("vls_feature_tests", {"tests/features/CompletionTests.cpp", auto feature_tests =
"tests/features/IndexNavigationTests.cpp", suite("vls_feature_tests",
"tests/features/SignatureHelpTests.cpp"}); {"tests/features/CompletionTests.cpp", "tests/features/IndexNavigationTests.cpp",
"tests/features/SignatureHelpTests.cpp", "tests/features/DocumentSymbolsTests.cpp"});
auto live_worker = project.executable("vls_live_worker_fixture"); auto live_worker = project.executable("vls_live_worker_fixture");
live_worker.cxx_standard(CxxStandard::Cxx26) live_worker.cxx_standard(CxxStandard::Cxx26)
.sources({"tests/debug/LiveWorkerFixture.cpp"}) .sources({"tests/debug/LiveWorkerFixture.cpp"})
+43
View File
@@ -0,0 +1,43 @@
# LSP parity matrix
Target (user direction): clangd feature parity plus every LSP capability that
applies to a C++ language server. Status is evidence-based; `PARTIAL` names the
missing part.
## Implemented and verified
| Capability | Evidence |
| --- | --- |
| initialize / initialized / shutdown / exit | native transcripts and registered tests |
| textDocument sync (full + incremental, UTF-8/UTF-16) | document suite, real stdio corpora |
| publishDiagnostics (stock GCC, in-process default profile) | diagnostic suite, stdio corpus |
| textDocument/hover, definition | stock occurrence corpus |
| textDocument/references, prepareRename, rename | navigation suite, stock corpus refusals |
| textDocument/completion (+ completionItem/resolve) | `vls_feature_tests`, real stdio session |
| textDocument/signatureHelp | `vls_feature_tests`, real stdio session |
| textDocument/documentSymbol | `vls_index_tests` path query, real stdio session |
| textDocument/documentHighlight | `vls_feature_tests`, real stdio session |
| workspace/symbol | stock occurrence corpus |
| voidLanguageServer/analysisStatus, providerStatus | stdio corpora |
| Debug adapter (DAP) separately through `vls-dap` | `vls_live_tests`, `vls_dap_tests` |
## Open
| Capability | Notes |
| --- | --- |
| Compiler-native completion with visibility proof | index-backed completion is explicitly incomplete |
| Overload-set signature help | only the selected occurrence's signature is available |
| textDocument/selectionRange, foldingRange | straightforward next slices |
| textDocument/codeAction, formatting | compiler-backed; needs a plan |
| textDocument/semanticTokens, inlayHint | larger
| textDocument/codeLens, executeCommand | command surface not designed |
| callHierarchy / typeHierarchy | needs compiler call/type relationships |
| workspace edits and file operations | client-side application is also open |
| Applying multi-file renames through client buffers | plans can be ready; application is client work |
| `EditorDiagnostics` reflection LSP wiring | the server has no reflection data source |
## Next slices
1. selectionRange and foldingRange from document snapshots.
2. codeAction quick fixes from published diagnostics.
3. Semantic tokens from stock occurrences.
+1 -1
View File
@@ -102,7 +102,7 @@ ingests occurrence facts after each analysis and the server answers
Hash.hpp definition through it. Real persistence migrations and cross-file Hash.hpp definition through it. Real persistence migrations and cross-file
rename coverage remain open. rename coverage remain open.
Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Compiler-native completion with visibility proof and deferred detail resolution remain open. Index-backed completion (roadmap 14 first slice) is implemented: `include/vls/features/Completion.hpp`, `src/features/Completion.cpp` and registered `vls_feature_tests` cover prefix extraction, filtering with replacement ranges, label+kind deduplication, deterministic ranking and bounds. `Server.cpp` advertises `completionProvider` and answers `textDocument/completion` from the symbol index through `EditorDiagnostics::completion`; a real stdio session with the stock observer returned `fnv1a64` and `fnv1a64_update` at a real call site. Every result is marked incomplete because the index does not prove visibility. Signature help is now served from the compiler-provided occurrence signature (parameter labels and ranges, active parameter, innermost call selection) and advertised by the server. Document symbols are served from the index by path and document highlights from same-binding occurrence facts; both are advertised and were exercised over stdio with the stock observer. Compiler-native completion with visibility proof and deferred detail resolution remain open.
The reflection provenance representation (roadmap 12 first slice) is The reflection provenance representation (roadmap 12 first slice) is
implemented as a bounded library with a registered suite: innermost-first implemented as a bounded library with a registered suite: innermost-first
+1
View File
@@ -66,6 +66,7 @@ The original writer released the foundation files. Current ownership follows.
| T-PLAN-EDITORS-022 | COMPLETE | Root | Verified Neovim 0.12.6, nvim-dap cfa2d58, VS Code 1.147.0, Node 24.22.3. Two ownership-ready contracts: [T-CLIENT-NEOVIM-023](tasks/T-CLIENT-NEOVIM-023.md) and [T-CLIENT-VSCODE-022](tasks/T-CLIENT-VSCODE-022.md). | | T-PLAN-EDITORS-022 | COMPLETE | Root | Verified Neovim 0.12.6, nvim-dap cfa2d58, VS Code 1.147.0, Node 24.22.3. Two ownership-ready contracts: [T-CLIENT-NEOVIM-023](tasks/T-CLIENT-NEOVIM-023.md) and [T-CLIENT-VSCODE-022](tasks/T-CLIENT-VSCODE-022.md). |
| T-CLIENT-NEOVIM-023 | IMPLEMENTED_TESTED | Root | `clients/neovim/` and `tests/native/NeovimClient.lua` passed with the installed server, adapter and nvim-dap. VS Code client remains. | | T-CLIENT-NEOVIM-023 | IMPLEMENTED_TESTED | Root | `clients/neovim/` and `tests/native/NeovimClient.lua` passed with the installed server, adapter and nvim-dap. VS Code client remains. |
| T-CLIENT-VSCODE-022 | IMPLEMENTED_TESTED | Root | `clients/vscode/` and `tests/native/VscodeClient.py` passed in a disposable extension host with VS Code 1.147.0. | | T-CLIENT-VSCODE-022 | IMPLEMENTED_TESTED | Root | `clients/vscode/` and `tests/native/VscodeClient.py` passed in a disposable extension host with VS Code 1.147.0. |
| T-LSP-PARITY-014 | PARTIAL | Root | Parity program (user direction: clangd parity plus the full applicable LSP surface). This slice: `textDocument/documentSymbol` from `SymbolIndex::find_by_path`, `textDocument/documentHighlight` from registered `vls_feature_tests` core, both advertised and exercised over stdio. Open: selectionRange, foldingRange, code actions, formatting, semantic tokens, inlay hints, call/type hierarchy, code lens, executeCommand, workspace edits/file operations, compiler-native completion, overload signature help, client-side multi-file rename application. [Matrix](LSP-PARITY.md). |
Per D-027 the generic runtime uses an explicit GPT-6.2 model and Max for each Per D-027 the generic runtime uses an explicit GPT-6.2 model and Max for each
assignment. The suggested Sol implementation assignment follows planner/preflight. assignment. The suggested Sol implementation assignment follows planner/preflight.
+20
View File
@@ -79,6 +79,26 @@ the upgraded snapshot (keeping `snapshot.prev.json`) and rewrites a legacy
about 25-30s in a Debug build (it passed VBS at ~27s); the full CMake run then about 25-30s in a Debug build (it passed VBS at ~27s); the full CMake run then
passed 18/18. passed 18/18.
## December 5 document symbols and document highlights
`SymbolIndex::find_by_path` returns the records whose use location is in one
path with the same overlay shadowing, deduplication, coverage and truncation as
`find` (registered `vls_index_tests` case
`finds_records_by_path_with_overlay_shadowing`). `EditorDiagnostics` maps it to
`textDocument/documentSymbol` and advertises `documentSymbolProvider`.
`include/vls/features/DocumentSymbols.hpp` adds a bounded, same-file highlight
core (`highlights`), used by `textDocument/documentHighlight` from the verified
occurrence facts with the ambiguous-binding rule; the server advertises
`documentHighlightProvider`.
A real stdio session with the stock observer on `DocumentSnapshot.cpp`:
```
documentSymbol: 1 first: ['fnv1a64']
documentHighlight: [(18, 33, 1)]
```
All 18 native suites and all 18 CMake tests passed. The outline currently
contains only recorded uses (the observer reports calls), not declarations.
## December 5 signature help from stock occurrence facts ## December 5 signature help from stock occurrence facts
`include/vls/features/SignatureHelp.hpp` and `include/vls/features/SignatureHelp.hpp` and
+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace vls::features::documents {
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 Location {
std::string path;
Range range;
auto operator<=>(const Location &) const = default;
};
// Semantic identity of one binding, joined by definition like navigation.
struct Binding {
std::string name;
std::optional<Location> definition;
auto operator<=>(const Binding &) const = default;
};
struct Use {
Binding binding;
std::string path;
Range range;
};
// Ranges of every proven use of the binding at the position, restricted to
// the same file, deduplicated and bounded. An empty result means no unique
// binding covers the position.
[[nodiscard]] std::vector<Range> highlights(std::span<const Use>, std::string_view path, Position,
std::size_t limit = 512);
} // namespace vls::features::documents
+3
View File
@@ -121,6 +121,9 @@ class SymbolIndex {
const std::optional<std::string> &content); const std::optional<std::string> &content);
[[nodiscard]] Result find(const Query &) const; [[nodiscard]] Result find(const Query &) const;
// Records whose use location is in PATH, with the same overlay shadowing,
// deduplication and coverage reporting as find().
[[nodiscard]] Result find_by_path(std::string_view path, std::size_t limit = 4096) const;
[[nodiscard]] Coverage coverage() const; [[nodiscard]] Coverage coverage() const;
[[nodiscard]] std::shared_ptr<const Generation> current() const; [[nodiscard]] std::shared_ptr<const Generation> current() const;
[[nodiscard]] std::uint64_t generation() const; [[nodiscard]] std::uint64_t generation() const;
@@ -37,6 +37,11 @@ class EditorDiagnostics {
// without details rather than details for a different entity. // without details rather than details for a different entity.
[[nodiscard]] Void::LanguageServer::Protocol::Json [[nodiscard]] Void::LanguageServer::Protocol::Json
completion_resolve(const Void::LanguageServer::Protocol::Json &item) const; completion_resolve(const Void::LanguageServer::Protocol::Json &item) const;
// Outline of the records the index holds for one document path.
[[nodiscard]] Void::LanguageServer::Protocol::Json document_symbols(std::string_view uri) const;
// 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;
struct NavigationReply { struct NavigationReply {
Void::LanguageServer::Protocol::Json result; Void::LanguageServer::Protocol::Json result;
+16 -2
View File
@@ -260,9 +260,13 @@ DispatchResult Server::handle(std::string_view body) {
Json{Json::Object{ Json{Json::Object{
{"workspaceFolders", Json{Json::Object{{"supported", Json{true}}, {"workspaceFolders", Json{Json::Object{{"supported", Json{true}},
{"changeNotifications", Json{true}}}}}}}}}; {"changeNotifications", Json{true}}}}}}}}};
if (diagnostics_) {
capabilities.emplace("documentSymbolProvider", Json{true});
}
if (diagnostics_ && diagnostics_->supports_occurrences()) { if (diagnostics_ && diagnostics_->supports_occurrences()) {
capabilities.emplace("hoverProvider", Json{true}); capabilities.emplace("hoverProvider", Json{true});
capabilities.emplace("definitionProvider", Json{true}); capabilities.emplace("definitionProvider", Json{true});
capabilities.emplace("documentHighlightProvider", Json{true});
} }
if (diagnostics_) if (diagnostics_)
capabilities.emplace("completionProvider", capabilities.emplace("completionProvider",
@@ -301,7 +305,7 @@ DispatchResult Server::handle(std::string_view body) {
: Json{Json::Object{{"state", Json{std::string{"disabled"}}}}}); : Json{Json::Object{{"state", Json{std::string{"disabled"}}}}});
} }
if (*method == "textDocument/hover" || *method == "textDocument/definition" || if (*method == "textDocument/hover" || *method == "textDocument/definition" ||
*method == "textDocument/signatureHelp") { *method == "textDocument/signatureHelp" || *method == "textDocument/documentHighlight") {
if (!diagnostics_ || !diagnostics_->supports_occurrences()) if (!diagnostics_ || !diagnostics_->supports_occurrences())
return error(id, -32601, "Method not found"); return error(id, -32601, "Method not found");
const auto *uri = as_string(member(member(params, "textDocument"), "uri")); const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
@@ -321,7 +325,9 @@ DispatchResult Server::handle(std::string_view body) {
auto result = *method == "textDocument/hover" ? diagnostics_->hover(*uri, selected) auto result = *method == "textDocument/hover" ? diagnostics_->hover(*uri, selected)
: *method == "textDocument/definition" : *method == "textDocument/definition"
? diagnostics_->definition(*uri, selected) ? diagnostics_->definition(*uri, selected)
: diagnostics_->signature_help(*uri, selected); : *method == "textDocument/signatureHelp"
? diagnostics_->signature_help(*uri, selected)
: diagnostics_->document_highlights(*uri, selected);
return reply(id, "result", std::move(result)); return reply(id, "result", std::move(result));
} }
if (*method == "completionItem/resolve") { if (*method == "completionItem/resolve") {
@@ -331,6 +337,14 @@ DispatchResult Server::handle(std::string_view body) {
return error(id, -32602, "Expected a completion item"); return error(id, -32602, "Expected a completion item");
return reply(id, "result", diagnostics_->completion_resolve(*params)); return reply(id, "result", diagnostics_->completion_resolve(*params));
} }
if (*method == "textDocument/documentSymbol") {
if (!diagnostics_)
return error(id, -32601, "Method not found");
const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri))
return error(id, -32602, "Expected textDocument.uri");
return reply(id, "result", diagnostics_->document_symbols(*uri));
}
if (*method == "textDocument/completion") { if (*method == "textDocument/completion") {
if (!diagnostics_) if (!diagnostics_)
return error(id, -32601, "Method not found"); return error(id, -32601, "Method not found");
+29
View File
@@ -0,0 +1,29 @@
#include <vls/features/DocumentSymbols.hpp>
#include <set>
#include <tuple>
namespace vls::features::documents {
std::vector<Range> highlights(std::span<const Use> uses, std::string_view path, Position position,
std::size_t limit) {
std::set<Binding> candidates;
for (const auto &use : uses)
if (use.path == path && use.range.start <= position && position <= use.range.end)
candidates.insert(use.binding);
std::vector<Range> result;
if (candidates.size() != 1)
return result;
std::set<Range> unique;
for (const auto &use : uses)
if (use.path == path && use.binding == *candidates.begin())
unique.insert(use.range);
for (const auto &range : unique) {
if (result.size() == limit)
break;
result.push_back(range);
}
return result;
}
} // namespace vls::features::documents
+34
View File
@@ -462,6 +462,40 @@ Result SymbolIndex::find(const Query &query) const {
return result; return result;
} }
Result SymbolIndex::find_by_path(std::string_view path, std::size_t limit) const {
auto &state = *state_;
std::lock_guard lock{state.mutex};
Result result;
result.coverage = state.coverage_locked(std::nullopt);
std::set<std::tuple<std::string, SymbolKind, Location>> seen;
std::set<std::string> shadowed;
for (const auto &[overlay_path, overlay] : state.overlays)
shadowed.insert(overlay_path);
const auto consider = [&](const SymbolRecord &record) {
if (record.location.path != path)
return;
if (!seen.emplace(record.name, record.kind, record.location).second)
return;
result.symbols.push_back(record);
};
for (const auto &[name, entry] : state.contexts)
for (const auto &record : entry.records)
if (!shadowed.contains(record.location.path))
consider(record);
for (const auto &[overlay_path, overlay] : state.overlays)
for (const auto &record : overlay.records)
consider(record);
std::ranges::sort(result.symbols, [](const auto &left, const auto &right) {
return std::tie(left.location, left.name, left.kind) <
std::tie(right.location, right.name, right.kind);
});
if (result.symbols.size() > limit) {
result.symbols.resize(limit);
result.truncated = true;
}
return result;
}
Coverage SymbolIndex::coverage() const { Coverage SymbolIndex::coverage() const {
auto &state = *state_; auto &state = *state_;
std::lock_guard lock{state.mutex}; std::lock_guard lock{state.mutex};
+80
View File
@@ -1,6 +1,7 @@
#include <vls/semantic/EditorDiagnostics.hpp> #include <vls/semantic/EditorDiagnostics.hpp>
#include <vls/features/Completion.hpp> #include <vls/features/Completion.hpp>
#include <vls/features/DocumentSymbols.hpp>
#include <vls/features/IndexNavigation.hpp> #include <vls/features/IndexNavigation.hpp>
#include <vls/features/SignatureHelp.hpp> #include <vls/features/SignatureHelp.hpp>
#include <vls/index/SymbolIndex.hpp> #include <vls/index/SymbolIndex.hpp>
@@ -973,6 +974,85 @@ Json EditorDiagnostics::completion_resolve(const Json &item) const {
return Json{std::move(enriched)}; return Json{std::move(enriched)};
} }
Json EditorDiagnostics::document_symbols(std::string_view uri) const {
auto &s = *state_;
const auto identity = Documents::normalize_uri(uri);
if (!identity || !identity->is_file_uri)
return Json{nullptr};
index::Result records;
{
std::lock_guard lock{s.mutex};
records = s.symbols.find_by_path(identity->canonical_path.native());
}
Json::Array symbols;
std::set<std::tuple<std::string, int, std::uint32_t, std::uint32_t>> seen;
for (const auto &record : records.symbols) {
const auto &location = record.location;
if (!seen.emplace(record.name, static_cast<int>(record.kind), location.line,
location.character)
.second)
continue;
const auto range = range_json(Documents::Range{{location.line, location.character},
{location.endLine, location.endCharacter}});
symbols.push_back(Json{Json::Object{{"name", Json{record.name}},
{"kind", Json{symbol_kind(record.kind)}},
{"range", range},
{"selectionRange", range}}});
}
return Json{std::move(symbols)};
}
Json EditorDiagnostics::document_highlights(std::string_view uri,
Documents::Position position) const {
auto &s = *state_;
auto key = Documents::client_uri_key(uri);
std::shared_ptr<const Receipt> receipt;
std::shared_ptr<const std::vector<Occurrence>> facts;
{
std::lock_guard lock{s.mutex};
const auto i = key ? s.entries.find(*key) : s.entries.end();
if (i == s.entries.end())
return Json{nullptr};
receipt = i->second.receipt;
facts = i->second.occurrences;
}
if (!receipt || !facts || !s.valid(*receipt))
return Json{nullptr};
const Documents::DocumentSnapshot *snapshot = nullptr;
for (const auto &entry : receipt->capture->entries())
if (entry.snapshot && entry.snapshot->identity.canonical_uri == *key) {
snapshot = entry.snapshot.get();
break;
}
if (!snapshot)
return Json{nullptr};
std::vector<features::documents::Use> uses;
for (const auto &occurrence : *facts) {
if (occurrence.use_file.get() != snapshot)
continue;
features::documents::Use use;
use.binding.name = occurrence.name;
if (occurrence.has_definition())
use.binding.definition = features::documents::Location{
occurrence.definition_file->identity.canonical_path.native(),
{{occurrence.definition.start.line, occurrence.definition.start.character},
{occurrence.definition.end.line, occurrence.definition.end.character}}};
use.path = snapshot->identity.canonical_path.native();
use.range = {{occurrence.use.start.line, occurrence.use.start.character},
{occurrence.use.end.line, occurrence.use.end.character}};
uses.push_back(std::move(use));
}
const auto ranges = features::documents::highlights(
uses, snapshot->identity.canonical_path.native(), {position.line, position.character});
Json::Array result;
for (const auto &range : ranges)
result.push_back(Json{Json::Object{
{"range", range_json(Documents::Range{{range.start.line, range.start.character},
{range.end.line, range.end.character}})},
{"kind", Json{std::int64_t{1}}}}});
return Json{std::move(result)};
}
void EditorDiagnostics::set_transactional_rename(bool supported) { void EditorDiagnostics::set_transactional_rename(bool supported) {
std::lock_guard lock{state_->mutex}; std::lock_guard lock{state_->mutex};
state_->transactional_rename = supported; state_->transactional_rename = supported;
+1 -1
View File
@@ -22,7 +22,7 @@ vls_test_suite(vls_scheduler_tests scheduler/SchedulerTests.cpp)
vls_test_suite(vls_index_tests index/SymbolIndexTests.cpp) vls_test_suite(vls_index_tests index/SymbolIndexTests.cpp)
vls_test_suite(vls_navigation_tests navigation/NavigationTests.cpp) vls_test_suite(vls_navigation_tests navigation/NavigationTests.cpp)
vls_test_suite(vls_reflection_tests reflection/ProvenanceTests.cpp) vls_test_suite(vls_reflection_tests reflection/ProvenanceTests.cpp)
vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp) vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp)
vls_test_suite(vls_live_tests debug/LiveSessionTests.cpp debug/LiveDapTests.cpp) vls_test_suite(vls_live_tests debug/LiveSessionTests.cpp debug/LiveDapTests.cpp)
target_link_libraries(vls_live_tests PRIVATE Void::System) target_link_libraries(vls_live_tests PRIVATE Void::System)
add_dependencies(vls_live_tests vls_live_worker_fixture vls-dap) add_dependencies(vls_live_tests vls_live_worker_fixture vls-dap)
+61
View File
@@ -0,0 +1,61 @@
#include <vls/features/DocumentSymbols.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <vector>
namespace {
using namespace vls::features::documents;
using Void::Testing::expect;
using Void::Testing::require;
Range range(std::uint32_t line, std::uint32_t character) {
return {{line, character}, {line, character + 4}};
}
Use use(std::string name, std::string path, Range span,
std::optional<Location> definition = std::nullopt) {
return {{std::move(name), std::move(definition)}, std::move(path), span};
}
Location definition(std::string path, std::uint32_t line) {
return {std::move(path), range(line, 0)};
}
} // namespace
VOID_TEST(DocumentSymbols, highlights_every_use_of_the_binding_at_the_position) {
const auto target = definition("/project/lib.cpp", 9);
const std::vector<Use> uses{use("f", "/project/a.cpp", range(1, 0), target),
use("f", "/project/a.cpp", range(3, 8), target),
use("f", "/project/b.cpp", range(2, 0), target),
use("g", "/project/a.cpp", range(5, 0))};
const auto result = highlights(uses, "/project/a.cpp", {1, 2});
require(result.size() == 2);
expect(result[0] == range(1, 0));
expect(result[1] == range(3, 8));
}
VOID_TEST(DocumentSymbols, no_unique_binding_means_no_highlights) {
const std::vector<Use> uses{use("f", "/project/a.cpp", range(1, 0)),
use("g", "/project/a.cpp", range(1, 0))};
expect(highlights(uses, "/project/a.cpp", {1, 1}).empty());
expect(highlights(uses, "/project/a.cpp", {9, 9}).empty());
expect(highlights(uses, "/project/other.cpp", {1, 1}).empty());
}
VOID_TEST(DocumentSymbols, highlights_deduplicate_and_bound) {
const auto target = definition("/project/lib.cpp", 9);
const std::vector<Use> uses{use("f", "/project/a.cpp", range(1, 0), target),
use("f", "/project/a.cpp", range(1, 0), target),
use("f", "/project/a.cpp", range(2, 0), target)};
expect(highlights(uses, "/project/a.cpp", {1, 1}).size() == 2);
expect(highlights(uses, "/project/a.cpp", {1, 1}, 1).size() == 1);
}
VOID_TEST(DocumentSymbols, same_spelling_without_a_shared_definition_is_ambiguous) {
const std::vector<Use> uses{
use("f", "/project/a.cpp", range(1, 0)),
use("f", "/project/a.cpp", range(1, 0), definition("/project/lib.cpp", 4))};
expect(highlights(uses, "/project/a.cpp", {1, 1}).empty());
}
+17
View File
@@ -441,3 +441,20 @@ VOID_TEST(SymbolIndex, schema_2_rejects_edited_records) {
expect(restored->status == SymbolIndex::LoadStatus::corrupt); expect(restored->status == SymbolIndex::LoadStatus::corrupt);
expect(restored->quarantine.has_value()); expect(restored->quarantine.has_value());
} }
VOID_TEST(SymbolIndex, finds_records_by_path_with_overlay_shadowing) {
SymbolIndex index;
require(index.publish(
context("debug:a", {record("a", "/project/a.cpp", 1), record("b", "/project/b.cpp", 2)})));
require(index.publish(context("debug:b", {record("c", "/project/a.cpp", 9)})));
auto result = index.find_by_path("/project/a.cpp");
require(result.symbols.size() == 2);
expect(result.symbols[0].name == "a" && result.symbols[1].name == "c");
expect(result.coverage.indexed && !result.truncated);
expect(index.find_by_path("/project/a.cpp", 1).truncated);
require(index.set_overlay("/project/a.cpp", "content", {record("d", "/project/a.cpp", 4)}));
result = index.find_by_path("/project/a.cpp");
require(result.symbols.size() == 1);
expect(result.symbols.front().name == "d");
expect(index.find_by_path("/project/absent.cpp").symbols.empty());
}