diff options
Diffstat (limited to 'Scripts/main.js')
| -rw-r--r-- | Scripts/main.js | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/Scripts/main.js b/Scripts/main.js index 0155d80..8515873 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -330,7 +330,7 @@ const stepCache = { }, async fetch(cwd, buildZigMtimeMs, buildZonMtimeMs) { - const zigPath = await resolveExecutable(CONFIG_KEYS.zigPath, "zig"); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; const result = await runProcess(zigPath, { @@ -420,7 +420,7 @@ function runProcess(command, options) { }); } -async function findExecutableOnPath(commandName) { +async function findOnPath(commandName) { const result = await runProcess("/usr/bin/env", { args: ["which", commandName], }); @@ -439,28 +439,37 @@ async function resolveExecutable(configKey, defaultCommand) { return configuredPath; } - return findExecutableOnPath(defaultCommand); + return await findOnPath(defaultCommand); } -// Resolves the Zig executable, surfacing a single localized warning when it's -// missing. Returns null when no path is found — callers must short-circuit. -async function requireZig() { +/** + * Resolve the zig executable, show warning if not found + * + * @returns {Promise(string|null)} - Path to the zig executable or null if not found + */ +async function resolveZigExecutable() { const zigPath = await resolveExecutable(CONFIG_KEYS.zigPath, "zig"); if (!zigPath) { nova.workspace.showWarningMessage( localizedText( "warning.zig.not_found", - "Zig was not found. Install it or set a Zig executable path in Zig extension settings." - ) + "Zig was not found. Install it or set a Zig executable path in Zig extension settings.", + ), ); return null; } return zigPath; } -async function findExecutableWithXcode(commandName) { +/** + * Resolve executable using Xcode xcrun + * + * @param {string} executableName - Executable name + * @returns {Promise(string|null)} - Path to the executable or null if not found + */ +async function findWithXcode(executableName) { const result = await runProcess("/usr/bin/xcrun", { - args: ["--find", commandName], + args: ["--find", executableName], }); if (result.status !== 0) { @@ -471,23 +480,25 @@ async function findExecutableWithXcode(commandName) { return path.length > 0 ? path : null; } -async function resolveLLDBDAPExecutable() { +/** + * Resolve the lldb-dap executable + * + * @returns {Promise(string|null)} - Path to the lldb-dap executable or null if not found + */ +async function resolveLldbDapExecutable() { const configuredPath = getConfigValue(CONFIG_KEYS.lldbDapPath); if (configuredPath) { return configuredPath; } - const xcodePath = await findExecutableWithXcode("lldb-dap"); + const xcodePath = await findWithXcode("lldb-dap"); if (xcodePath) { return xcodePath; } - return findExecutableOnPath("lldb-dap"); + return await findOnPath("lldb-dap"); } -function executableDisplayName(path, fallback) { - return path || fallback; -} function lldbFrameworkPaths() { return [ @@ -735,8 +746,8 @@ class ZigLanguageServer { localizedText( "warning.zls.stopped_unexpectedly", "The Zig language server stopped unexpectedly ({executable}).", - { executable: executableDisplayName(zlsPath, "zls") } - ) + { executable: zlsPath || "zls" }, + ), ); } }); @@ -950,25 +961,25 @@ class ZigTaskAssistant { } async resolveBuildAction(config, cwd) { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; return this.createAction(zigPath, buildZigArgv(config), cwd); } async resolveDebugBuildAction(config, cwd) { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; return this.createAction( zigPath, buildZigArgv(config, { defaultOptimize: "Debug" }), - cwd + cwd, ); } async resolveBuildRunAction(config, cwd, forceConsole) { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; const step = resolveRunStep(config); @@ -995,7 +1006,7 @@ class ZigTaskAssistant { } async resolveBuildStepAction(step) { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; const cwd = nova.workspace.path || null; @@ -1005,7 +1016,7 @@ class ZigTaskAssistant { } async resolveTestAction(config, cwd) { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; const argv = buildZigArgv(config, { step: "test" }); @@ -1023,7 +1034,7 @@ class ZigTaskAssistant { } async resolveWatchAction(config, cwd) { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; const step = resolveStep(config, "step", null); @@ -1044,7 +1055,7 @@ class ZigTaskAssistant { } async resolveCurrentFileRunAction() { - const zigPath = await requireZig(); + const zigPath = await resolveZigExecutable(); if (!zigPath) return null; const filePath = activeZigFilePath(); @@ -1079,7 +1090,8 @@ class ZigTaskAssistant { } async resolveDebugAction(config, cwd) { - const lldbDapPath = await resolveLLDBDAPExecutable(); + const lldbDapPath = await resolveLldbDapExecutable + (); if (!lldbDapPath) { nova.workspace.showWarningMessage( localizedText( |
