perf(config): memoize descriptor hashes by stat fingerprint; generate plugin tests
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s
VoidBuildSystem CI / fuzz-clang (push) Failing after 4s
VoidBuildSystem CI / sanitizers-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 12:33:56 +03:00
1 parent 09fd3cce39
commit e135ae3023
6 files changed
+306 -35

No files matched your search

+64 -13
View File
@@ -1212,6 +1212,7 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
" \"categories\": [\"Other\"],\n"
" \"activationEvents\": [],\n"
" \"main\": \"./extension.js\",\n"
" \"scripts\": {\"test\": \"node test/extension.test.js\"},\n"
" \"contributes\": {\n \"commands\": " +
json_array(commands,
[](const PluginCommand &command) {
@@ -1232,7 +1233,8 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
" 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"
" terminal.sendText([vbs, ...full].map((a) => (a.includes(' ') ? `'${a}'` : a)).join(' "
"'));\n"
"}\n\n"
"const commands = [\n";
for (const auto &command : commands) {
@@ -1249,6 +1251,51 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
"function deactivate() {}\n\n"
"module.exports = { activate, deactivate };\n";
// Executes the extension against a mocked VS Code API (`npm test`).
const std::string vscode_test_js =
std::string{} +
R"js(// Generated by `vbs ide plugin`: runs extension.js against a mocked VS Code API.
const Module = require('module');
const registered = new Map();
const terminals = [];
const workspace = '/tmp/vbs-workspace';
const vscodeMock = {
window: {
createTerminal: ({ name }) => ({
name,
show() {},
sendText(text) { terminals.push({ name, text }); },
}),
},
commands: {
registerCommand: (id, fn) => { registered.set(id, fn); return { dispose() {} }; },
},
workspace: { workspaceFolders: [{ uri: { fsPath: workspace } }] },
};
const originalLoad = Module._load;
Module._load = function (request) {
if (request === 'vscode') return vscodeMock;
return originalLoad.apply(this, arguments);
};
const extension = require('../extension.js');
extension.activate({ subscriptions: [] });
for (const [, fn] of registered) fn();
)js" +
"const expectedCommands = " + std::to_string(commands.size()) + ";\n" +
R"js(if (registered.size !== expectedCommands)
throw new Error('expected ' + expectedCommands + ' commands, got ' + registered.size);
if (terminals.length !== registered.size) throw new Error('every command must open a terminal');
const build = terminals.find((t) => t.name === 'VBS: Build');
if (!build) throw new Error('build command missing');
if (!build.text.includes('build')) throw new Error('build args missing: ' + build.text);
if (!build.text.includes('--project ' + workspace))
throw new Error('workspace project not injected: ' + build.text);
const install = terminals.find((t) => t.name === 'VBS: Install');
if (!install || !install.text.includes('--prefix')) throw new Error('install prefix missing');
extension.deactivate();
console.log('extension tests passed: ' + terminals.length + ' commands');
)js";
const std::string readme = std::format(
"# VoidBuildSystem editor extension\n\n"
"Generated by `vbs ide plugin` for the project at `{}`.\n\n"
@@ -1295,8 +1342,8 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
for (const auto &[name, content] :
std::vector<std::pair<std::string, std::string>>{{"extension.toml", zed_manifest},
{"tasks.json", zed_tasks},
{"README.md", zed_readme}}) {
{"tasks.json", zed_tasks},
{"README.md", zed_readme}}) {
if (auto written = write_asset(output / name, content); !written) {
return std::unexpected{written.error()};
}
@@ -1309,7 +1356,8 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
" <id>com.faumaray.vbs</id>\n"
" <name>VoidBuildSystem</name>\n"
" <vendor>Void</vendor>\n"
" <description>Build, test, install and package with VoidBuildSystem (VBS).</description>\n"
" <description>Build, test, install and package with VoidBuildSystem "
"(VBS).</description>\n"
" <depends>com.intellij.modules.platform</depends>\n"
" <depends>com.intellij.modules.cidr.lang</depends>\n"
" <actions>\n"
@@ -1319,7 +1367,8 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
" </action>\n"
" <action id=\"Vbs.Install\" class=\"com.faumaray.vbs.InstallAction\"\n"
" text=\"VBS: Install\" description=\"Stage an install prefix\">\n"
" <add-to-group group-id=\"ToolsMenu\" anchor=\"after\" relative-to-action=\"Vbs.Build\"/>\n"
" <add-to-group group-id=\"ToolsMenu\" anchor=\"after\" "
"relative-to-action=\"Vbs.Build\"/>\n"
" </action>\n"
" </actions>\n"
"</idea-plugin>\n";
@@ -1363,7 +1412,8 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
"class InstallAction : AnAction(\"VBS: Install\") {\n"
" override fun actionPerformed(event: AnActionEvent) {\n"
" event.project?.let {\n"
" runVbs(it, \"install\", listOf(\"install\", \"--prefix\", \"build/install\"))\n"
" runVbs(it, \"install\", listOf(\"install\", \"--prefix\", "
"\"build/install\"))\n"
" }\n"
" }\n"
"}\n";
@@ -1371,11 +1421,11 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
"# VbsCLion\n\nCLion (JetBrains) plugin assets for VoidBuildSystem, generated by "
"`vbs ide plugin --editor clion`.\n\nCLion can also read the CMake File API document "
"emitted by `vbs ide generate`, so this plugin is complementary: it adds Tools-menu "
"actions for `vbs build` and `vbs install`.\n\n```sh\n./gradlew buildPlugin\n```\n\nSet "
"actions for `vbs build` and `vbs install`.\n\n```sh\n./gradlew "
"buildPlugin\n```\n\nSet "
"`VBS_BIN` if `vbs` is not on `PATH`.\n";
for (const auto &[name, content] :
std::vector<std::pair<std::string, std::string>>{
for (const auto &[name, content] : std::vector<std::pair<std::string, std::string>>{
{"src/main/resources/META-INF/plugin.xml", plugin_xml},
{"build.gradle.kts", gradle},
{"src/main/kotlin/com/faumaray/vbs/VbsActions.kt", action_kt},
@@ -1392,10 +1442,11 @@ export_ide_plugin_assets(const IdePluginOptions &options) {
"editor plugin assets are generated for vscode, zed and clion 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}}) {
for (const auto &[name, content] : std::vector<std::pair<std::string, std::string>>{
{"package.json", package_json},
{"extension.js", extension_js},
{"test/extension.test.js", vscode_test_js},
{"README.md", readme}}) {
if (auto written = write_asset(output / name, content); !written) {
return std::unexpected{written.error()};
}