Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge composed bundle environment into Ruby object #2881

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
vinistock marked this conversation as resolved.
Show resolved Hide resolved

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" });
});
});
Loading