Skip to content

Commit 21a81e7

Browse files
committed
Use local executables when working on the Ruby LSP
1 parent 77337ef commit 21a81e7

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)