feat(ide): export a portable VS Code extension; publish Void/VbsVsCode
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 4s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 58s

This commit is contained in:
faumaray committed 2026-12-05 09:50:21 +03:00
1 parent 399b52c31c
commit 12a52bbd0d
9 files changed
+278 -2

No files matched your search

+139
View File
@@ -1150,6 +1150,140 @@ query_compdb_entries(const std::filesystem::path &compdb_path, const CompdbQuery
namespace {
Void::Result::Result<IdePluginReport, Void::Result::Error>
export_ide_plugin_assets(const IdePluginOptions &options) {
using Util::json_array;
using Util::json_quote;
std::error_code ec;
const auto output = options.output_dir.lexically_normal();
std::filesystem::create_directories(output, ec);
if (ec) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::io_error,
std::format("cannot create plugin directory '{}': {}", output.string(), ec.message()))};
}
IdePluginReport report;
const auto write_asset =
[&](const std::filesystem::path &path,
std::string_view content) -> Void::Result::Result<void, Void::Result::Error> {
if (!options.force && std::filesystem::exists(path, ec)) {
report.skipped_existing_files.push_back(path);
return {};
}
auto written = Platform::atomic_write_file(path, content, false);
if (!written) {
return std::unexpected{written.error()};
}
report.written_files.push_back(path);
return {};
};
const std::string project = options.project_root.lexically_normal().string();
const std::string build = options.build_root.lexically_normal().string();
struct PluginCommand {
std::string id;
std::string title;
std::vector<std::string> args;
};
const std::vector<PluginCommand> commands = {
{"vbs.build", "VBS: Build", {"build"}},
{"vbs.test", "VBS: Test", {"test"}},
{"vbs.install", "VBS: Install", {"install", "--prefix", "build/install"}},
{"vbs.package",
"VBS: Package (installer)",
{"install", "--prefix", "build/install", "--archive", "build/install/installer.sh",
"--archive-format", "sh"}},
{"vbs.daemonStart", "VBS: Start Daemon", {"daemon", "run"}},
{"vbs.daemonStatus", "VBS: Daemon Status", {"daemon", "status"}},
};
const std::string package_json =
"{\n"
" \"name\": \"vbs-tools\",\n"
" \"displayName\": \"VoidBuildSystem\",\n"
" \"description\": \"Build, test, install and package with VoidBuildSystem.\",\n"
" \"version\": \"0.1.0\",\n"
" \"publisher\": \"void\",\n"
" \"license\": \"MIT\",\n"
" \"engines\": {\"vscode\": \"^1.80.0\"},\n"
" \"categories\": [\"Other\"],\n"
" \"activationEvents\": [],\n"
" \"main\": \"./extension.js\",\n"
" \"contributes\": {\n \"commands\": " +
json_array(commands,
[](const PluginCommand &command) {
return "{\"command\":" + json_quote(command.id) +
",\"title\":" + json_quote(command.title) + '}';
}) +
"\n }\n}\n";
std::string extension_js =
"// Generated by `vbs ide plugin`. Requires the `vbs` executable in PATH or VBS_BIN.\n"
"const vscode = require('vscode');\n"
"const vbs = process.env.VBS_BIN || \"vbs\";\n\n"
"function projectArgs() {\n"
" const folders = vscode.workspace.workspaceFolders;\n"
" return folders && folders.length ? ['--project', folders[0].uri.fsPath] : [];\n"
"}\n\n"
"function runTerminal(name, args) {\n"
" const terminal = vscode.window.createTerminal({ name });\n"
" terminal.show(true);\n"
" const full = [...args, ...projectArgs()];\n"
" terminal.sendText([vbs, ...full].map((a) => (a.includes(' ') ? `'${a}'` : a)).join(' '));\n"
"}\n\n"
"const commands = [\n";
for (const auto &command : commands) {
extension_js += " [" + json_quote(command.id) + ", " + json_quote(command.title) + ", " +
json_array(command.args, json_quote) + "],\n";
}
extension_js += "];\n\n"
"function activate(context) {\n"
" for (const [id, title, args] of commands) {\n"
" context.subscriptions.push(vscode.commands.registerCommand(id, () => "
"runTerminal(title, args)));\n"
" }\n"
"}\n\n"
"function deactivate() {}\n\n"
"module.exports = { activate, deactivate };\n";
const std::string readme = std::format(
"# VoidBuildSystem editor extension\n\n"
"Generated by `vbs ide plugin` for the project at `{}`.\n\n"
"## Commands\n\n{}\n\n"
"## Install\n\n"
"```sh\ncd {} && npm install -g @vscode/vsce && vsce package\n"
"code --install-extension vbs-tools-0.1.0.vsix\n```\n\n"
"Set `VBS_BIN` if `vbs` is not on `PATH`.\n",
project,
[&] {
std::string list;
for (const auto &command : commands) {
list += "- `" + command.title + "` (`" + command.id + "`)\n";
}
return list;
}(),
output.string());
if (options.editor != IdeKind::VsCode) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::unsupported,
"editor plugin assets are currently generated for vscode only")};
}
for (const auto &[name, content] :
std::vector<std::pair<std::string, std::string>>{{"package.json", package_json},
{"extension.js", extension_js},
{"README.md", readme}}) {
if (auto written = write_asset(output / name, content); !written) {
return std::unexpected{written.error()};
}
}
return report;
}
std::string file_api_target_type(TargetKind kind) {
switch (kind) {
case TargetKind::Executable:
@@ -1390,4 +1524,9 @@ std::string format_ide_query_json(const Graph::BuildGraph &graph,
return out;
}
Void::Result::Result<IdePluginReport, Void::Result::Error>
generate_ide_plugin_assets(const IdePluginOptions &options) {
return export_ide_plugin_assets(options);
}
} // namespace Void::Build::Editor