Serve reference code lenses and the showReferences command
A bounded core builds one lens per document position with its proven reference count. EditorDiagnostics counts index records by name and definition and serves textDocument/codeLens; workspace/executeCommand implements vls.showReferences via the navigation binding. Registered feature tests cover titles, arguments, deduplication and bounds. A real stdio session showed the one-reference lens at the fnv1a64 call and resolved it to the source location.
This commit is contained in:
1 parent
ec86a79a1a
commit
0bf5873069
12 files changed
+279
-5
No files matched your search
+1
-1
@@ -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/features/DocumentSymbols.cpp src/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.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/features/TextStructure.cpp src/features/CodeActions.cpp src/features/SemanticTokens.cpp src/features/InlayHints.cpp src/features/FileOperations.cpp src/features/IncludeUpdate.cpp src/features/CallHierarchy.cpp src/features/CodeLens.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)
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ void build(Void::Build::Project &project) {
|
|||||||
"src/features/FileOperations.cpp",
|
"src/features/FileOperations.cpp",
|
||||||
"src/features/IncludeUpdate.cpp",
|
"src/features/IncludeUpdate.cpp",
|
||||||
"src/features/CallHierarchy.cpp",
|
"src/features/CallHierarchy.cpp",
|
||||||
|
"src/features/CodeLens.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",
|
||||||
@@ -159,7 +160,7 @@ void build(Void::Build::Project &project) {
|
|||||||
"tests/features/TextStructureTests.cpp", "tests/features/CodeActionsTests.cpp",
|
"tests/features/TextStructureTests.cpp", "tests/features/CodeActionsTests.cpp",
|
||||||
"tests/features/SemanticTokensTests.cpp", "tests/features/InlayHintsTests.cpp",
|
"tests/features/SemanticTokensTests.cpp", "tests/features/InlayHintsTests.cpp",
|
||||||
"tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp",
|
"tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp",
|
||||||
"tests/features/CallHierarchyTests.cpp"});
|
"tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.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"})
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
|||||||
| textDocument/codeAction (quickfix) | `vls_feature_tests` + `vls_diagnostic_tests`, real stdio session |
|
| textDocument/codeAction (quickfix) | `vls_feature_tests` + `vls_diagnostic_tests`, real stdio session |
|
||||||
| textDocument/semanticTokens/full | `vls_feature_tests`, real stdio session |
|
| textDocument/semanticTokens/full | `vls_feature_tests`, real stdio session |
|
||||||
| textDocument/inlayHint (parameter types) | `vls_feature_tests`, real stdio session |
|
| textDocument/inlayHint (parameter types) | `vls_feature_tests`, real stdio session |
|
||||||
|
| textDocument/codeLens + workspace/executeCommand (`vls.showReferences`) | `vls_feature_tests`, real stdio session |
|
||||||
| workspace/symbol | stock occurrence corpus |
|
| workspace/symbol | stock occurrence corpus |
|
||||||
| workspace fileOperations (didCreate/didRename/didDelete) | `vls_feature_tests`, real stdio session |
|
| workspace fileOperations (didCreate/didRename/didDelete) | `vls_feature_tests`, real stdio session |
|
||||||
| workspace/willRenameFiles (include updates) | `vls_feature_tests`, real stdio session |
|
| workspace/willRenameFiles (include updates) | `vls_feature_tests`, real stdio session |
|
||||||
@@ -35,7 +36,6 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
|||||||
| Overload-set signature help | only the selected occurrence's signature is available |
|
| Overload-set signature help | only the selected occurrence's signature is available |
|
||||||
| textDocument/formatting | needs a plan |
|
| textDocument/formatting | needs a plan |
|
||||||
| callHierarchy / typeHierarchy | prepare, incomingCalls and outgoingCalls are implemented and served; outgoing calls are verified over stdio now that the observer reports full function extents. Type hierarchy is open. |
|
| callHierarchy / typeHierarchy | prepare, incomingCalls and outgoingCalls are implemented and served; outgoing calls are verified over stdio now that the observer reports full function extents. Type hierarchy is open. |
|
||||||
| textDocument/codeLens, executeCommand | command surface not designed |
|
|
||||||
| Client-side application of server-issued workspace edits | rename and code actions return edits the clients apply directly |
|
| Client-side application of server-issued workspace edits | rename and code actions return edits the clients apply directly |
|
||||||
| Applying multi-file renames through client buffers | plans can be ready; application is client work |
|
| 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 |
|
| `EditorDiagnostics` reflection LSP wiring | the server has no reflection data source |
|
||||||
|
|||||||
@@ -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. 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. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences with a bounded one-type legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. 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. Selection and folding ranges are served from immutable document snapshots with registered bounded cores. Code actions now offer the compiler's own suggested fixes (quickfix) from retained published diagnostics, with SARIF fix decoding bound to the owner snapshot. Semantic tokens encode the proven call occurrences with a bounded one-type legend. Inlay hints project parameter types from the occurrence signature at each argument start. Workspace file-operation notifications invalidate dependent index contexts and re-queue open documents. A will-rename request returns the include updates for open documents. Code lenses show index reference counts and the `vls.showReferences` command resolves them to navigation locations. Call hierarchy serves prepare and incoming calls (grouped by enclosing definition or explicitly by file) from the stock call facts. Outgoing calls are served and verified: the stock observer now reports full function extents, so nested calls are attributed to the enclosing definition. 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
|
||||||
|
|||||||
@@ -79,6 +79,25 @@ 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 code lenses and the reference command
|
||||||
|
|
||||||
|
`include/vls/features/CodeLens.hpp` builds one bounded lens per unique
|
||||||
|
document position, titled with the proven reference count and carrying
|
||||||
|
{path, line, character} arguments. `EditorDiagnostics::code_lenses` counts
|
||||||
|
records by (name, definition location) from the current index generation and
|
||||||
|
serves `textDocument/codeLens`; `workspace/executeCommand` implements
|
||||||
|
`vls.showReferences`, resolving the arguments through the navigation binding
|
||||||
|
and returning the reference locations. Both are advertised and bounded.
|
||||||
|
|
||||||
|
Real stdio session with the stock observer:
|
||||||
|
```
|
||||||
|
codeLens: [({'character': 33, 'line': 18}, '1 reference')]
|
||||||
|
executeCommand: [{"range": {"end": {"character": 40, "line": 18}, "start": {"character": 33, "line": 18}},
|
||||||
|
"uri": "file:///.../DocumentSnapshot.cpp"}]
|
||||||
|
unknown command error: -32602
|
||||||
|
```
|
||||||
|
All 18 native suites and all 18 CMake tests passed.
|
||||||
|
|
||||||
## December 5 full function extents from the stock observer
|
## December 5 full function extents from the stock observer
|
||||||
|
|
||||||
The stock occurrence observer now reports an optional `extent` inside each
|
The stock occurrence observer now reports an optional `extent` inside each
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <compare>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <span>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace vls::features::code_lens {
|
||||||
|
|
||||||
|
struct Position {
|
||||||
|
std::uint32_t line{}, character{};
|
||||||
|
auto operator<=>(const Position &) const = default;
|
||||||
|
};
|
||||||
|
struct Range {
|
||||||
|
Position start, end;
|
||||||
|
auto operator<=>(const Range &) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
// One outline symbol with its proven reference count.
|
||||||
|
struct Entry {
|
||||||
|
std::string name;
|
||||||
|
std::string path;
|
||||||
|
Range range;
|
||||||
|
std::size_t references{};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Lens {
|
||||||
|
Range range;
|
||||||
|
std::string title;
|
||||||
|
std::vector<std::string> arguments;
|
||||||
|
auto operator<=>(const Lens &) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Limits {
|
||||||
|
std::size_t lenses{512};
|
||||||
|
std::size_t nameBytes{256};
|
||||||
|
std::size_t titleBytes{128};
|
||||||
|
};
|
||||||
|
|
||||||
|
// One lens per unique (path, range), titled with the reference count and
|
||||||
|
// carrying {path, line, character} arguments so a client can resolve it through
|
||||||
|
// workspace/executeCommand. Entries are ordered by position and bounded.
|
||||||
|
[[nodiscard]] std::vector<Lens> build(std::span<const Entry>, const Limits & = Limits{});
|
||||||
|
|
||||||
|
} // namespace vls::features::code_lens
|
||||||
@@ -60,6 +60,8 @@ class EditorDiagnostics {
|
|||||||
selection_ranges(std::string_view uri, std::span<const Documents::Position>) const;
|
selection_ranges(std::string_view uri, std::span<const Documents::Position>) const;
|
||||||
// Foldable brace blocks, comments, regions and include groups.
|
// Foldable brace blocks, comments, regions and include groups.
|
||||||
[[nodiscard]] Void::LanguageServer::Protocol::Json folding_ranges(std::string_view uri) const;
|
[[nodiscard]] Void::LanguageServer::Protocol::Json folding_ranges(std::string_view uri) const;
|
||||||
|
// Reference-count lenses for the records the index holds for one document.
|
||||||
|
[[nodiscard]] Void::LanguageServer::Protocol::Json code_lenses(std::string_view uri) const;
|
||||||
// Quick fixes suggested by the compiler for diagnostics overlapping the
|
// Quick fixes suggested by the compiler for diagnostics overlapping the
|
||||||
// requested range. Only fixes proven in the owner snapshot are offered.
|
// requested range. Only fixes proven in the owner snapshot are offered.
|
||||||
[[nodiscard]] Void::LanguageServer::Protocol::Json code_actions(std::string_view uri,
|
[[nodiscard]] Void::LanguageServer::Protocol::Json code_actions(std::string_view uri,
|
||||||
|
|||||||
@@ -312,6 +312,14 @@ DispatchResult Server::handle(std::string_view body) {
|
|||||||
}
|
}
|
||||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||||
capabilities.emplace("callHierarchyProvider", Json{true});
|
capabilities.emplace("callHierarchyProvider", Json{true});
|
||||||
|
if (diagnostics_ && diagnostics_->supports_occurrences()) {
|
||||||
|
capabilities.emplace("codeLensProvider",
|
||||||
|
Json{Json::Object{{"resolveProvider", Json{false}}}});
|
||||||
|
capabilities.emplace(
|
||||||
|
"executeCommandProvider",
|
||||||
|
Json{Json::Object{
|
||||||
|
{"commands", Json{Json::Array{Json{std::string{"vls.showReferences"}}}}}}});
|
||||||
|
}
|
||||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||||
capabilities.emplace("inlayHintProvider", Json{true});
|
capabilities.emplace("inlayHintProvider", Json{true});
|
||||||
if (diagnostics_ && diagnostics_->supports_occurrences())
|
if (diagnostics_ && diagnostics_->supports_occurrences())
|
||||||
@@ -434,6 +442,40 @@ DispatchResult Server::handle(std::string_view body) {
|
|||||||
}
|
}
|
||||||
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
|
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
|
||||||
}
|
}
|
||||||
|
if (*method == "textDocument/codeLens") {
|
||||||
|
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||||
|
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_->code_lenses(*uri));
|
||||||
|
}
|
||||||
|
if (*method == "workspace/executeCommand") {
|
||||||
|
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||||
|
return error(id, -32601, "Method not found");
|
||||||
|
const auto *command = as_string(member(params, "command"));
|
||||||
|
const auto *arguments = as_array(member(params, "arguments"));
|
||||||
|
if (!command || !arguments || arguments->size() != 2)
|
||||||
|
return error(id, -32602, "Expected a command and two arguments");
|
||||||
|
if (*command != "vls.showReferences")
|
||||||
|
return error(id, -32601, "Unregistered command");
|
||||||
|
const auto *uri = as_string(&(*arguments)[0]);
|
||||||
|
const auto *position = as_object(&(*arguments)[1]);
|
||||||
|
const auto line = position ? find_member(*position, "line") : nullptr;
|
||||||
|
const auto character = position ? find_member(*position, "character") : nullptr;
|
||||||
|
const auto *line_value = line ? std::get_if<std::int64_t>(&line->value) : nullptr;
|
||||||
|
const auto *character_value =
|
||||||
|
character ? std::get_if<std::int64_t>(&character->value) : nullptr;
|
||||||
|
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri) || !line_value ||
|
||||||
|
!character_value || *line_value < 0 || *character_value < 0 ||
|
||||||
|
*line_value > Void::LanguageServer::Documents::kMaxPositionValue ||
|
||||||
|
*character_value > Void::LanguageServer::Documents::kMaxPositionValue)
|
||||||
|
return error(id, -32602, "Expected textDocument.uri and a bounded position");
|
||||||
|
auto navigation =
|
||||||
|
diagnostics_->references(*uri, {static_cast<std::uint32_t>(*line_value),
|
||||||
|
static_cast<std::uint32_t>(*character_value)});
|
||||||
|
return reply(id, "result", std::move(navigation.result));
|
||||||
|
}
|
||||||
if (*method == "textDocument/prepareCallHierarchy") {
|
if (*method == "textDocument/prepareCallHierarchy") {
|
||||||
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
if (!diagnostics_ || !diagnostics_->supports_occurrences())
|
||||||
return error(id, -32601, "Method not found");
|
return error(id, -32601, "Method not found");
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include <vls/features/CodeLens.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
#include <tuple>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace vls::features::code_lens {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::string title(std::size_t references) {
|
||||||
|
return std::to_string(references) + (references == 1 ? " reference" : " references");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::vector<Lens> build(std::span<const Entry> entries, const Limits &limits) {
|
||||||
|
std::vector<Lens> result;
|
||||||
|
std::set<std::tuple<std::string, Range>> seen;
|
||||||
|
for (const auto &entry : entries) {
|
||||||
|
if (entry.path.empty() || entry.name.empty() || entry.name.size() > limits.nameBytes ||
|
||||||
|
entry.range.end < entry.range.start)
|
||||||
|
continue;
|
||||||
|
if (!seen.emplace(entry.path, entry.range).second)
|
||||||
|
continue;
|
||||||
|
auto text = title(entry.references);
|
||||||
|
if (text.size() > limits.titleBytes)
|
||||||
|
text.resize(limits.titleBytes);
|
||||||
|
result.push_back({entry.range,
|
||||||
|
std::move(text),
|
||||||
|
{entry.path, std::to_string(entry.range.start.line),
|
||||||
|
std::to_string(entry.range.start.character)}});
|
||||||
|
}
|
||||||
|
std::ranges::sort(result, [](const Lens &left, const Lens &right) {
|
||||||
|
return std::tie(left.range.start, left.range.end) <
|
||||||
|
std::tie(right.range.start, right.range.end);
|
||||||
|
});
|
||||||
|
if (result.size() > limits.lenses)
|
||||||
|
result.resize(limits.lenses);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace vls::features::code_lens
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <vls/features/CallHierarchy.hpp>
|
#include <vls/features/CallHierarchy.hpp>
|
||||||
#include <vls/features/CodeActions.hpp>
|
#include <vls/features/CodeActions.hpp>
|
||||||
|
#include <vls/features/CodeLens.hpp>
|
||||||
#include <vls/features/Completion.hpp>
|
#include <vls/features/Completion.hpp>
|
||||||
#include <vls/features/DocumentSymbols.hpp>
|
#include <vls/features/DocumentSymbols.hpp>
|
||||||
#include <vls/features/IndexNavigation.hpp>
|
#include <vls/features/IndexNavigation.hpp>
|
||||||
@@ -1038,6 +1039,57 @@ Json EditorDiagnostics::completion_resolve(const Json &item) const {
|
|||||||
return Json{std::move(enriched)};
|
return Json{std::move(enriched)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json EditorDiagnostics::code_lenses(std::string_view uri) const {
|
||||||
|
auto &s = *state_;
|
||||||
|
const auto identity = Documents::normalize_uri(uri);
|
||||||
|
if (!identity || !identity->is_file_uri)
|
||||||
|
return Json{nullptr};
|
||||||
|
const auto path = identity->canonical_path.native();
|
||||||
|
index::Result records;
|
||||||
|
std::map<std::tuple<std::string, std::string, std::uint32_t, std::uint32_t>, std::size_t>
|
||||||
|
counts;
|
||||||
|
{
|
||||||
|
std::lock_guard lock{s.mutex};
|
||||||
|
records = s.symbols.find_by_path(path);
|
||||||
|
if (const auto generation = s.symbols.current())
|
||||||
|
for (const auto &record : generation->symbols()) {
|
||||||
|
const auto &where = record.definition ? *record.definition : record.location;
|
||||||
|
++counts[{record.name, where.path, where.line, where.character}];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<features::code_lens::Entry> entries;
|
||||||
|
for (const auto &record : records.symbols) {
|
||||||
|
const auto &where = record.definition ? *record.definition : record.location;
|
||||||
|
const auto found = counts.find({record.name, where.path, where.line, where.character});
|
||||||
|
entries.push_back({{record.name},
|
||||||
|
record.location.path,
|
||||||
|
{{record.location.line, record.location.character},
|
||||||
|
{record.location.endLine, record.location.endCharacter}},
|
||||||
|
found == counts.end() ? 0 : found->second});
|
||||||
|
}
|
||||||
|
const auto lenses = features::code_lens::build(entries);
|
||||||
|
Json::Array result;
|
||||||
|
for (const auto &lens : lenses) {
|
||||||
|
const auto &arguments = lens.arguments;
|
||||||
|
if (arguments.size() != 3)
|
||||||
|
continue;
|
||||||
|
result.push_back(Json{Json::Object{
|
||||||
|
{"range",
|
||||||
|
range_json(Documents::Range{{lens.range.start.line, lens.range.start.character},
|
||||||
|
{lens.range.end.line, lens.range.end.character}})},
|
||||||
|
{"command",
|
||||||
|
Json{Json::Object{
|
||||||
|
{"title", Json{lens.title}},
|
||||||
|
{"command", Json{std::string{"vls.showReferences"}}},
|
||||||
|
{"arguments",
|
||||||
|
Json{Json::Array{
|
||||||
|
Json{Documents::path_to_file_uri(arguments[0])},
|
||||||
|
Json{Json::Object{{"line", Json{std::stoll(arguments[1])}},
|
||||||
|
{"character", Json{std::stoll(arguments[2])}}}}}}}}}}}});
|
||||||
|
}
|
||||||
|
return Json{std::move(result)};
|
||||||
|
}
|
||||||
|
|
||||||
Json EditorDiagnostics::document_symbols(std::string_view uri) const {
|
Json EditorDiagnostics::document_symbols(std::string_view uri) const {
|
||||||
auto &s = *state_;
|
auto &s = *state_;
|
||||||
const auto identity = Documents::normalize_uri(uri);
|
const auto identity = Documents::normalize_uri(uri);
|
||||||
|
|||||||
@@ -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 features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp)
|
vls_test_suite(vls_feature_tests features/CompletionTests.cpp features/IndexNavigationTests.cpp features/SignatureHelpTests.cpp features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.cpp features/InlayHintsTests.cpp features/FileOperationsTests.cpp features/IncludeUpdateTests.cpp features/CallHierarchyTests.cpp features/CodeLensTests.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)
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
#include <vls/features/CodeLens.hpp>
|
||||||
|
|
||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using namespace vls::features::code_lens;
|
||||||
|
using Void::Testing::expect;
|
||||||
|
using Void::Testing::require;
|
||||||
|
|
||||||
|
Range range(std::uint32_t line) { return {{line, 0}, {line, 4}}; }
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
VOID_TEST(CodeLens, titles_singular_and_plural_counts) {
|
||||||
|
const std::vector<Entry> entries{{"a", "/p/a.cpp", range(1), 1},
|
||||||
|
{"b", "/p/a.cpp", range(2), 0},
|
||||||
|
{"c", "/p/a.cpp", range(3), 3}};
|
||||||
|
const auto lenses = build(entries);
|
||||||
|
require(lenses.size() == 3);
|
||||||
|
expect(lenses[0].title == "1 reference");
|
||||||
|
expect(lenses[1].title == "0 references");
|
||||||
|
expect(lenses[2].title == "3 references");
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CodeLens, arguments_carry_the_path_and_start) {
|
||||||
|
const std::vector<Entry> entries{{"a", "/p/a.cpp", {{4, 2}, {4, 9}}, 2}};
|
||||||
|
const auto lenses = build(entries);
|
||||||
|
require(lenses.size() == 1);
|
||||||
|
require(lenses.front().arguments.size() == 3);
|
||||||
|
expect(lenses.front().arguments[0] == "/p/a.cpp");
|
||||||
|
expect(lenses.front().arguments[1] == "4");
|
||||||
|
expect(lenses.front().arguments[2] == "2");
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CodeLens, deduplicates_by_path_and_range) {
|
||||||
|
const std::vector<Entry> entries{{"a", "/p/a.cpp", range(1), 1},
|
||||||
|
{"a", "/p/a.cpp", range(1), 5},
|
||||||
|
{"a", "/p/b.cpp", range(1), 2}};
|
||||||
|
const auto lenses = build(entries);
|
||||||
|
require(lenses.size() == 2);
|
||||||
|
expect(lenses[0].title == "1 reference");
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CodeLens, is_sorted_and_bounded) {
|
||||||
|
const std::vector<Entry> entries{{"c", "/p/a.cpp", range(9), 1},
|
||||||
|
{"a", "/p/a.cpp", range(1), 1},
|
||||||
|
{"b", "/p/a.cpp", range(5), 1}};
|
||||||
|
const auto lenses = build(entries, Limits{.lenses = 2});
|
||||||
|
require(lenses.size() == 2);
|
||||||
|
expect(lenses[0].range.start.line == 1);
|
||||||
|
expect(lenses[1].range.start.line == 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CodeLens, rejects_malformed_and_bounds_fields) {
|
||||||
|
const std::vector<Entry> entries{{"", "/p/a.cpp", range(1), 1},
|
||||||
|
{"a", "", range(2), 1},
|
||||||
|
{"b", "/p/a.cpp", {{3, 4}, {3, 1}}, 1},
|
||||||
|
{"c", "/p/a.cpp", range(4), 1}};
|
||||||
|
const auto lenses = build(entries);
|
||||||
|
require(lenses.size() == 1);
|
||||||
|
expect(lenses.front().title == "1 reference");
|
||||||
|
const auto bounded = build(entries, Limits{.titleBytes = 4});
|
||||||
|
require(!bounded.empty());
|
||||||
|
expect(bounded.front().title == "1 re");
|
||||||
|
}
|
||||||
Reference in new issue
Block a user