Skip to content

Commit

Permalink
Merge composed bundle environment into Ruby object
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Nov 20, 2024
1 parent a738d5b commit 2b3512d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions vscode/src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export class Ruby implements RubyInterface {
return this.activateRuby();
}

mergeComposedEnvironment(env: Record<string, string>) {
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);
Expand Down
17 changes: 17 additions & 0 deletions vscode/src/test/suite/ruby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
});
});

0 comments on commit 2b3512d

Please sign in to comment.