Skip to content

Commit 7fb9adf

Browse files
authored
Use local executables when working on the Ruby LSP (#3065)
### Motivation I was trying to make some more improvements to our launcher and I realized we were missing something we should have probably done about 2 years ago. When working on the LSP itself, we don't use the local version of the launcher. We use the local version of the server, but only after the bundle has been composed. Composing the bundle uses whatever latest version is globally installed. This is detrimental to us catching bugs in the launch process before releasing it to users. We need to change that. ### Implementation To ensure that the local version of the executable is always chosen when working on the LSP, I started mutating the `PATH` to include the `exe` directory. That way, whenever `ruby-lsp` is invoked, the first thing that will be found is the local executable. ### Automated Tests Added a test to make sure the `PATH` is being mutated.
1 parent 77337ef commit 7fb9adf

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

vscode/src/ruby.ts

+14
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ export class Ruby implements RubyInterface {
186186
if (!this.error) {
187187
this.fetchRubyVersionInfo();
188188
await this.setupBundlePath();
189+
190+
// When working on the Ruby LSP itself, we want to use the local version of our executables rather than the ones
191+
// globally installed. That allows us to catch mistakes made in the launch process before they are released
192+
if (
193+
path.basename(this.workspaceFolder.uri.fsPath) === "ruby-lsp" &&
194+
os.platform() !== "win32"
195+
) {
196+
const localExecutablesUri = vscode.Uri.joinPath(
197+
this.workspaceFolder.uri,
198+
"exe",
199+
);
200+
201+
this._env.PATH = `${localExecutablesUri.fsPath}${path.delimiter}${this._env.PATH}`;
202+
}
189203
}
190204
}
191205

vscode/src/test/suite/ruby.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-process-env */
22
import * as assert from "assert";
33
import * as path from "path";
4+
import os from "os";
45

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

168169
assert.deepStrictEqual(ruby.env, { BUNDLE_GEMFILE: ".ruby-lsp/Gemfile" });
169170
});
171+
172+
test("Adds local exe directory to PATH when working on the Ruby LSP itself", async () => {
173+
if (os.platform() === "win32") {
174+
// We don't mutate the path on Windows
175+
return;
176+
}
177+
178+
const manager = process.env.CI
179+
? ManagerIdentifier.None
180+
: ManagerIdentifier.Chruby;
181+
182+
const configStub = sinon
183+
.stub(vscode.workspace, "getConfiguration")
184+
.returns({
185+
get: (name: string) => {
186+
if (name === "rubyVersionManager") {
187+
return { identifier: manager };
188+
} else if (name === "bundleGemfile") {
189+
return "";
190+
}
191+
192+
return undefined;
193+
},
194+
} as unknown as vscode.WorkspaceConfiguration);
195+
196+
const workspacePath = path.dirname(
197+
path.dirname(path.dirname(path.dirname(__dirname))),
198+
);
199+
const lspFolder: vscode.WorkspaceFolder = {
200+
uri: vscode.Uri.file(workspacePath),
201+
name: path.basename(workspacePath),
202+
index: 0,
203+
};
204+
const ruby = new Ruby(context, lspFolder, outputChannel, FAKE_TELEMETRY);
205+
await ruby.activateRuby();
206+
207+
const firstEntry = ruby.env.PATH!.split(path.delimiter)[0];
208+
assert.match(firstEntry, /ruby-lsp\/exe$/);
209+
210+
configStub.restore();
211+
}).timeout(10000);
170212
});

0 commit comments

Comments
 (0)