Add return-type inlay hints after calls
The bounded inlay-hint core now matches a call's closing parenthesis (nested calls, literals and comments aware) and places a type hint labelled with the compiler's canonical type. EditorDiagnostics emits it for every occurrence independently of parameter signatures. Registered tests cover nested matching, placement, skipped cases and bounds; a real stdio session showed both the parameter and return hints at the fnv1a64 call.
This commit is contained in:
1 parent
0bf5873069
commit
2cced8363d
6 files changed
+135
-7
No files matched your search
@@ -20,7 +20,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
||||
| 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 |
|
||||
| textDocument/inlayHint (parameter and return 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 fileOperations (didCreate/didRename/didDelete) | `vls_feature_tests`, real stdio session |
|
||||
@@ -40,7 +40,7 @@ missing part. Updated December 5, 2026 after semantic tokens and inlay hints.
|
||||
| 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 |
|
||||
| textDocument/formatting | no formatter is available; needs a dependency decision |
|
||||
|
||||
## Next slices
|
||||
|
||||
|
||||
@@ -79,6 +79,22 @@ 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 return-type inlay hints
|
||||
|
||||
`include/vls/features/InlayHints.hpp` gained `call_end` (the offset past the
|
||||
matching ')' of a call, nested calls/literals/comments aware) and
|
||||
`return_type_hint`: a type hint after the call's closing parenthesis labelled
|
||||
with the compiler's canonical type. `EditorDiagnostics::inlay_hints` emits it for
|
||||
every occurrence independently of whether a parameter signature exists.
|
||||
|
||||
Real stdio session with the stock observer at `fnv1a64(text)`:
|
||||
```
|
||||
inlayHint: 2 first: [({'character': 41, 'line': 18}, 'std::string_view:', 2),
|
||||
({'character': 46, 'line': 18}, ': long unsigned int', 1)]
|
||||
```
|
||||
Registered `vls_feature_tests` grew to 88 cases. All 18 native suites and all
|
||||
18 CMake tests passed.
|
||||
|
||||
## December 5 code lenses and the reference command
|
||||
|
||||
`include/vls/features/CodeLens.hpp` builds one bounded lens per unique
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -44,4 +45,15 @@ argument_starts(std::string_view text, std::size_t callee_end, const Limits & =
|
||||
std::string_view text, std::size_t callee_end,
|
||||
Range requested, const Limits & = Limits{});
|
||||
|
||||
// Offset just past the matching ')' of the call whose '(' follows CALLEE_END.
|
||||
[[nodiscard]] std::optional<std::size_t> call_end(std::string_view text, std::size_t callee_end,
|
||||
const Limits & = Limits{});
|
||||
|
||||
// A return-type hint after the call's closing parenthesis, labelled with the
|
||||
// compiler's canonical type. Absent when the type is empty, the call is
|
||||
// unterminated or the position is outside the requested range.
|
||||
[[nodiscard]] std::optional<Hint> return_type_hint(std::string_view text, std::size_t callee_end,
|
||||
std::string_view canonical_type, Range requested,
|
||||
const Limits & = Limits{});
|
||||
|
||||
} // namespace vls::features::inlay_hints
|
||||
@@ -124,4 +124,71 @@ std::vector<Hint> parameter_hints(std::span<const std::string> signatures, std::
|
||||
return hints;
|
||||
}
|
||||
|
||||
std::optional<std::size_t> call_end(std::string_view text, std::size_t callee_end, const Limits &) {
|
||||
if (callee_end > text.size())
|
||||
return std::nullopt;
|
||||
const auto open = text.find('(', callee_end);
|
||||
if (open == std::string_view::npos)
|
||||
return std::nullopt;
|
||||
int depth{};
|
||||
char quote{'\0'};
|
||||
bool line_comment{};
|
||||
bool block_comment{};
|
||||
for (std::size_t index = open; 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;
|
||||
} else if (ch == '/' && next == '*') {
|
||||
block_comment = true;
|
||||
++index;
|
||||
} else if (ch == '"' || ch == '\'') {
|
||||
quote = ch;
|
||||
} else if (ch == '(') {
|
||||
++depth;
|
||||
} else if (ch == ')' && --depth == 0) {
|
||||
return index + 1;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<Hint> return_type_hint(std::string_view text, std::size_t callee_end,
|
||||
std::string_view canonical_type, Range requested,
|
||||
const Limits &limits) {
|
||||
if (canonical_type.empty())
|
||||
return std::nullopt;
|
||||
const auto end = call_end(text, callee_end);
|
||||
if (!end)
|
||||
return std::nullopt;
|
||||
const auto position = position_of(text, *end);
|
||||
if (!in_range(position, requested))
|
||||
return std::nullopt;
|
||||
std::string label = ": ";
|
||||
label += canonical_type;
|
||||
if (label.size() > limits.labelBytes)
|
||||
label.resize(limits.labelBytes);
|
||||
return Hint{position, std::move(label), 1, true, false};
|
||||
}
|
||||
|
||||
} // namespace vls::features::inlay_hints
|
||||
@@ -1324,15 +1324,20 @@ Json EditorDiagnostics::inlay_hints(std::string_view uri, Documents::Range range
|
||||
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())
|
||||
if (occurrence.use_file.get() != snapshot)
|
||||
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());
|
||||
if (!occurrence.signature.empty()) {
|
||||
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());
|
||||
}
|
||||
if (const auto returned = features::inlay_hints::return_type_hint(
|
||||
snapshot->text, use->second, occurrence.canonical_type, requested))
|
||||
hints.push_back(*returned);
|
||||
}
|
||||
std::ranges::sort(hints);
|
||||
const auto unique = std::ranges::unique(hints);
|
||||
|
||||
@@ -74,3 +74,31 @@ VOID_TEST(InlayHints, hints_and_labels_are_bounded) {
|
||||
require(hints.size() == 1);
|
||||
expect(hints.front().label == "in:");
|
||||
}
|
||||
|
||||
VOID_TEST(InlayHints, call_end_matches_nested_calls_and_literals) {
|
||||
const std::string text = "f(g(1, 2), \")\", h()) + 1;";
|
||||
const auto end = call_end(text, 1);
|
||||
require(end.has_value());
|
||||
expect(*end == text.find(") + 1") + 1);
|
||||
expect(!call_end("f(1, 2", 1).has_value());
|
||||
expect(!call_end("f", 1).has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(InlayHints, return_type_hint_follows_the_closing_paren) {
|
||||
const std::string text = "auto x = f(1, 2);";
|
||||
const auto hint = return_type_hint(text, text.find("f") + 1, "int", whole_document());
|
||||
require(hint.has_value());
|
||||
expect(hint->label == ": int");
|
||||
expect(hint->kind == 1 && hint->padding_left && !hint->padding_right);
|
||||
expect(hint->position.character == text.find(")") + 1);
|
||||
}
|
||||
|
||||
VOID_TEST(InlayHints, return_type_hint_requires_type_call_and_range) {
|
||||
const std::string text = "auto x = f(1);";
|
||||
expect(!return_type_hint(text, 10, "", whole_document()).has_value());
|
||||
expect(!return_type_hint("auto x = f(1", 10, "int", whole_document()).has_value());
|
||||
expect(!return_type_hint(text, 10, "int", {{0, 0}, {0, 5}}).has_value());
|
||||
const auto bounded = return_type_hint(text, 10, std::string(300, 't'), whole_document());
|
||||
require(bounded.has_value());
|
||||
expect(bounded->label.size() == 128);
|
||||
}
|
||||
Reference in new issue
Block a user