From 1399ed29bc5e377644e16450b8a79fd47acee92c Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 15 Jan 2025 10:20:39 -0500 Subject: [PATCH] Use local executables when working on the Ruby LSP --- vscode/src/ruby.ts | 11 +++++++++ vscode/src/test/suite/ruby.test.ts | 36 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/vscode/src/ruby.ts b/vscode/src/ruby.ts index 5270bc9a3..10d49d99a 100644 --- a/vscode/src/ruby.ts +++ b/vscode/src/ruby.ts @@ -186,6 +186,17 @@ 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") { + const localExecutablesUri = vscode.Uri.joinPath( + this.workspaceFolder.uri, + "exe", + ); + + this._env.PATH = `${localExecutablesUri.fsPath}${path.delimiter}${this._env.PATH}`; + } } } diff --git a/vscode/src/test/suite/ruby.test.ts b/vscode/src/test/suite/ruby.test.ts index e1c4abb34..0d6e6d365 100644 --- a/vscode/src/test/suite/ruby.test.ts +++ b/vscode/src/test/suite/ruby.test.ts @@ -167,4 +167,40 @@ 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 () => { + 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); });