diff --git a/vscode/src/client.ts b/vscode/src/client.ts index 594ce633c..114b385f2 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -389,6 +389,10 @@ export default class Client extends LanguageClient implements ClientInterface { this.degraded = this.initializeResult?.degraded_mode; } + if (this.initializeResult?.bundle_env) { + this.ruby.mergeComposedEnvironment(this.initializeResult.bundle_env); + } + await this.fetchAddons(); } diff --git a/vscode/src/debugger.ts b/vscode/src/debugger.ts index 12e7547dc..4b39681cf 100644 --- a/vscode/src/debugger.ts +++ b/vscode/src/debugger.ts @@ -127,6 +127,12 @@ export class Debugger name: workspace.workspaceFolder.name, }; + // In newer versions of the server, the composed bundle environment is merged directly into the Ruby object and no + // adjustments have to be made here + if (debugConfiguration.env.BUNDLE_GEMFILE) { + return debugConfiguration; + } + const customBundleUri = vscode.Uri.joinPath(workspaceUri, ".ruby-lsp"); return vscode.workspace.fs.readDirectory(customBundleUri).then( diff --git a/vscode/src/ruby.ts b/vscode/src/ruby.ts index fad69bb63..bf0d6c8e7 100644 --- a/vscode/src/ruby.ts +++ b/vscode/src/ruby.ts @@ -218,6 +218,10 @@ export class Ruby implements RubyInterface { return this.activateRuby(); } + mergeComposedEnvironment(env: Record) { + this._env = { ...this._env, ...env }; + } + private async runActivation(manager: VersionManager) { const { env, version, yjit, gemPath } = await manager.activate(); const [major, minor, _patch] = version.split(".").map(Number); diff --git a/vscode/src/test/suite/ruby.test.ts b/vscode/src/test/suite/ruby.test.ts index b3832b439..e1c4abb34 100644 --- a/vscode/src/test/suite/ruby.test.ts +++ b/vscode/src/test/suite/ruby.test.ts @@ -150,4 +150,21 @@ suite("Ruby environment activation", () => { "/opt/rubies/3.3.5/lib/ruby/gems/3.3.0", ]); }); + + test("mergeComposedEnv merges environment variables", () => { + const ruby = new Ruby( + context, + workspaceFolder, + outputChannel, + FAKE_TELEMETRY, + ); + + assert.deepStrictEqual(ruby.env, {}); + + ruby.mergeComposedEnvironment({ + BUNDLE_GEMFILE: ".ruby-lsp/Gemfile", + }); + + assert.deepStrictEqual(ruby.env, { BUNDLE_GEMFILE: ".ruby-lsp/Gemfile" }); + }); });