From 3314997f1b1b7c7eb256d14b33ce5e1fdc4ce896 Mon Sep 17 00:00:00 2001 From: Adam Daniels Date: Tue, 12 Nov 2024 14:09:45 -0500 Subject: [PATCH] Mise plugin checks 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`. --- vscode/src/ruby/mise.ts | 54 +++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/vscode/src/ruby/mise.ts b/vscode/src/ruby/mise.ts index 3695b2677a..8c1fb3cb8e 100644 --- a/vscode/src/ruby/mise.ts +++ b/vscode/src/ruby/mise.ts @@ -30,24 +30,52 @@ export class Mise extends VersionManager { const misePath = config.get( "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(", ")}`, ); } }