Serve parameter inlay hints from occurrence signatures

A bounded core finds top-level argument starts (nested brackets,
literals and comments aware) and projects parameter-type hints from the
compiler signature, filtered to the requested range. The server
advertises inlayHintProvider and serves textDocument/inlayHint through
EditorDiagnostics. Registered tests cover splitting, filtering, short
signatures and bounds; a real stdio session returned the
std::string_view hint for the fnv1a64 argument. Refresh the parity
matrix.
This commit is contained in:
faumaray committed 2026-12-05 15:40:19 +03:00
1 parent 12a71ff692
commit 130cb57a7f
12 files changed
+360 -10

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/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/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/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/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_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)
+2 -1
View File
@@ -73,6 +73,7 @@ void build(Void::Build::Project &project) {
"src/features/TextStructure.cpp",
"src/features/CodeActions.cpp",
"src/features/SemanticTokens.cpp",
"src/features/InlayHints.cpp",
"src/debug/live/LiveSession.cpp",
"src/modules/ModuleWorkQueue.cpp",
"src/modules/GccScan.cpp",
@@ -153,7 +154,7 @@ void build(Void::Build::Project &project) {
{"tests/features/CompletionTests.cpp", "tests/features/IndexNavigationTests.cpp",
"tests/features/SignatureHelpTests.cpp", "tests/features/DocumentSymbolsTests.cpp",
"tests/features/TextStructureTests.cpp", "tests/features/CodeActionsTests.cpp",
"tests/features/SemanticTokensTests.cpp"});
"tests/features/SemanticTokensTests.cpp", "tests/features/InlayHintsTests.cpp"});
auto live_worker = project.executable("vls_live_worker_fixture");
live_worker.cxx_standard(CxxStandard::Cxx26)
.sources({"tests/debug/LiveWorkerFixture.cpp"})
+8 -6
View File
@@ -2,7 +2,7 @@
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.
missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
## Implemented and verified
@@ -20,6 +20,7 @@ missing part.
| textDocument/selectionRange, foldingRange | `vls_feature_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/inlayHint (parameter types) | `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` |
@@ -31,15 +32,16 @@ missing part.
| 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/formatting | needs a plan |
| textDocument/inlayHint | open |
| textDocument/codeLens, executeCommand | command surface not designed |
| callHierarchy / typeHierarchy | needs compiler call/type relationships |
| textDocument/codeLens, executeCommand | command surface not designed |
| 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 |
| semantic token modifiers / richer token types | legend is one type (`function`) from occurrences |
| inlay hints beyond parameter types | return-type and deduced-type hints need more compiler data |
## Next slices
1. Formatting and inlay hints.
2. call/type hierarchy and code lens.
3. executeCommand and workspace edits/file operations.
1. `workspace/applyEdit` and client-side application of ready rename plans.
2. call hierarchy from stock call facts.
3. Formatting via the selected compiler.
+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
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. 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. Compiler-native completion with visibility proof and deferred detail resolution remain open.
The reflection provenance representation (roadmap 12 first slice) is
implemented as a bounded library with a registered suite: innermost-first
+12
View File
@@ -79,6 +79,18 @@ 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
passed 18/18.
## December 5 inlay hints from occurrence signatures
`include/vls/features/InlayHints.hpp` finds the top-level argument starts of a
call (bounded, nested-bracket/literal/comment aware) and projects one
parameter-type hint per argument from the compiler signature, filtered to the
requested range and bounded. The server advertises `inlayHintProvider` and
serves `textDocument/inlayHint` through `EditorDiagnostics`; a real stdio
session with the stock observer returned
`inlayHint: 1 first: [({'character': 41, 'line': 18}, 'std::string_view:', 2)]`
for the `fnv1a64(text)` argument. `vls_feature_tests` grew from 54 to 60 cases.
All 18 native suites and all 18 CMake tests passed.
## December 5 semantic tokens from stock occurrences
`include/vls/features/SemanticTokens.hpp` normalizes occurrence tokens
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include <compare>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace vls::features::inlay_hints {
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 Hint {
Position position;
std::string label;
std::uint32_t kind{}; // LSP InlayHintKind: 2 is Parameter
bool padding_left{}, padding_right{};
auto operator<=>(const Hint &) const = default;
};
struct Limits {
std::size_t arguments{16};
std::size_t hints{256};
std::size_t labelBytes{128};
};
// Byte offsets of the top-level argument starts of the call whose '(' follows
// CALLEE_END. Nested brackets, literals and comments do not split arguments.
[[nodiscard]] std::vector<std::size_t>
argument_starts(std::string_view text, std::size_t callee_end, const Limits & = Limits{});
// One parameter-type hint before each argument, taken from the compiler
// signature for that position. Hints outside the requested range are skipped;
// a signature without that parameter contributes nothing.
[[nodiscard]] std::vector<Hint> parameter_hints(std::span<const std::string> signatures,
std::string_view text, std::size_t callee_end,
Range requested, const Limits & = Limits{});
} // namespace vls::features::inlay_hints
@@ -54,6 +54,9 @@ class EditorDiagnostics {
Documents::Range range) const;
// Semantic tokens for the document's proven occurrences, delta-encoded.
[[nodiscard]] Void::LanguageServer::Protocol::Json semantic_tokens(std::string_view uri) const;
// Parameter-type hints from the compiler signature, within the range.
[[nodiscard]] Void::LanguageServer::Protocol::Json inlay_hints(std::string_view uri,
Documents::Range range) const;
struct NavigationReply {
Void::LanguageServer::Protocol::Json result;
+28
View File
@@ -266,6 +266,8 @@ DispatchResult Server::handle(std::string_view body) {
capabilities.emplace("selectionRangeProvider", Json{true});
capabilities.emplace("foldingRangeProvider", Json{true});
}
if (diagnostics_ && diagnostics_->supports_occurrences())
capabilities.emplace("inlayHintProvider", Json{true});
if (diagnostics_ && diagnostics_->supports_occurrences())
capabilities.emplace(
"semanticTokensProvider",
@@ -386,6 +388,32 @@ DispatchResult Server::handle(std::string_view body) {
}
return reply(id, "result", diagnostics_->selection_ranges(*uri, selected));
}
if (*method == "textDocument/inlayHint") {
if (!diagnostics_ || !diagnostics_->supports_occurrences())
return error(id, -32601, "Method not found");
const auto *uri = as_string(member(member(params, "textDocument"), "uri"));
const auto *range = member(params, "range");
const auto *start = member(range, "start");
const auto *end = member(range, "end");
const auto coordinate = [](const Json *value,
std::string_view key) -> std::optional<std::uint32_t> {
const auto *field = member(value, key);
const auto *number = field ? std::get_if<std::int64_t>(&field->value) : nullptr;
if (!number || *number < 0 ||
*number > Void::LanguageServer::Documents::kMaxPositionValue)
return std::nullopt;
return static_cast<std::uint32_t>(*number);
};
const auto start_line = coordinate(start, "line"),
start_character = coordinate(start, "character");
const auto end_line = coordinate(end, "line"), end_character = coordinate(end, "character");
if (!uri || !Void::LanguageServer::Documents::client_uri_key(*uri) || !start_line ||
!start_character || !end_line || !end_character)
return error(id, -32602, "Expected textDocument.uri and a bounded range");
return reply(id, "result",
diagnostics_->inlay_hints(
*uri, {{*start_line, *start_character}, {*end_line, *end_character}}));
}
if (*method == "textDocument/semanticTokens/full") {
if (!diagnostics_ || !diagnostics_->supports_occurrences())
return error(id, -32601, "Method not found");
+127
View File
@@ -0,0 +1,127 @@
#include <vls/features/InlayHints.hpp>
#include <vls/features/SignatureHelp.hpp>
#include <algorithm>
namespace vls::features::inlay_hints {
namespace {
Position position_of(std::string_view text, std::size_t offset) {
offset = std::min(offset, text.size());
Position position;
std::size_t start{};
while (true) {
const auto newline = text.find('\n', start);
const auto end = newline == std::string_view::npos ? text.size() : newline;
if (offset <= end)
return {position.line, static_cast<std::uint32_t>(offset - start)};
start = newline + 1;
++position.line;
}
}
bool in_range(Position position, Range range) {
return range.start <= position && position <= range.end;
}
} // namespace
std::vector<std::size_t> argument_starts(std::string_view text, std::size_t callee_end,
const Limits &limits) {
std::vector<std::size_t> starts;
if (callee_end > text.size())
return starts;
const auto open = text.find('(', callee_end);
if (open == std::string_view::npos)
return starts;
int depth{};
char quote{'\0'};
bool line_comment{};
bool block_comment{};
bool pending = true; // next non-space content starts an argument
for (std::size_t index = open + 1; index < text.size(); ++index) {
const char ch = text[index];
const char next = index + 1 < text.size() ? text[index + 1] : '\0';
if (line_comment) {
if (ch == '\n')
line_comment = false;
continue;
}
if (block_comment) {
if (ch == '*' && next == '/') {
block_comment = false;
++index;
}
continue;
}
if (quote != '\0') {
if (ch == '\\')
++index;
else if (ch == quote)
quote = '\0';
continue;
}
if (ch == '/' && next == '/') {
line_comment = true;
++index;
continue;
}
if (ch == '/' && next == '*') {
block_comment = true;
++index;
continue;
}
if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
continue;
if (ch == ')' && depth == 0)
break;
if (ch == ',' && depth == 0) {
pending = true;
continue;
}
if (pending) {
if (starts.size() == limits.arguments)
break;
starts.push_back(index);
pending = false;
}
if (ch == '"' || ch == '\'')
quote = ch;
else if (ch == '(' || ch == '[' || ch == '{')
++depth;
else if ((ch == ')' || ch == ']' || ch == '}') && depth > 0)
--depth;
}
return starts;
}
std::vector<Hint> parameter_hints(std::span<const std::string> signatures, std::string_view text,
std::size_t callee_end, Range requested, const Limits &limits) {
std::vector<Hint> hints;
const auto arguments = argument_starts(text, callee_end, limits);
if (arguments.empty())
return hints;
std::vector<std::string> parameters;
for (const auto &signature : signatures) {
const auto parsed = signature::parse(signature);
parameters.clear();
for (const auto &parameter : parsed.parameters)
parameters.push_back(parameter.label);
if (parameters.size() < arguments.size())
continue;
for (std::size_t index = 0; index != arguments.size(); ++index) {
if (hints.size() == limits.hints)
return hints;
const auto position = position_of(text, arguments[index]);
if (!in_range(position, requested))
continue;
std::string label = parameters[index];
if (label.size() > limits.labelBytes)
label.resize(limits.labelBytes);
hints.push_back({position, label + ":", 2, false, true});
}
break;
}
return hints;
}
} // namespace vls::features::inlay_hints
+54
View File
@@ -4,6 +4,7 @@
#include <vls/features/Completion.hpp>
#include <vls/features/DocumentSymbols.hpp>
#include <vls/features/IndexNavigation.hpp>
#include <vls/features/InlayHints.hpp>
#include <vls/features/SemanticTokens.hpp>
#include <vls/features/SignatureHelp.hpp>
#include <vls/features/TextStructure.hpp>
@@ -1199,6 +1200,59 @@ Json EditorDiagnostics::semantic_tokens(std::string_view uri) const {
return Json{Json::Object{{"data", Json{std::move(data)}}}};
}
Json EditorDiagnostics::inlay_hints(std::string_view uri, Documents::Range range) 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{Json::Array{}};
receipt = i->second.receipt;
facts = i->second.occurrences;
}
if (!receipt || !facts || !s.valid(*receipt))
return Json{Json::Array{}};
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{Json::Array{}};
std::vector<features::inlay_hints::Hint> hints;
const features::inlay_hints::Range requested{{range.start.line, range.start.character},
{range.end.line, range.end.character}};
for (const auto &occurrence : *facts) {
if (occurrence.use_file.get() != snapshot || occurrence.signature.empty())
continue;
const auto use = snapshot->range_to_offsets(occurrence.use);
if (!use)
continue;
const std::vector<std::string> signatures{occurrence.signature};
const auto produced = features::inlay_hints::parameter_hints(signatures, snapshot->text,
use->second, requested);
hints.insert(hints.end(), produced.begin(), produced.end());
}
std::ranges::sort(hints);
const auto unique = std::ranges::unique(hints);
hints.erase(unique.begin(), unique.end());
Json::Array result;
for (const auto &hint : hints) {
if (result.size() == 256)
break;
result.push_back(
Json{Json::Object{{"position", position({hint.position.line, hint.position.character})},
{"label", Json{hint.label}},
{"kind", Json{static_cast<std::int64_t>(hint.kind)}},
{"paddingRight", Json{hint.padding_right}}}});
}
return Json{std::move(result)};
}
void EditorDiagnostics::set_transactional_rename(bool supported) {
std::lock_guard lock{state_->mutex};
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_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 features/DocumentSymbolsTests.cpp features/TextStructureTests.cpp features/CodeActionsTests.cpp features/SemanticTokensTests.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)
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)
+76
View File
@@ -0,0 +1,76 @@
#include <vls/features/InlayHints.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
#include <vector>
namespace {
using namespace vls::features::inlay_hints;
using Void::Testing::expect;
using Void::Testing::require;
Range whole_document() { return {{0, 0}, {1000, 0}}; }
} // namespace
VOID_TEST(InlayHints, finds_top_level_argument_starts) {
const std::string text = "call(1, two, three);";
const auto starts = argument_starts(text, 4);
require(starts.size() == 3);
expect(text.substr(starts[0], 1) == "1");
expect(text.substr(starts[1], 3) == "two");
expect(text.substr(starts[2], 5) == "three");
expect(argument_starts("call();", 4).empty());
expect(argument_starts("call", 4).empty());
}
VOID_TEST(InlayHints, nested_brackets_literals_and_comments_do_not_split) {
const std::string text = R"(call(inner(1, 2), [3, 4], {5, 6}, "a, b", /* , */ tail));)";
const auto starts = argument_starts(text, 4);
require(starts.size() == 5);
expect(text.substr(starts[1], 1) == "[");
expect(text.substr(starts[3], 1) == "\"");
expect(text.find("tail", starts[4]) == starts[4]);
}
VOID_TEST(InlayHints, parameter_hints_follow_the_signature) {
const std::vector<std::string> signatures{"int add(int, double)"};
const std::string text = "auto x = add(1, 2.0);";
const auto hints = parameter_hints(signatures, text, text.find("add") + 3, whole_document());
require(hints.size() == 2);
expect(hints[0].label == "int:" && hints[0].position.character == 13);
expect(hints[1].label == "double:" && hints[1].position.character == 16);
expect(hints[0].kind == 2 && hints[0].padding_right && !hints[0].padding_left);
}
VOID_TEST(InlayHints, hints_are_filtered_by_the_requested_range) {
const std::vector<std::string> signatures{"int add(int, int)"};
const std::string text = "add(1, 2);";
const auto hints = parameter_hints(signatures, text, 3, {{0, 4}, {0, 5}});
require(hints.size() == 1);
expect(hints.front().label == "int:");
expect(hints.front().position.character == 4);
}
VOID_TEST(InlayHints, a_short_signature_or_missing_signature_contributes_nothing) {
const std::string text = "add(1, 2, 3);";
expect(parameter_hints(std::vector<std::string>{"int add(int, int)"}, text, 3, whole_document())
.empty());
expect(parameter_hints({}, text, 3, whole_document()).empty());
expect(parameter_hints(std::vector<std::string>{"int add(int, int, int)"}, "add();", 3,
whole_document())
.empty());
}
VOID_TEST(InlayHints, hints_and_labels_are_bounded) {
std::vector<std::string> signatures{"void f(int, int, int, int)"};
const std::string text = "f(1, 2, 3, 4);";
Limits limits;
limits.arguments = 2;
limits.hints = 1;
limits.labelBytes = 2;
const auto hints = parameter_hints(signatures, text, 1, whole_document(), limits);
require(hints.size() == 1);
expect(hints.front().label == "in:");
}