refactor(editor): share the compdb entry query with a new CLI command
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 8s

This commit is contained in:
faumaray committed 2026-12-04 08:09:11 +03:00
1 parent af735c28ff
commit f5eb489e79
9 files changed
+221 -64

No files matched your search

+81
View File
@@ -1201,6 +1201,71 @@ int execute_tokens_command(std::string_view sub, const TokensCmdOptions &opts) {
return 0;
}
struct CompdbEntriesCmdOptions {
std::string project_arg;
std::optional<std::string> build_arg;
std::optional<std::string> file_arg;
std::string limit_arg{"50"};
};
int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) {
int parsed_limit = 0;
if (!Void::Str::to_int(opts.limit_arg, parsed_limit) || parsed_limit < 0 ||
parsed_limit > 500) {
std::cerr << "vbs compdb entries: invalid --limit value '" << opts.limit_arg << "'\n";
return 2;
}
const auto limit = static_cast<std::size_t>(parsed_limit);
const std::filesystem::path project_root{opts.project_arg};
const std::filesystem::path build_root =
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
auto selection = Editor::read_selection_state(project_root);
if (!selection) {
std::cerr << "vbs compdb entries: " << selection.error().message() << '\n';
return 1;
}
std::filesystem::path compdb_path;
if (selection->has_value()) {
compdb_path = (*selection)->selected_compdb_path;
} else {
std::error_code ec;
const auto root_alias = build_root / "compile_commands.json";
if (std::filesystem::exists(root_alias, ec)) {
compdb_path = root_alias;
}
}
if (compdb_path.empty()) {
std::cerr << "vbs compdb entries: no compilation database is published; "
"run 'vbs compdb export' first\n";
return 1;
}
Editor::CompdbQuery query;
query.file_filter = opts.file_arg.value_or(std::string{});
query.limit = limit;
auto queried = Editor::query_compdb_entries(compdb_path, query);
if (!queried) {
std::cerr << "vbs compdb entries: " << queried.error().message() << '\n';
return 1;
}
std::cout << "# " << queried->compdb_path.string() << " (" << queried->total
<< " matching, showing " << queried->entries.size() << ")\n";
for (const auto &entry : queried->entries) {
std::cout << entry.file << '\n';
if (!entry.arguments.empty()) {
std::cout << " ";
for (const auto &argument : entry.arguments) {
std::cout << argument << ' ';
}
std::cout << '\n';
} else if (!entry.command.empty()) {
std::cout << " " << entry.command << '\n';
}
}
return 0;
}
struct VerifyCmdOptions {
std::optional<std::string> name_arg;
std::optional<std::string> version_arg;
@@ -2518,6 +2583,7 @@ int main(int argc, char **argv) {
TokensCmdOptions tokens_opts;
LockCmdOptions lock_opts;
VerifyCmdOptions verify_opts;
CompdbEntriesCmdOptions compdb_entries_opts;
publish_opts.project_arg = cwd;
BridgeCmdOptions bridge_opts;
GcCmdOptions gc_opts;
@@ -2681,6 +2747,18 @@ int main(int argc, char **argv) {
publish_binary_opts.token_env, "VBS_REGISTRY_TOKEN");
add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary.
auto &compdb_entries_root_cmd =
root.subcommand("compdb-entries", "Query bounded entries from the published compile database");
compdb_entries_root_cmd
.option_default("--project", "-C", "Project directory", compdb_entries_opts.project_arg,
cwd)
.option("--build-dir", "-B", "Build directory", compdb_entries_opts.build_arg)
.option("--file", "", "Only entries whose source path ends with this value",
compdb_entries_opts.file_arg)
.option_default("--limit", "", "Maximum entries (0-500)", compdb_entries_opts.limit_arg,
"50");
add_log_flags(compdb_entries_root_cmd);
auto &verify_cmd =
root.subcommand("verify", "Verify a detached Ed25519 signature over a package artifact");
verify_cmd
@@ -3143,6 +3221,9 @@ int main(int argc, char **argv) {
if (cmd == "verify") {
return execute_verify_command(verify_opts);
}
if (cmd == "compdb-entries") {
return execute_compdb_entries_command(compdb_entries_opts);
}
if (cmd == "bridge") {
return execute_bridge_command(bridge_opts);
}