-
Notifications
You must be signed in to change notification settings - Fork 234
add support for rv version manager #3878
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
matheuscumpian
wants to merge
1
commit into
Shopify:main
Choose a base branch
from
matheuscumpian:add-rv
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.
+201
−1
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
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
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,46 @@ | ||
| import * as vscode from "vscode"; | ||
|
|
||
| import { VersionManager, ActivationResult } from "./versionManager"; | ||
|
|
||
| // Manage your Ruby environment with rv | ||
| // | ||
| // Learn more: https://github.com/spinel-coop/rv | ||
| export class Rv extends VersionManager { | ||
| async activate(): Promise<ActivationResult> { | ||
| const rvExec = await this.findRv(); | ||
| const parsedResult = await this.runEnvActivationScript(`${rvExec} ruby run --`); | ||
|
|
||
| return { | ||
| env: { ...process.env, ...parsedResult.env }, | ||
| yjit: parsedResult.yjit, | ||
| version: parsedResult.version, | ||
| gemPath: parsedResult.gemPath, | ||
| }; | ||
| } | ||
|
|
||
| private async findRv(): Promise<string> { | ||
| const config = vscode.workspace.getConfiguration("rubyLsp"); | ||
| const configuredRvPath = config.get<string | undefined>("rubyVersionManager.rvExecutablePath"); | ||
|
|
||
| if (configuredRvPath) { | ||
| return this.ensureRvExistsAt(configuredRvPath); | ||
| } else { | ||
| const possiblePaths = [ | ||
| vscode.Uri.file("/home/linuxbrew/.linuxbrew/bin"), | ||
| vscode.Uri.file("/usr/local/bin"), | ||
| vscode.Uri.file("/opt/homebrew/bin"), | ||
| vscode.Uri.joinPath(vscode.Uri.file("/"), "usr", "bin"), | ||
| ]; | ||
| return this.findExec(possiblePaths, "rv"); | ||
| } | ||
| } | ||
|
|
||
| private async ensureRvExistsAt(path: string): Promise<string> { | ||
| try { | ||
| await vscode.workspace.fs.stat(vscode.Uri.file(path)); | ||
| return path; | ||
| } catch (_error: any) { | ||
| throw new Error(`The Ruby LSP version manager is configured to be rv, but ${path} does not exist`); | ||
| } | ||
| } | ||
| } | ||
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,129 @@ | ||
| import assert from "assert"; | ||
| import path from "path"; | ||
| import os from "os"; | ||
| import fs from "fs"; | ||
|
|
||
| import * as vscode from "vscode"; | ||
| import sinon from "sinon"; | ||
| import { afterEach, beforeEach } from "mocha"; | ||
|
|
||
| import { Rv } from "../../../ruby/rv"; | ||
| import { WorkspaceChannel } from "../../../workspaceChannel"; | ||
| import * as common from "../../../common"; | ||
| import { ACTIVATION_SEPARATOR, FIELD_SEPARATOR, VALUE_SEPARATOR } from "../../../ruby/versionManager"; | ||
| import { createContext, FakeContext } from "../helpers"; | ||
|
|
||
| suite("Rv", () => { | ||
| if (os.platform() === "win32") { | ||
| // eslint-disable-next-line no-console | ||
| console.log("Skipping Rv tests on Windows"); | ||
| return; | ||
| } | ||
|
|
||
| let activationPath: vscode.Uri; | ||
| let sandbox: sinon.SinonSandbox; | ||
| let context: FakeContext; | ||
|
|
||
| beforeEach(() => { | ||
| sandbox = sinon.createSandbox(); | ||
| context = createContext(); | ||
| activationPath = vscode.Uri.joinPath(context.extensionUri, "activation.rb"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sandbox.restore(); | ||
| context.dispose(); | ||
| }); | ||
|
|
||
| test("Activates with auto-detected version", async () => { | ||
| const workspacePath = process.env.PWD!; | ||
| const workspaceFolder = { | ||
| uri: vscode.Uri.from({ scheme: "file", path: workspacePath }), | ||
| name: path.basename(workspacePath), | ||
| index: 0, | ||
| }; | ||
| const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL); | ||
|
|
||
| const rv = new Rv(workspaceFolder, outputChannel, context, async () => {}); | ||
|
|
||
| const envStub = ["3.4.8", "/path/to/gems", "true", `ANY${VALUE_SEPARATOR}true`].join(FIELD_SEPARATOR); | ||
|
|
||
| const execStub = sandbox.stub(common, "asyncExec").resolves({ | ||
| stdout: "", | ||
| stderr: `${ACTIVATION_SEPARATOR}${envStub}${ACTIVATION_SEPARATOR}`, | ||
| }); | ||
|
|
||
| // Stub findRv to return the executable path | ||
| sandbox.stub(rv, "findRv" as any).resolves("rv"); | ||
|
|
||
| const { env, version, yjit } = await rv.activate(); | ||
|
|
||
| assert.ok( | ||
| execStub.calledOnceWithExactly(`rv ruby run -- -EUTF-8:UTF-8 '${activationPath.fsPath}'`, { | ||
| cwd: workspacePath, | ||
| shell: vscode.env.shell, | ||
|
|
||
| env: process.env, | ||
| encoding: "utf-8", | ||
| }), | ||
| ); | ||
|
|
||
| assert.strictEqual(version, "3.4.8"); | ||
| assert.strictEqual(yjit, true); | ||
| assert.strictEqual(env.ANY, "true"); | ||
| }); | ||
|
|
||
| test("Allows configuring where rv is installed", async () => { | ||
| const workspacePath = fs.mkdtempSync(path.join(os.tmpdir(), "ruby-lsp-test-")); | ||
| const workspaceFolder = { | ||
| uri: vscode.Uri.from({ scheme: "file", path: workspacePath }), | ||
| name: path.basename(workspacePath), | ||
| index: 0, | ||
| }; | ||
| const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL); | ||
|
|
||
| const rv = new Rv(workspaceFolder, outputChannel, context, async () => {}); | ||
|
|
||
| const envStub = ["3.4.8", "/path/to/gems", "true", `ANY${VALUE_SEPARATOR}true`].join(FIELD_SEPARATOR); | ||
|
|
||
| const execStub = sandbox.stub(common, "asyncExec").resolves({ | ||
| stdout: "", | ||
| stderr: `${ACTIVATION_SEPARATOR}${envStub}${ACTIVATION_SEPARATOR}`, | ||
| }); | ||
|
|
||
| const rvPath = path.join(workspacePath, "rv"); | ||
| fs.writeFileSync(rvPath, "fakeRvBinary"); | ||
|
|
||
| // Stub findRv to return the configured executable path | ||
| sandbox.stub(rv, "findRv" as any).resolves(rvPath); | ||
|
|
||
| const configStub = sinon.stub(vscode.workspace, "getConfiguration").returns({ | ||
| get: (name: string) => { | ||
| if (name === "rubyVersionManager.rvExecutablePath") { | ||
| return rvPath; | ||
| } | ||
| return ""; | ||
| }, | ||
| } as any); | ||
|
|
||
| const { env, version, yjit } = await rv.activate(); | ||
|
|
||
| assert.ok( | ||
| execStub.calledOnceWithExactly(`${rvPath} ruby run -- -EUTF-8:UTF-8 '${activationPath.fsPath}'`, { | ||
| cwd: workspacePath, | ||
| shell: vscode.env.shell, | ||
|
|
||
| env: process.env, | ||
| encoding: "utf-8", | ||
| }), | ||
| ); | ||
|
|
||
| assert.strictEqual(version, "3.4.8"); | ||
| assert.strictEqual(yjit, true); | ||
| assert.deepStrictEqual(env.ANY, "true"); | ||
|
|
||
| execStub.restore(); | ||
| configStub.restore(); | ||
| fs.rmSync(workspacePath, { recursive: true, force: true }); | ||
| }); | ||
| }); |
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.
Should we be using
joinPathlike we are doing in all other places we build paths?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 noticed you've created a new PR (#3894) that refactors a lot of the version managers code. Should I wait for that to merge and then align this PR with the new pattern?
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.
Let's finish this one and then I rebase mine.