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
@@ -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