Skip to content

Commit dd3968c

Browse files
authored
Merge composed bundle environment into Ruby object (#2881)
### Motivation Closes #1767, closes #1785 Merge the composed bundle environment into the workspace's Ruby object. The language server sets up the composed bundle environment, returns it, and then we merge that into the Ruby object to ensure that any other parts of the extension are using the exact same environment. This fixes a few issues people have been experiencing with the debug client. ### Implementation Started merging the composed environment into the Ruby object and then started relying on that for the debug client. ### Automated Tests Added some tests. I will follow up with another PR that creates an integration test for a scenario that currently fails.
1 parent 51e76fa commit dd3968c

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

vscode/src/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ export default class Client extends LanguageClient implements ClientInterface {
389389
this.degraded = this.initializeResult?.degraded_mode;
390390
}
391391

392+
if (this.initializeResult?.bundle_env) {
393+
this.ruby.mergeComposedEnvironment(this.initializeResult.bundle_env);
394+
}
395+
392396
await this.fetchAddons();
393397
}
394398

vscode/src/debugger.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ export class Debugger
127127
name: workspace.workspaceFolder.name,
128128
};
129129

130+
// In newer versions of the server, the composed bundle environment is merged directly into the Ruby object and no
131+
// adjustments have to be made here
132+
if (debugConfiguration.env.BUNDLE_GEMFILE) {
133+
return debugConfiguration;
134+
}
135+
130136
const customBundleUri = vscode.Uri.joinPath(workspaceUri, ".ruby-lsp");
131137

132138
return vscode.workspace.fs.readDirectory(customBundleUri).then(

vscode/src/ruby.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ export class Ruby implements RubyInterface {
218218
return this.activateRuby();
219219
}
220220

221+
mergeComposedEnvironment(env: Record<string, string>) {
222+
this._env = { ...this._env, ...env };
223+
}
224+
221225
private async runActivation(manager: VersionManager) {
222226
const { env, version, yjit, gemPath } = await manager.activate();
223227
const [major, minor, _patch] = version.split(".").map(Number);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,21 @@ suite("Ruby environment activation", () => {
150150
"/opt/rubies/3.3.5/lib/ruby/gems/3.3.0",
151151
]);
152152
});
153+
154+
test("mergeComposedEnv merges environment variables", () => {
155+
const ruby = new Ruby(
156+
context,
157+
workspaceFolder,
158+
outputChannel,
159+
FAKE_TELEMETRY,
160+
);
161+
162+
assert.deepStrictEqual(ruby.env, {});
163+
164+
ruby.mergeComposedEnvironment({
165+
BUNDLE_GEMFILE: ".ruby-lsp/Gemfile",
166+
});
167+
168+
assert.deepStrictEqual(ruby.env, { BUNDLE_GEMFILE: ".ruby-lsp/Gemfile" });
169+
});
153170
});

0 commit comments

Comments
 (0)