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:
1 parent
12a71ff692
commit
130cb57a7f
12 files changed
+360
-10
No files matched your search
@@ -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:");
|
||||
}
|
||||
Reference in new issue
Block a user