aboutsummaryrefslogtreecommitdiff
path: root/Scripts/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/main.js')
-rw-r--r--Scripts/main.js102
1 files changed, 70 insertions, 32 deletions
diff --git a/Scripts/main.js b/Scripts/main.js
index aa11e9e..7477993 100644
--- a/Scripts/main.js
+++ b/Scripts/main.js
@@ -48,7 +48,10 @@ exports.activate = function activate() {
try {
disposable.dispose();
} catch (error) {
- console.error(`[${EXTENSION_ID}] Failed to dispose registration`, error);
+ console.error(
+ `[${EXTENSION_ID}] Failed to dispose registration`,
+ error,
+ );
}
}
});
@@ -76,7 +79,10 @@ exports.deactivate = function deactivate() {
try {
disposable.dispose();
} catch (error) {
- console.error(`[${EXTENSION_ID}] Failed to dispose registration`, error);
+ console.error(
+ `[${EXTENSION_ID}] Failed to dispose registration`,
+ error,
+ );
}
}
});
@@ -385,9 +391,7 @@ function parseProjectName(cwd) {
if (typeof content !== "string" || content.length === 0) return null;
const stripped = content.replace(/\/\/[^\n]*/g, "");
- const match = stripped.match(
- /\.name\s*=\s*(?:"([^"]+)"|\.([A-Za-z_][\w]*))/,
- );
+ const match = stripped.match(/\.name\s*=\s*(?:"([^"]+)"|\.([A-Za-z_][\w]*))/);
if (!match) return null;
return match[1] || match[2] || null;
}
@@ -536,7 +540,30 @@ const stepCache = {
* @param {*} variables - Dictionary of variable names and values
*/
function localizeText(key, fallback, variables) {
- let text = nova.localize(key, fallback);
+ let text = nova.localize(key, null);
+
+ if (key === text) {
+ return `Localization missing for ${key}`;
+ }
+
+ if (!variables || typeof variables !== "object") {
+ return text;
+ }
+
+ for (const [name, value] of Object.entries(variables)) {
+ text = text.split(`{${name}}`).join(String(value));
+ }
+
+ return text;
+}
+
+function localize(key, variables) {
+ let text = nova.localize(key, null);
+
+ if (key === text) {
+ console.warn(`[locales] Missing localization for ${key}`);
+ return text;
+ }
if (!variables || typeof variables !== "object") {
return text;
@@ -628,21 +655,22 @@ async function findOnPath(executableName) {
// package managers use but that may be absent when Nova is launched from the
// Dock (where launchd provides a narrower system PATH than a login shell).
const fallbackPrefixes = [
- "/opt/homebrew/bin", // Homebrew – Apple Silicon
- "/usr/local/bin", // Homebrew – Intel / manual installs
+ "/opt/homebrew/bin", // Homebrew – Apple Silicon
+ "/usr/local/bin", // Homebrew – Intel / manual installs
`${nova.environment && nova.environment.HOME}/.local/bin`, // mise, cargo, etc.
];
- const augmentedPath = [...new Set([
- ...novaPath.split(":").filter(Boolean),
- ...fallbackPrefixes,
- ])].join(":");
+ const augmentedPath = [
+ ...new Set([...novaPath.split(":").filter(Boolean), ...fallbackPrefixes]),
+ ].join(":");
const result = await runProcess("/usr/bin/env", {
args: ["which", executableName],
env: { PATH: augmentedPath },
});
const found = result.stdout.trim();
- console.log(`[${EXTENSION_ID}] findOnPath: ${executableName} → ${result.status === 0 ? found : "not found"}`);
+ console.log(
+ `[${EXTENSION_ID}] findOnPath: ${executableName} → ${result.status === 0 ? found : "not found"}`,
+ );
if (result.status !== 0) {
return null;
@@ -661,7 +689,9 @@ async function findOnPath(executableName) {
async function resolveExecutable(configKey, defaultCommand) {
const configuredPath = getConfigValue(configKey);
if (configuredPath) {
- console.log(`[${EXTENSION_ID}] findOnPath: ${defaultCommand} → config: ${configuredPath}`);
+ console.log(
+ `[${EXTENSION_ID}] findOnPath: ${defaultCommand} → config: ${configuredPath}`,
+ );
return configuredPath;
}
@@ -678,7 +708,7 @@ async function resolveZigExecutable() {
if (!zigPath) {
nova.workspace.showWarningMessage(
localizeText(
- "warning.zig.not_found",
+ "warning.zig.not-found",
"Zig was not found. Install it or set a Zig executable path in Zig extension settings.",
),
);
@@ -877,7 +907,9 @@ function registerCommands() {
const command = payload && payload.command;
const args = (payload && payload.args) || [];
const cwd = (payload && payload.cwd) || workspace.path || null;
- console.log(`[${EXTENSION_ID}] runInTerminal: command=${command} cwd=${cwd}`);
+ console.log(
+ `[${EXTENSION_ID}] runInTerminal: command=${command} cwd=${cwd}`,
+ );
if (!command) {
workspace.showWarningMessage(
@@ -947,10 +979,14 @@ class ZigLanguageServer {
observeConfig(key, restart) {
const onChange = () => {
if (restart) {
- console.log(`[${LANGUAGE_CLIENT_ID}] config changed (${key}) → restart`);
+ console.log(
+ `[${LANGUAGE_CLIENT_ID}] config changed (${key}) → restart`,
+ );
this.start();
} else {
- console.log(`[${LANGUAGE_CLIENT_ID}] config changed (${key}) → push configuration`);
+ console.log(
+ `[${LANGUAGE_CLIENT_ID}] config changed (${key}) → push configuration`,
+ );
this.pushConfiguration().catch((error) => {
console.error(
`[${LANGUAGE_CLIENT_ID}] pushConfiguration failed`,
@@ -997,7 +1033,9 @@ class ZigLanguageServer {
const sinceLastStop = Date.now() - lastZlsStopAt;
if (lastZlsStopAt > 0 && sinceLastStop < ZLS_RESTART_GRACE_MS) {
const wait = ZLS_RESTART_GRACE_MS - sinceLastStop;
- console.log(`[${LANGUAGE_CLIENT_ID}] waiting ${wait}ms for previous ZLS to exit`);
+ console.log(
+ `[${LANGUAGE_CLIENT_ID}] waiting ${wait}ms for previous ZLS to exit`,
+ );
await new Promise((resolve) => setTimeout(resolve, wait));
if (generation !== this.restartGeneration) {
return;
@@ -1018,7 +1056,7 @@ class ZigLanguageServer {
this.warnMissingTool(
"zls",
localizeText(
- "warning.zls.not_found",
+ "warning.zls.not-found",
"ZLS was not found. Install it or set a ZLS executable path in Zig extension settings.",
),
);
@@ -1078,7 +1116,9 @@ class ZigLanguageServer {
}
});
- console.log(`[${LANGUAGE_CLIENT_ID}] starting client: zls=${zlsPath} zig=${zigPath || "not found"}`);
+ console.log(
+ `[${LANGUAGE_CLIENT_ID}] starting client: zls=${zlsPath} zig=${zigPath || "not found"}`,
+ );
try {
client.start();
this.client = client;
@@ -1176,7 +1216,7 @@ class ZigTaskAssistant {
constructor() {
this.disposable = nova.assistants.registerTaskAssistant(this, {
identifier: TASK_ASSISTANT_ID,
- name: localizeText("name.extension", "Zig"),
+ name: localize("autotasks.title"),
});
}
@@ -1190,9 +1230,8 @@ class ZigTaskAssistant {
provideTasks() {
const tasks = [];
- const currentFile = new Task(
- localizeText("task.current_file.name", "Current Zig File"),
- );
+ const currentFile = new Task(localize("autotasks.current-file.name"));
+ currentFile.image = "zig-script";
currentFile.setAction(
Task.Run,
new TaskResolvableAction({
@@ -1219,11 +1258,8 @@ class ZigTaskAssistant {
const steps = stepCache.getOrFetch(workspacePath);
if (steps && steps.length > 0) {
for (const step of steps) {
- const task = new Task(
- localizeText("task.build_step.name", "Zig Build: {step}", {
- step,
- }),
- );
+ const task = new Task(localize("autotasks.buildstep.name", { step }));
+ task.image = "zig-hex";
task.setAction(
Task.Run,
new TaskResolvableAction({
@@ -1245,7 +1281,9 @@ class ZigTaskAssistant {
const type = context.data && context.data.type;
const config = context.config;
const cwd = getTaskCwd(config);
- console.log(`[${TASK_ASSISTANT_ID}] resolveTaskAction: type=${type} cwd=${cwd}`);
+ console.log(
+ `[${TASK_ASSISTANT_ID}] resolveTaskAction: type=${type} cwd=${cwd}`,
+ );
if (type === "clean") {
return this.resolveCleanAction(cwd);
@@ -1475,7 +1513,7 @@ class ZigTaskAssistant {
if (!lldbDapPath) {
nova.workspace.showWarningMessage(
localizeText(
- "warning.lldb_dap.not_found",
+ "warning.lldb_dap.not-found",
"lldb-dap was not found. Install Xcode Command Line Tools or set an LLDB DAP executable path in Zig extension settings.",
),
);