Consume a compiler-agnostic completion index
Under D-032, completion can now merge candidates from a documented, versioned index file produced by any external tool. The bounded core parses and selects the innermost covering scope, the server puts its items ahead of index-backed ones and takes isIncomplete from the scope's complete flag, and registered feature tests cover parsing, selection and bounds. A real stdio session returned the provided items first with isIncomplete false inside the scope and true outside.
This commit is contained in:
1 parent
236c3c5718
commit
4a029152e9
13 files changed
+336
-11
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/features/CodeLens.cpp src/features/DocumentLinks.cpp src/features/Formatting.cpp src/features/TypeHierarchy.cpp src/features/Outline.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/features/DocumentLinks.cpp src/features/Formatting.cpp src/features/TypeHierarchy.cpp src/features/Outline.cpp src/features/CompletionSource.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)
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ void build(Void::Build::Project &project) {
|
|||||||
"src/features/Formatting.cpp",
|
"src/features/Formatting.cpp",
|
||||||
"src/features/TypeHierarchy.cpp",
|
"src/features/TypeHierarchy.cpp",
|
||||||
"src/features/Outline.cpp",
|
"src/features/Outline.cpp",
|
||||||
|
"src/features/CompletionSource.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",
|
||||||
@@ -166,7 +167,8 @@ void build(Void::Build::Project &project) {
|
|||||||
"tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp",
|
"tests/features/FileOperationsTests.cpp", "tests/features/IncludeUpdateTests.cpp",
|
||||||
"tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.cpp",
|
"tests/features/CallHierarchyTests.cpp", "tests/features/CodeLensTests.cpp",
|
||||||
"tests/features/DocumentLinksTests.cpp", "tests/features/FormattingTests.cpp",
|
"tests/features/DocumentLinksTests.cpp", "tests/features/FormattingTests.cpp",
|
||||||
"tests/features/TypeHierarchyTests.cpp", "tests/features/OutlineTests.cpp"});
|
"tests/features/TypeHierarchyTests.cpp", "tests/features/OutlineTests.cpp",
|
||||||
|
"tests/features/CompletionSourceTests.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"})
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
|||||||
|
|
||||||
| Capability | Notes |
|
| Capability | Notes |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| Compiler-native completion with visibility proof | not pursued through a custom compiler (D-032); generic completion remains index-backed and incomplete |
|
| Compiler-native completion with visibility proof | provided through the compiler-agnostic `--completion-index` interface (D-032); visibility proof is the producer's claim. The built-in index-backed completion remains incomplete without it. |
|
||||||
| Overload-set signature help | observed overloads are listed with the compiler-selected one first; visibility and overload resolution are not proven |
|
| Overload-set signature help | observed overloads are listed with the compiler-selected one first; visibility and overload resolution are not proven |
|
||||||
| 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. |
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ suite covers stepping, inspection per generation, continue, cancel, refusal
|
|||||||
without a stop, malformed output and the deadline, and a real DAP transcript
|
without a stop, malformed output and the deadline, and a real DAP transcript
|
||||||
test drives the adapter end to end.
|
test drives the adapter end to end.
|
||||||
|
|
||||||
Completion is now served: `textDocument/completion` is advertised and answered from the symbol index through `EditorDiagnostics::completion`, with a bounded ranking core in `include/vls/features/` and registered `vls_feature_tests`. Results are explicitly incomplete because the index does not prove visibility; compiler-native completion, deferred detail resolution and signature help remain open.
|
A compiler-agnostic completion index (`--completion-index`) can supply proven candidates merged ahead of index-backed ones. Completion is now served: `textDocument/completion` is advertised and answered from the symbol index through `EditorDiagnostics::completion`, with a bounded ranking core in `include/vls/features/` and registered `vls_feature_tests`. Results are explicitly incomplete because the index does not prove visibility; compiler-native completion, deferred detail resolution and signature help remain open.
|
||||||
|
|
||||||
Index-backed rename coverage is now merged into the navigation fact set (`vls/features/IndexNavigation.hpp`): persisted index contexts and records join the set with the index's completeness, existing compiler-derived facts win, and records without a known current content identity stay non-editable so rename refuses them. Multi-file rename can therefore be ready from real index data when a transactional client is present, proven by registered `vls_feature_tests` cases.
|
Index-backed rename coverage is now merged into the navigation fact set (`vls/features/IndexNavigation.hpp`): persisted index contexts and records join the set with the index's completeness, existing compiler-derived facts win, and records without a known current content identity stay non-editable so rename refuses them. Multi-file rename can therefore be ready from real index data when a transactional client is present, proven by registered `vls_feature_tests` cases.
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,25 @@ start coordinate only, so ranges are zero-width until an end is available.
|
|||||||
LSP adapters and index/rename/debugging integration remain open. `vbs test`
|
LSP adapters and index/rename/debugging integration remain open. `vbs test`
|
||||||
passed all 17 native suites; CMake passed the reflection and trace suites.
|
passed all 17 native suites; CMake passed the reflection and trace suites.
|
||||||
|
|
||||||
|
## December 6 compiler-agnostic completion source
|
||||||
|
|
||||||
|
Per D-032, completion can now consume a documented, compiler-agnostic index
|
||||||
|
(`--completion-index PATH`) produced by any external tool:
|
||||||
|
`{"schema":1,"scopes":[{"path","startLine","startCharacter","endLine",
|
||||||
|
"endCharacter","complete","items":[{"label","kind?","detail?","insertText?"}]}]}`
|
||||||
|
with the producer's visibility claim carried through unchanged. The bounded
|
||||||
|
core (`vls/features/CompletionSource.hpp`) parses and selects the innermost
|
||||||
|
covering scope; the server merges its candidates ahead of index-backed ones and
|
||||||
|
sets `isIncomplete` from the scope's `complete` flag. Registered
|
||||||
|
`vls_feature_tests` grew to 115 cases.
|
||||||
|
|
||||||
|
Real stdio session:
|
||||||
|
```
|
||||||
|
inside scope: isIncomplete = False items = ['alpha', 'beta', 'main']
|
||||||
|
outside scope: isIncomplete = True
|
||||||
|
```
|
||||||
|
All 18 native suites and all 18 CMake tests passed.
|
||||||
|
|
||||||
## December 6 locality ranking in completion
|
## December 6 locality ranking in completion
|
||||||
|
|
||||||
Completion candidates now carry whether they are declared in the requesting
|
Completion candidates now carry whether they are declared in the requesting
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
#include <Void/LanguageServer/Documents/DocumentStore.hpp>
|
||||||
#include <vls/Framing.hpp>
|
#include <vls/Framing.hpp>
|
||||||
#include <vls/WorkspaceSession.hpp>
|
#include <vls/WorkspaceSession.hpp>
|
||||||
|
#include <vls/features/CompletionSource.hpp>
|
||||||
#include <vls/reflection/Provenance.hpp>
|
#include <vls/reflection/Provenance.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -37,6 +38,7 @@ class Server {
|
|||||||
WorkspaceSession workspace_;
|
WorkspaceSession workspace_;
|
||||||
std::unique_ptr<semantic::EditorDiagnostics> diagnostics_;
|
std::unique_ptr<semantic::EditorDiagnostics> diagnostics_;
|
||||||
std::shared_ptr<const reflection::Snapshot> reflection_;
|
std::shared_ptr<const reflection::Snapshot> reflection_;
|
||||||
|
std::vector<features::completion_source::Scope> completion_scopes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Thin transport loop shared by the executable and stream-failure unit tests.
|
// Thin transport loop shared by the executable and stream-failure unit tests.
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ struct WorkspaceLaunch {
|
|||||||
std::shared_ptr<const semantic::GccProfile> diagnostics_profile{};
|
std::shared_ptr<const semantic::GccProfile> diagnostics_profile{};
|
||||||
// Versioned reflection provenance snapshot served as read-only hover.
|
// Versioned reflection provenance snapshot served as read-only hover.
|
||||||
std::optional<std::filesystem::path> reflection_snapshot;
|
std::optional<std::filesystem::path> reflection_snapshot;
|
||||||
|
// A compiler-agnostic completion index produced outside VLS.
|
||||||
|
std::optional<std::filesystem::path> completion_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SemanticDriver {
|
struct SemanticDriver {
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <compare>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <expected>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace vls::features::completion_source {
|
||||||
|
|
||||||
|
// Positions are LSP positions in the document's negotiated encoding, so any
|
||||||
|
// producer can write them without knowing VLS internals.
|
||||||
|
struct Position {
|
||||||
|
std::uint32_t line{}, character{};
|
||||||
|
auto operator<=>(const Position &) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Provided {
|
||||||
|
std::string label;
|
||||||
|
std::int64_t kind{1};
|
||||||
|
std::string detail;
|
||||||
|
std::string insert_text;
|
||||||
|
auto operator<=>(const Provided &) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
// One compiler-produced completion point: a position range with the
|
||||||
|
// candidates visible there. COMPLETE means the producer proved the list is
|
||||||
|
// exhaustive for the range (visibility proof is the producer's claim, carried
|
||||||
|
// through unchanged).
|
||||||
|
struct Scope {
|
||||||
|
std::string path;
|
||||||
|
Position start, end;
|
||||||
|
bool complete{};
|
||||||
|
std::vector<Provided> items;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Limits {
|
||||||
|
std::size_t scopes{1024};
|
||||||
|
std::size_t items{4096};
|
||||||
|
std::size_t itemsPerScope{256};
|
||||||
|
std::size_t pathBytes{4096};
|
||||||
|
std::size_t textBytes{1024};
|
||||||
|
std::size_t fileBytes{8 * 1024 * 1024};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parses the versioned completion index:
|
||||||
|
// {"schema":1,"scopes":[{"path":...,"startLine":..,"startCharacter":..,
|
||||||
|
// "endLine":..,"endCharacter":..,"complete":bool,
|
||||||
|
// "items":[{"label":..,"kind":int?,"detail":?,"insertText":?}]}]}
|
||||||
|
[[nodiscard]] std::expected<std::vector<Scope>, std::string> parse(std::string_view bytes,
|
||||||
|
const Limits & = Limits{});
|
||||||
|
|
||||||
|
// The innermost scope covering the position, or null.
|
||||||
|
[[nodiscard]] const Scope *at(const std::vector<Scope> &, std::string_view path, Position);
|
||||||
|
|
||||||
|
} // namespace vls::features::completion_source
|
||||||
+36
-4
@@ -136,6 +136,15 @@ DispatchResult error(const Json &id, std::int64_t code, std::string_view message
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Server::Server(WorkspaceLaunch launch, std::function<bool(std::string)> send) : workspace_(launch) {
|
Server::Server(WorkspaceLaunch launch, std::function<bool(std::string)> send) : workspace_(launch) {
|
||||||
|
if (launch.completion_index) {
|
||||||
|
std::ifstream stream{*launch.completion_index, std::ios::binary};
|
||||||
|
std::string bytes{std::istreambuf_iterator<char>{stream}, {}};
|
||||||
|
if (!bytes.empty()) {
|
||||||
|
auto parsed = features::completion_source::parse(bytes);
|
||||||
|
if (parsed)
|
||||||
|
completion_scopes_ = std::move(*parsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (launch.reflection_snapshot) {
|
if (launch.reflection_snapshot) {
|
||||||
std::ifstream stream{*launch.reflection_snapshot, std::ios::binary};
|
std::ifstream stream{*launch.reflection_snapshot, std::ios::binary};
|
||||||
std::string bytes{std::istreambuf_iterator<char>{stream}, {}};
|
std::string bytes{std::istreambuf_iterator<char>{stream}, {}};
|
||||||
@@ -733,10 +742,33 @@ DispatchResult Server::handle(std::string_view body) {
|
|||||||
*line_value > Void::LanguageServer::Documents::kMaxPositionValue ||
|
*line_value > Void::LanguageServer::Documents::kMaxPositionValue ||
|
||||||
*character_value > Void::LanguageServer::Documents::kMaxPositionValue)
|
*character_value > Void::LanguageServer::Documents::kMaxPositionValue)
|
||||||
return error(id, -32602, "Expected textDocument.uri and a bounded position");
|
return error(id, -32602, "Expected textDocument.uri and a bounded position");
|
||||||
return reply(
|
const Void::LanguageServer::Documents::Position selected{
|
||||||
id, "result",
|
static_cast<std::uint32_t>(*line_value), static_cast<std::uint32_t>(*character_value)};
|
||||||
diagnostics_->completion(*uri, {static_cast<std::uint32_t>(*line_value),
|
auto result = diagnostics_->completion(*uri, selected);
|
||||||
static_cast<std::uint32_t>(*character_value)}));
|
const auto identity = Void::LanguageServer::Documents::normalize_uri(*uri);
|
||||||
|
if (!completion_scopes_.empty() && identity && identity->is_file_uri) {
|
||||||
|
if (const auto *scope = features::completion_source::at(
|
||||||
|
completion_scopes_, identity->canonical_path.native(),
|
||||||
|
{selected.line, selected.character})) {
|
||||||
|
auto &fields = std::get<Json::Object>(result.value);
|
||||||
|
Json::Array merged;
|
||||||
|
for (const auto &provided : scope->items) {
|
||||||
|
Json::Object item{{"label", Json{provided.label}},
|
||||||
|
{"kind", Json{provided.kind}}};
|
||||||
|
if (!provided.detail.empty())
|
||||||
|
item.emplace("detail", Json{provided.detail});
|
||||||
|
if (!provided.insert_text.empty())
|
||||||
|
item.emplace("insertText", Json{provided.insert_text});
|
||||||
|
merged.push_back(Json{std::move(item)});
|
||||||
|
}
|
||||||
|
if (const auto *existing = as_array(find_member(fields, "items")))
|
||||||
|
for (const auto &entry : *existing)
|
||||||
|
merged.push_back(entry);
|
||||||
|
fields.insert_or_assign("items", Json{std::move(merged)});
|
||||||
|
fields.insert_or_assign("isIncomplete", Json{!scope->complete});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reply(id, "result", std::move(result));
|
||||||
}
|
}
|
||||||
if (*method == "textDocument/references" || *method == "textDocument/prepareRename" ||
|
if (*method == "textDocument/references" || *method == "textDocument/prepareRename" ||
|
||||||
*method == "textDocument/rename") {
|
*method == "textDocument/rename") {
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
#include <vls/features/CompletionSource.hpp>
|
||||||
|
|
||||||
|
#include <Void/LanguageServer/Protocol/Json.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace vls::features::completion_source {
|
||||||
|
namespace P = Void::LanguageServer::Protocol;
|
||||||
|
using Json = P::Json;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::optional<std::uint32_t> coordinate(const Json *value) {
|
||||||
|
if (!value)
|
||||||
|
return std::nullopt;
|
||||||
|
const auto *number = std::get_if<std::int64_t>(&value->value);
|
||||||
|
if (!number || *number < 0)
|
||||||
|
return std::nullopt;
|
||||||
|
return static_cast<std::uint32_t>(*number);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> text(const Json *value, std::size_t limit) {
|
||||||
|
const auto *string = value ? P::as_string(value) : nullptr;
|
||||||
|
if (!string || string->empty() || string->size() > limit ||
|
||||||
|
string->find('\0') != std::string::npos)
|
||||||
|
return std::nullopt;
|
||||||
|
return *string;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::expected<std::vector<Scope>, std::string> parse(std::string_view bytes, const Limits &limits) {
|
||||||
|
if (bytes.size() > limits.fileBytes)
|
||||||
|
return std::unexpected("completion index exceeds its byte bound");
|
||||||
|
auto parsed = P::parse_json(bytes, 16);
|
||||||
|
if (!parsed)
|
||||||
|
return std::unexpected("completion index is not valid JSON");
|
||||||
|
const auto *root = P::as_object(&*parsed);
|
||||||
|
if (!root || root->size() != 2)
|
||||||
|
return std::unexpected("completion index is not an object");
|
||||||
|
const auto schema = P::as_int64(P::find_member(*root, "schema"));
|
||||||
|
const auto *scopes = P::as_array(P::find_member(*root, "scopes"));
|
||||||
|
if (!schema || *schema != 1 || !scopes || scopes->size() > limits.scopes)
|
||||||
|
return std::unexpected("unsupported completion index");
|
||||||
|
std::vector<Scope> result;
|
||||||
|
for (const auto &item : *scopes) {
|
||||||
|
const auto *fields = P::as_object(&item);
|
||||||
|
if (!fields)
|
||||||
|
return std::unexpected("completion scope is not an object");
|
||||||
|
const auto path = text(P::find_member(*fields, "path"), limits.pathBytes);
|
||||||
|
const auto start_line = coordinate(P::find_member(*fields, "startLine"));
|
||||||
|
const auto start_character = coordinate(P::find_member(*fields, "startCharacter"));
|
||||||
|
const auto end_line = coordinate(P::find_member(*fields, "endLine"));
|
||||||
|
const auto end_character = coordinate(P::find_member(*fields, "endCharacter"));
|
||||||
|
const auto complete = P::as_bool(P::find_member(*fields, "complete"));
|
||||||
|
const auto *items = P::as_array(P::find_member(*fields, "items"));
|
||||||
|
if (!path || !start_line || !start_character || !end_line || !end_character || !complete ||
|
||||||
|
!items || items->size() > limits.itemsPerScope)
|
||||||
|
return std::unexpected("completion scope is incomplete");
|
||||||
|
Scope scope{
|
||||||
|
*path, {*start_line, *start_character}, {*end_line, *end_character}, *complete, {}};
|
||||||
|
if (scope.end < scope.start)
|
||||||
|
return std::unexpected("completion scope range is reversed");
|
||||||
|
for (const auto &entry : *items) {
|
||||||
|
if (result.size() + scope.items.size() >= limits.items)
|
||||||
|
return std::unexpected("completion index exceeds its item bound");
|
||||||
|
const auto *candidate = P::as_object(&entry);
|
||||||
|
const auto label = candidate
|
||||||
|
? text(P::find_member(*candidate, "label"), limits.textBytes)
|
||||||
|
: std::nullopt;
|
||||||
|
if (!label)
|
||||||
|
return std::unexpected("completion item lacks a label");
|
||||||
|
Provided provided{*label, 1, {}, {}};
|
||||||
|
if (const auto *kind = P::find_member(*candidate, "kind")) {
|
||||||
|
const auto *number = std::get_if<std::int64_t>(&kind->value);
|
||||||
|
if (!number || *number < 1 || *number > 26)
|
||||||
|
return std::unexpected("completion item kind is invalid");
|
||||||
|
provided.kind = *number;
|
||||||
|
}
|
||||||
|
if (const auto *detail = P::find_member(*candidate, "detail")) {
|
||||||
|
auto value = text(detail, limits.textBytes);
|
||||||
|
if (!value)
|
||||||
|
return std::unexpected("completion item detail is invalid");
|
||||||
|
provided.detail = std::move(*value);
|
||||||
|
}
|
||||||
|
if (const auto *insert = P::find_member(*candidate, "insertText")) {
|
||||||
|
auto value = text(insert, limits.textBytes);
|
||||||
|
if (!value)
|
||||||
|
return std::unexpected("completion item insertText is invalid");
|
||||||
|
provided.insert_text = std::move(*value);
|
||||||
|
}
|
||||||
|
scope.items.push_back(std::move(provided));
|
||||||
|
}
|
||||||
|
result.push_back(std::move(scope));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::uint64_t span_size(const Scope &scope) {
|
||||||
|
return (static_cast<std::uint64_t>(scope.end.line) - scope.start.line) * 1'000'000 +
|
||||||
|
(static_cast<std::uint64_t>(scope.end.character) - scope.start.character);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
const Scope *at(const std::vector<Scope> &scopes, std::string_view path, Position position) {
|
||||||
|
const Scope *best{};
|
||||||
|
for (const auto &scope : scopes) {
|
||||||
|
if (scope.path != path || position < scope.start || scope.end < position)
|
||||||
|
continue;
|
||||||
|
if (!best || span_size(scope) < span_size(*best))
|
||||||
|
best = &scope;
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace vls::features::completion_source
|
||||||
+12
-2
@@ -15,7 +15,7 @@ namespace Workspace = Void::LanguageServer::Workspace;
|
|||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
std::optional<std::string> root, user_file, provider, database, selector, build_root,
|
std::optional<std::string> root, user_file, provider, database, selector, build_root,
|
||||||
producer_cwd, profile, gcc_profile, reflection_snapshot;
|
producer_cwd, profile, gcc_profile, reflection_snapshot, completion_index;
|
||||||
bool gcc_diagnostics{};
|
bool gcc_diagnostics{};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ std::expected<vls::WorkspaceLaunch, std::string> workspace_launch(const Options
|
|||||||
if (!options.root) {
|
if (!options.root) {
|
||||||
if (options.user_file || options.provider || options.database || options.selector ||
|
if (options.user_file || options.provider || options.database || options.selector ||
|
||||||
options.build_root || options.producer_cwd || options.profile || options.gcc_profile ||
|
options.build_root || options.producer_cwd || options.profile || options.gcc_profile ||
|
||||||
options.gcc_diagnostics || options.reflection_snapshot)
|
options.gcc_diagnostics || options.reflection_snapshot || options.completion_index)
|
||||||
return std::unexpected{"workspace options require --workspace-root"};
|
return std::unexpected{"workspace options require --workspace-root"};
|
||||||
return launch;
|
return launch;
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,13 @@ std::expected<vls::WorkspaceLaunch, std::string> workspace_launch(const Options
|
|||||||
return std::unexpected{!build ? build.error() : producer.error()};
|
return std::unexpected{!build ? build.error() : producer.error()};
|
||||||
launch.build_root = std::move(*build);
|
launch.build_root = std::move(*build);
|
||||||
launch.producer_cwd = std::move(*producer);
|
launch.producer_cwd = std::move(*producer);
|
||||||
|
if (options.completion_index) {
|
||||||
|
const fs::path selected{*options.completion_index};
|
||||||
|
std::error_code index_error;
|
||||||
|
if (!selected.is_absolute() || !fs::is_regular_file(selected, index_error))
|
||||||
|
return std::unexpected{"--completion-index requires an existing absolute file"};
|
||||||
|
launch.completion_index = selected;
|
||||||
|
}
|
||||||
if (options.reflection_snapshot) {
|
if (options.reflection_snapshot) {
|
||||||
const fs::path snapshot{*options.reflection_snapshot};
|
const fs::path snapshot{*options.reflection_snapshot};
|
||||||
std::error_code snapshot_error;
|
std::error_code snapshot_error;
|
||||||
@@ -131,6 +138,9 @@ int main(int argc, char **argv) {
|
|||||||
"--gcc-profile", "",
|
"--gcc-profile", "",
|
||||||
"enable stock GCC diagnostics for this workspace using an absolute prepared profile",
|
"enable stock GCC diagnostics for this workspace using an absolute prepared profile",
|
||||||
options.gcc_profile);
|
options.gcc_profile);
|
||||||
|
parser.option("--completion-index", "",
|
||||||
|
"compiler-agnostic completion index served ahead of index candidates",
|
||||||
|
options.completion_index);
|
||||||
parser.option("--reflection-snapshot", "",
|
parser.option("--reflection-snapshot", "",
|
||||||
"versioned reflection provenance snapshot served as read-only hover",
|
"versioned reflection provenance snapshot served as read-only hover",
|
||||||
options.reflection_snapshot);
|
options.reflection_snapshot);
|
||||||
|
|||||||
@@ -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 features/CodeLensTests.cpp features/DocumentLinksTests.cpp features/FormattingTests.cpp features/TypeHierarchyTests.cpp features/OutlineTests.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 features/DocumentLinksTests.cpp features/FormattingTests.cpp features/TypeHierarchyTests.cpp features/OutlineTests.cpp features/CompletionSourceTests.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,84 @@
|
|||||||
|
#include <vls/features/CompletionSource.hpp>
|
||||||
|
|
||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using namespace vls::features::completion_source;
|
||||||
|
using Void::Testing::expect;
|
||||||
|
using Void::Testing::require;
|
||||||
|
|
||||||
|
std::string index(std::string_view scopes) {
|
||||||
|
return R"({"schema":1,"scopes":[)" + std::string{scopes} + "]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string scope(std::string_view path, int start_line, int start_character, int end_line,
|
||||||
|
int end_character, bool complete, std::string_view items) {
|
||||||
|
return R"({"path":")" + std::string{path} + R"(","startLine":)" + std::to_string(start_line) +
|
||||||
|
R"(,"startCharacter":)" + std::to_string(start_character) + R"(,"endLine":)" +
|
||||||
|
std::to_string(end_line) + R"(,"endCharacter":)" + std::to_string(end_character) +
|
||||||
|
R"(,"complete":)" + (complete ? "true" : "false") + R"(,"items":[)" +
|
||||||
|
std::string{items} + "]}";
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
VOID_TEST(CompletionSource, parses_scopes_and_items) {
|
||||||
|
const auto bytes = index(scope(
|
||||||
|
"/p/a.cpp", 0, 0, 2, 0, true,
|
||||||
|
R"json({"label":"alpha","kind":12,"detail":"int alpha()","insertText":"alpha()"},{"label":"beta"})json"));
|
||||||
|
const auto parsed = parse(bytes);
|
||||||
|
require(parsed.has_value());
|
||||||
|
require(parsed->size() == 1);
|
||||||
|
const auto &first = parsed->front();
|
||||||
|
expect(first.path == "/p/a.cpp");
|
||||||
|
expect(first.complete);
|
||||||
|
expect(first.start == Position{0, 0});
|
||||||
|
expect(first.end == Position{2, 0});
|
||||||
|
require(first.items.size() == 2);
|
||||||
|
expect(first.items[0].label == "alpha");
|
||||||
|
expect(first.items[0].kind == 12);
|
||||||
|
expect(first.items[0].detail == "int alpha()");
|
||||||
|
expect(first.items[0].insert_text == "alpha()");
|
||||||
|
expect(first.items[1].kind == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CompletionSource, selects_the_innermost_covering_scope) {
|
||||||
|
const auto bytes = index(scope("/p/a.cpp", 0, 0, 10, 0, false, R"({"label":"outer"})") + "," +
|
||||||
|
scope("/p/a.cpp", 2, 0, 4, 0, true, R"({"label":"inner"})") + "," +
|
||||||
|
scope("/p/b.cpp", 0, 0, 10, 0, true, R"({"label":"other"})"));
|
||||||
|
const auto parsed = parse(bytes);
|
||||||
|
require(parsed.has_value());
|
||||||
|
const auto *selected = at(*parsed, "/p/a.cpp", {3, 5});
|
||||||
|
require(selected != nullptr);
|
||||||
|
expect(selected->items.front().label == "inner");
|
||||||
|
expect(selected->complete);
|
||||||
|
expect(at(*parsed, "/p/a.cpp", {20, 0}) == nullptr);
|
||||||
|
expect(at(*parsed, "/p/missing.cpp", {1, 0}) == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CompletionSource, rejects_malformed_and_incomplete_scopes) {
|
||||||
|
expect(!parse("not json").has_value());
|
||||||
|
expect(!parse(R"({"schema":2,"scopes":[]})").has_value());
|
||||||
|
expect(!parse(R"({"schema":1})").has_value());
|
||||||
|
expect(!parse(index(scope("/p/a.cpp", 1, 0, 0, 0, true, ""))).has_value());
|
||||||
|
expect(
|
||||||
|
!parse(
|
||||||
|
index(
|
||||||
|
R"({"path":"/p/a.cpp","startLine":0,"startCharacter":0,"endLine":1,"endCharacter":0,"complete":true,"items":[{"kind":4}]})"))
|
||||||
|
.has_value());
|
||||||
|
expect(
|
||||||
|
!parse(
|
||||||
|
index(
|
||||||
|
R"({"path":"/p/a.cpp","startLine":0,"startCharacter":0,"endLine":1,"endCharacter":0,"complete":true,"items":[{"label":"x","kind":99}]})"))
|
||||||
|
.has_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID_TEST(CompletionSource, is_bounded) {
|
||||||
|
const auto bytes = index(scope("/p/a.cpp", 0, 0, 1, 0, true, R"({"label":"a"},{"label":"b"})"));
|
||||||
|
expect(parse(bytes, Limits{.itemsPerScope = 1}).has_value() == false);
|
||||||
|
expect(parse(bytes, Limits{.scopes = 0}).has_value() == false);
|
||||||
|
expect(parse(bytes, Limits{.fileBytes = 8}).has_value() == false);
|
||||||
|
expect(parse(bytes, Limits{.textBytes = 0}).has_value() == false);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user