-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add settings for mise bin path and mise profile
- Loading branch information
Showing
6 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as fs from "node:fs/promises"; | ||
import * as os from "node:os"; | ||
import * as path from "node:path"; | ||
import * as vscode from "vscode"; | ||
import { logger } from "./logger"; | ||
import { execAsync } from "./shell"; | ||
|
||
export async function resolveMisePath(): Promise<string> { | ||
const config = vscode.workspace.getConfiguration("mise"); | ||
const configuredPath = config.get<string>("binPath")?.trim(); | ||
|
||
if (configuredPath) { | ||
if (await isValidBinary(configuredPath)) { | ||
return configuredPath; | ||
} | ||
logger.warn( | ||
`Configured mise path ${configuredPath} is invalid. Trying to resolve another path...`, | ||
); | ||
} | ||
|
||
// Check if mise is in the PATH | ||
const { stdout } = await execAsync("which mise").catch(() => ({ | ||
stdout: "", | ||
})); | ||
if (stdout) { | ||
return stdout.trim(); | ||
} | ||
|
||
// Check common installation locations | ||
const homedir = os.homedir(); | ||
const commonPaths = [ | ||
path.join(homedir, ".local", "bin", "mise"), // ~/.local/bin/mise | ||
"/usr/local/bin/mise", // Homebrew | ||
"/opt/homebrew/bin/mise", // Homebrew | ||
path.join(homedir, "bin", "mise"), // ~/bin/mise | ||
]; | ||
|
||
const allPaths = [...commonPaths]; | ||
|
||
for (const binPath of allPaths) { | ||
if (await isValidBinary(binPath)) { | ||
return binPath; | ||
} | ||
} | ||
|
||
throw new Error("Could not find mise binary in any standard location"); | ||
} | ||
|
||
export async function isValidBinary(filepath: string): Promise<boolean> { | ||
try { | ||
const stats = await fs.stat(filepath); | ||
const isExecutable = (stats.mode & fs.constants.X_OK) !== 0; | ||
if (stats.isFile() && isExecutable) { | ||
const { stdout } = await execAsync(`"${filepath}" --help`); | ||
return stdout.toLowerCase().includes("mise"); | ||
} | ||
} catch (error) { | ||
logger.error( | ||
`Path ${filepath} is not a valid mise binary:`, | ||
error as Error, | ||
); | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as vscode from "vscode"; | ||
|
||
type Created = { type?: "info" | "error"; settingsKey?: string }; | ||
|
||
export async function showSettingsNotification( | ||
message: string, | ||
{ type = "info", settingsKey = "mise." }: Created = {}, | ||
) { | ||
const notifyFn = | ||
type === "error" | ||
? vscode.window.showErrorMessage | ||
: vscode.window.showInformationMessage; | ||
|
||
const action = "Configure"; | ||
const selection = await notifyFn(message, action); | ||
if (selection === action) { | ||
vscode.commands.executeCommand( | ||
"workbench.action.openSettings", | ||
settingsKey, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { exec } from "node:child_process"; | ||
import { promisify } from "node:util"; | ||
|
||
export const execAsync = promisify(exec); |