Skip to content

Commit

Permalink
Mise plugin checks multiple install locations for mise binary
Browse files Browse the repository at this point in the history
The installation path of Mise differs through the installation method
chosen. Using Homebrew results in a path under `/opt/homebrew` where as
the installation method from the Mise website is typically under
`$HOME/.local`.
  • Loading branch information
adam12 committed Dec 12, 2024
1 parent 896617a commit 3314997
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions vscode/src/ruby/mise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,52 @@ export class Mise extends VersionManager {
const misePath = config.get<string | undefined>(
"rubyVersionManager.miseExecutablePath",
);
const miseUri = misePath
? vscode.Uri.file(misePath)
: vscode.Uri.joinPath(
vscode.Uri.file(os.homedir()),
".local",
"bin",
"mise",

if (misePath) {
const configuredPath = vscode.Uri.file(misePath);

try {
await vscode.workspace.fs.stat(configuredPath);
return configuredPath;
} catch (error: any) {
throw new Error(
`Mise executable configured as ${configuredPath}, but that file doesn't exist`,
);
}
}

// Possible mise installation paths
//
// 1. Installation from curl | sh (per mise.jdx.dev Getting Started)
// 2. Homebrew M series
const possiblePaths = [
vscode.Uri.joinPath(
vscode.Uri.file(os.homedir()),
".local",
"bin",
"mise",
),
vscode.Uri.joinPath(
vscode.Uri.file("/"),
"opt",
"homebrew",
"bin",
"mise",
),
];

try {
await vscode.workspace.fs.stat(miseUri);
return miseUri;
} catch (error: any) {
// Couldn't find it
for (const possiblePath of possiblePaths) {
try {
await vscode.workspace.fs.stat(possiblePath);
return possiblePath;
} catch (error: any) {
// Continue looking
}
}

throw new Error(
`The Ruby LSP version manager is configured to be Mise, but ${miseUri.fsPath} does not exist`,
`The Ruby LSP version manager is configured to be Mise, but could not find Mise installation. Searched in ` +
`${possiblePaths.join(", ")}`,
);
}
}

0 comments on commit 3314997

Please sign in to comment.