Implement the VLS roadmap on the native VBS build
Native VBS and CMake builds of the server and every registered suite: protocol and document sync, VBS/compdb providers, stock GCC diagnostics (including in-process default profile preparation), the stock occurrence observer and hover/definition, the bounded Scheduler, C++ module graph, scan and artifact cache with real CMI production, the context-aware symbol index with schema-2 snapshot migration, navigation and guarded rename, reflection provenance with splice-origin extraction, index-backed completion and signature help, live GCC worker control with a registered DAP suite, and the Neovim and VS Code clients. VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced from the versioned patches and verified stepping reflection/template code with projected values 17/34 and 41/82.
This commit is contained in:
1 parent
ca04975d54
commit
da8003f6d4
310 files changed
+47552
-480
No files matched your search
@@ -0,0 +1,159 @@
|
||||
#include <vls/features/SignatureHelp.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace vls::features::signature;
|
||||
using Void::Testing::expect;
|
||||
using Void::Testing::require;
|
||||
|
||||
std::vector<std::string> parameter_labels(const Signature &signature) {
|
||||
std::vector<std::string> labels;
|
||||
for (const auto ¶meter : signature.parameters)
|
||||
labels.push_back(parameter.label);
|
||||
return labels;
|
||||
}
|
||||
|
||||
std::vector<std::string> single(std::string_view text) { return {std::string{text}}; }
|
||||
} // namespace
|
||||
|
||||
VOID_TEST(SignatureHelp, parses_a_plain_signature) {
|
||||
const auto parsed = parse("std::string_view Void::Hash::fnv1a64(std::string_view)");
|
||||
expect(parsed.label == "std::string_view Void::Hash::fnv1a64(std::string_view)");
|
||||
expect(parameter_labels(parsed) == std::vector<std::string>{"std::string_view"});
|
||||
require(parsed.parameters.front().range.has_value());
|
||||
expect(parsed.parameters.front().range->second - parsed.parameters.front().range->first ==
|
||||
parsed.parameters.front().label.size());
|
||||
expect(parsed.label.substr(parsed.parameters.front().range->first,
|
||||
parsed.parameters.front().label.size()) ==
|
||||
parsed.parameters.front().label);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, splits_multiple_parameters) {
|
||||
const auto parsed = parse("int twice(int, double, const char *)");
|
||||
expect(parameter_labels(parsed) == std::vector<std::string>{"int", "double", "const char *"});
|
||||
for (const auto ¶meter : parsed.parameters) {
|
||||
require(parameter.range.has_value());
|
||||
expect(parsed.label.substr(parameter.range->first, parameter.label.size()) ==
|
||||
parameter.label);
|
||||
}
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, ignores_commas_in_nested_brackets_and_templates) {
|
||||
const auto parsed =
|
||||
parse("void f(std::pair<int, int>, std::array<char, 3>, int (*)(int, int), int[])");
|
||||
expect(parameter_labels(parsed) == std::vector<std::string>{"std::pair<int, int>",
|
||||
"std::array<char, 3>",
|
||||
"int (*)(int, int)", "int[]"});
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, handles_empty_and_missing_parameter_lists) {
|
||||
expect(parse("int f()").parameters.empty());
|
||||
expect(parse("int f( )").parameters.empty());
|
||||
expect(parse("int value").parameters.empty());
|
||||
expect(parse("broken(").parameters.empty());
|
||||
expect(parse("").label.empty());
|
||||
expect(parse("int f(int,)").parameters.size() == 1);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, counts_top_level_commas) {
|
||||
const std::string call = "f(a, b, c);";
|
||||
expect(active_parameter(call, call.find("(a") + 2) == 0);
|
||||
expect(active_parameter(call, call.find("b")) == 1);
|
||||
expect(active_parameter(call, call.find("c")) == 2);
|
||||
expect(active_parameter(call, call.find(");")) == 2);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, nested_calls_and_brackets_do_not_count) {
|
||||
const std::string call = "outer(inner(1, 2), [3, 4], {5, 6}, ";
|
||||
expect(active_parameter(call, call.size()) == 3);
|
||||
const std::string nested = "outer(inner(1, 2))";
|
||||
// Inside inner's second argument, not the outer call.
|
||||
expect(active_parameter(nested, nested.find("2)")) == 1);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, literals_and_comments_do_not_count) {
|
||||
const std::string call = R"(f("a, b", 'x', /* , */ suffix, // ,
|
||||
after))";
|
||||
expect(active_parameter(call, call.find("suffix")) == 2);
|
||||
expect(active_parameter(call, call.size() - 2) == 3);
|
||||
expect(active_parameter(R"(f("unterminated, )", 20) == 0);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, without_an_open_parenthesis_the_parameter_is_zero) {
|
||||
expect(active_parameter("int value = f", 14) == 0);
|
||||
expect(active_parameter("", 0) == 0);
|
||||
expect(active_parameter("f(a", 99) == 0);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, backward_scan_is_bounded) {
|
||||
Limits limits;
|
||||
limits.scanBytes = 3;
|
||||
const std::string call = std::string(64, ' ') + "f(a, b";
|
||||
expect(active_parameter(call, call.size(), limits) == 0);
|
||||
expect(active_parameter(call, call.size()) == 1);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, build_assembles_signatures_and_active_parameter) {
|
||||
const std::vector<std::string> signatures{"int f(int, int)", ""};
|
||||
const std::string call = "auto x = f(1, ";
|
||||
const auto result = build(signatures, call, call.size());
|
||||
require(result.signatures.size() == 1);
|
||||
expect(result.active_signature == 0);
|
||||
expect(result.active_parameter == 1);
|
||||
const std::vector<std::string> none;
|
||||
expect(build(none, call, call.size()).signatures.empty());
|
||||
const std::vector<std::string> empty{"", ""};
|
||||
expect(build(empty, call, call.size()).signatures.empty());
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, build_bounds_signatures_and_parameters) {
|
||||
Limits limits;
|
||||
limits.signatures = 1;
|
||||
limits.parameters = 2;
|
||||
limits.labelBytes = 16;
|
||||
const std::vector<std::string> signatures{"int f(int, int, int)", "int g(int)"};
|
||||
const auto result = build(signatures, "f(1, 2, 3)", 9, limits);
|
||||
require(result.signatures.size() == 1);
|
||||
expect(result.signatures.front().label.size() == 16);
|
||||
expect(result.signatures.front().parameters.size() == 2);
|
||||
expect(result.active_parameter == 2);
|
||||
limits.parameterBytes = 3;
|
||||
const auto short_parameters = parse("int f(long long)", limits);
|
||||
require(!short_parameters.parameters.empty());
|
||||
expect(short_parameters.parameters.front().label.size() == 3);
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, in_call_spans_the_argument_list) {
|
||||
const std::string_view call = "add(1, 2)";
|
||||
expect(!in_call(call, 0, 3, 3));
|
||||
expect(in_call(call, 0, 3, 4));
|
||||
expect(in_call(call, 0, 3, 6));
|
||||
expect(in_call(call, 0, 3, 8));
|
||||
expect(!in_call(call, 0, 3, 9));
|
||||
expect(!in_call(call, 4, 2, 6));
|
||||
expect(!in_call("add 1", 0, 3, 3));
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, in_call_ignores_literals_and_comments) {
|
||||
const std::string text = R"x(f(a, ")", /* ) */ b))x";
|
||||
const auto inside = text.find("b)");
|
||||
expect(in_call(text, 0, 1, inside));
|
||||
const std::string closed = R"y(f(")"))y";
|
||||
expect(!in_call(closed, 0, 1, closed.size()));
|
||||
}
|
||||
|
||||
VOID_TEST(SignatureHelp, in_call_scan_is_bounded) {
|
||||
Limits limits;
|
||||
limits.scanBytes = 4;
|
||||
const std::string call = "f(" + std::string(32, 'x') + ", y)";
|
||||
expect(in_call(call, 0, 1, call.size() - 1, limits));
|
||||
const std::string long_call = "f(" + std::string(32, 'x') + ")";
|
||||
// The matching ')' lies outside the bounded window, so the answer stays
|
||||
// conservative (still inside) rather than inventing a close.
|
||||
expect(in_call(long_call, 0, 1, long_call.size() - 1, limits));
|
||||
}
|
||||
Reference in new issue
Block a user