-
Notifications
You must be signed in to change notification settings - Fork 1
Extract version managers from ruby-lsp #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ono-max
wants to merge
1
commit into
Shopify:main
Choose a base branch
from
ono-max:extract-version-managers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,15 @@ | ||
| import { exec } from "child_process"; | ||
| import { promisify } from "util"; | ||
| import { window } from "vscode"; | ||
|
|
||
| export interface RubyInterface { | ||
| error: boolean; | ||
| versionManager: { identifier: string }; | ||
| rubyVersion?: string; | ||
| } | ||
|
|
||
| export const asyncExec = promisify(exec); | ||
| export const RUBY_ENVIRONMENTS = "Ruby Environments"; | ||
| export const LOG_CHANNEL = window.createOutputChannel(RUBY_ENVIRONMENTS, { | ||
| log: true, | ||
| }); | ||
This file contains hidden or 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,88 @@ | ||
| import os from "os"; | ||
| import path from "path"; | ||
|
|
||
| import * as vscode from "vscode"; | ||
|
|
||
| import { VersionManager, ActivationResult } from "./versionManager"; | ||
|
|
||
| // A tool to manage multiple runtime versions with a single CLI tool | ||
| // | ||
| // Learn more: https://github.com/asdf-vm/asdf | ||
| export class Asdf extends VersionManager { | ||
| async activate(): Promise<ActivationResult> { | ||
| // These directories are where we can find the ASDF executable for v0.16 and above | ||
| const possibleExecutablePaths = [ | ||
| vscode.Uri.joinPath(vscode.Uri.file("/"), "opt", "homebrew", "bin"), | ||
| vscode.Uri.joinPath(vscode.Uri.file("/"), "usr", "local", "bin"), | ||
| ]; | ||
|
|
||
| // Prefer the path configured by the user, then the ASDF scripts for versions below v0.16 and finally the | ||
| // executables for v0.16 and above | ||
| const asdfPath = | ||
| (await this.getConfiguredAsdfPath()) ?? | ||
| (await this.findAsdfInstallation()) ?? | ||
| (await this.findExec(possibleExecutablePaths, "asdf")); | ||
|
|
||
| // If there's no extension name, then we are using the ASDF executable directly. If there is an extension, then it's | ||
| // a shell script and we have to source it first | ||
| const baseCommand = path.extname(asdfPath) === "" ? asdfPath : `. ${asdfPath} && asdf`; | ||
|
|
||
| const parsedResult = await this.runEnvActivationScript(`${baseCommand} exec ruby`); | ||
|
|
||
| return { | ||
| env: { ...process.env, ...parsedResult.env }, | ||
| yjit: parsedResult.yjit, | ||
| version: parsedResult.version, | ||
| gemPath: parsedResult.gemPath, | ||
| }; | ||
| } | ||
|
|
||
| // Only public for testing. Finds the ASDF installation URI based on what's advertised in the ASDF documentation | ||
| async findAsdfInstallation(): Promise<string | undefined> { | ||
| const scriptName = path.basename(vscode.env.shell) === "fish" ? "asdf.fish" : "asdf.sh"; | ||
|
|
||
| // Possible ASDF installation paths as described in https://asdf-vm.com/guide/getting-started.html#_3-install-asdf. | ||
| // In order, the methods of installation are: | ||
| // 1. Git | ||
| // 2. Pacman | ||
| // 3. Homebrew M series | ||
| // 4. Homebrew Intel series | ||
| const possiblePaths = [ | ||
| vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".asdf", scriptName), | ||
| vscode.Uri.joinPath(vscode.Uri.file("/"), "opt", "asdf-vm", scriptName), | ||
| vscode.Uri.joinPath(vscode.Uri.file("/"), "opt", "homebrew", "opt", "asdf", "libexec", scriptName), | ||
| vscode.Uri.joinPath(vscode.Uri.file("/"), "usr", "local", "opt", "asdf", "libexec", scriptName), | ||
| ]; | ||
|
|
||
| for (const possiblePath of possiblePaths) { | ||
| try { | ||
| await vscode.workspace.fs.stat(possiblePath); | ||
| return possiblePath.fsPath; | ||
| } catch (_error: any) { | ||
| // Continue looking | ||
| } | ||
| } | ||
|
|
||
| this.outputChannel.info(`Could not find installation for ASDF < v0.16. Searched in ${possiblePaths.join(", ")}`); | ||
| return undefined; | ||
| } | ||
|
|
||
| private async getConfiguredAsdfPath(): Promise<string | undefined> { | ||
| const config = vscode.workspace.getConfiguration("rubyLsp"); | ||
| const asdfPath = config.get<string | undefined>("rubyVersionManager.asdfExecutablePath"); | ||
|
|
||
| if (!asdfPath) { | ||
| return; | ||
| } | ||
|
|
||
| const configuredPath = vscode.Uri.file(asdfPath); | ||
|
|
||
| try { | ||
| await vscode.workspace.fs.stat(configuredPath); | ||
| this.outputChannel.info(`Using configured ASDF executable path: ${asdfPath}`); | ||
| return configuredPath.fsPath; | ||
| } catch (_error: any) { | ||
| throw new Error(`ASDF executable configured as ${configuredPath.fsPath}, but that file doesn't exist`); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this name from "Ruby LSP" to "Ruby Environments"