Skip to content

Commit

Permalink
VSCode extension checks multiple install locations for mise binary (#…
Browse files Browse the repository at this point in the history
…2943)

Support multiple install locations for `mise` binary

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 authored Dec 13, 2024
1 parent d244ad2 commit 2e6d8d4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
30 changes: 19 additions & 11 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ import { None } from "./ruby/none";
import { Custom } from "./ruby/custom";
import { Asdf } from "./ruby/asdf";

async function detectMise() {
const possiblePaths = [
vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".local", "bin", "mise"),
vscode.Uri.joinPath(vscode.Uri.file("/"), "opt", "homebrew", "bin", "mise"),
];

for (const possiblePath of possiblePaths) {
try {
await vscode.workspace.fs.stat(possiblePath);
return true;
} catch (error: any) {
// Continue looking
}
}

return false;
}

export enum ManagerIdentifier {
Asdf = "asdf",
Auto = "auto",
Expand Down Expand Up @@ -408,19 +426,9 @@ export class Ruby implements RubyInterface {
}
}

try {
await vscode.workspace.fs.stat(
vscode.Uri.joinPath(
vscode.Uri.file(os.homedir()),
".local",
"bin",
"mise",
),
);
if (await detectMise()) {
this.versionManager = ManagerIdentifier.Mise;
return;
} catch (error: any) {
// If the Mise binary doesn't exist, then continue checking
}

if (os.platform() === "win32") {
Expand Down
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 2e6d8d4

Please sign in to comment.