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:
1 parent
da8003f6d4
commit
8ca3dcbf74
16 files changed
+366
-8
No files matched your search
@@ -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_navigation_tests navigation/NavigationTests.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)
|
||||
target_link_libraries(vls_live_tests PRIVATE Void::System)
|
||||
add_dependencies(vls_live_tests vls_live_worker_fixture vls-dap)
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
@@ -441,3 +441,20 @@ VOID_TEST(SymbolIndex, schema_2_rejects_edited_records) {
|
||||
expect(restored->status == SymbolIndex::LoadStatus::corrupt);
|
||||
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());
|
||||
}
|
||||
Reference in new issue
Block a user