Skip to content

Commit

Permalink
Use local executables when working on the Ruby LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 15, 2025
1 parent 77337ef commit 21a81e7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ export class Ruby implements RubyInterface {
if (!this.error) {
this.fetchRubyVersionInfo();
await this.setupBundlePath();

// When working on the Ruby LSP itself, we want to use the local version of our executables rather than the ones
// globally installed. That allows us to catch mistakes made in the launch process before they are released
if (
path.basename(this.workspaceFolder.uri.fsPath) === "ruby-lsp" &&
os.platform() !== "win32"
) {
const localExecutablesUri = vscode.Uri.joinPath(
this.workspaceFolder.uri,
"exe",
);

this._env.PATH = `${localExecutablesUri.fsPath}${path.delimiter}${this._env.PATH}`;
}
}
}

Expand Down
42 changes: 42 additions & 0 deletions vscode/src/test/suite/ruby.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-process-env */
import * as assert from "assert";
import * as path from "path";
import os from "os";

import * as vscode from "vscode";
import sinon from "sinon";
Expand Down Expand Up @@ -167,4 +168,45 @@ suite("Ruby environment activation", () => {

assert.deepStrictEqual(ruby.env, { BUNDLE_GEMFILE: ".ruby-lsp/Gemfile" });
});

test("Adds local exe directory to PATH when working on the Ruby LSP itself", async () => {
if (os.platform() === "win32") {
// We don't mutate the path on Windows
return;
}

const manager = process.env.CI
? ManagerIdentifier.None
: ManagerIdentifier.Chruby;

const configStub = sinon
.stub(vscode.workspace, "getConfiguration")
.returns({
get: (name: string) => {
if (name === "rubyVersionManager") {
return { identifier: manager };
} else if (name === "bundleGemfile") {
return "";
}

return undefined;
},
} as unknown as vscode.WorkspaceConfiguration);

const workspacePath = path.dirname(
path.dirname(path.dirname(path.dirname(__dirname))),
);
const lspFolder: vscode.WorkspaceFolder = {
uri: vscode.Uri.file(workspacePath),
name: path.basename(workspacePath),
index: 0,
};
const ruby = new Ruby(context, lspFolder, outputChannel, FAKE_TELEMETRY);
await ruby.activateRuby();

const firstEntry = ruby.env.PATH!.split(path.delimiter)[0];
assert.match(firstEntry, /ruby-lsp\/exe$/);

configStub.restore();
}).timeout(10000);
});

0 comments on commit 21a81e7

Please sign in to comment.