Skip to content

Commit 25f00de

Browse files
committed
Merge composed bundle environment into Ruby object
1 parent feaab3e commit 25f00de

File tree

5 files changed

+26
-70
lines changed

5 files changed

+26
-70
lines changed

vscode/src/client.ts

+4
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

+1-22
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,7 @@ export class Debugger
127127
name: workspace.workspaceFolder.name,
128128
};
129129

130-
const customBundleUri = vscode.Uri.joinPath(workspaceUri, ".ruby-lsp");
131-
132-
return vscode.workspace.fs.readDirectory(customBundleUri).then(
133-
(value) => {
134-
if (value.some((entry) => entry[0] === "Gemfile")) {
135-
debugConfiguration.env.BUNDLE_GEMFILE = vscode.Uri.joinPath(
136-
customBundleUri,
137-
"Gemfile",
138-
).fsPath;
139-
} else if (value.some((entry) => entry[0] === "gems.rb")) {
140-
debugConfiguration.env.BUNDLE_GEMFILE = vscode.Uri.joinPath(
141-
customBundleUri,
142-
"gems.rb",
143-
).fsPath;
144-
}
145-
146-
return debugConfiguration;
147-
},
148-
() => {
149-
return debugConfiguration;
150-
},
151-
);
130+
return debugConfiguration;
152131
}
153132

154133
// If the extension is deactivating, we need to ensure the debug process is terminated or else it may continue running

vscode/src/ruby.ts

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ export class Ruby implements RubyInterface {
208208
return this.activateRuby();
209209
}
210210

211+
mergeComposedEnvironment(env: Record<string, string>) {
212+
this._env = { ...this._env, ...env };
213+
}
214+
211215
private async runActivation(manager: VersionManager) {
212216
const { env, version, yjit, gemPath } = await manager.activate();
213217
const [major, minor, _patch] = version.split(".").map(Number);

vscode/src/test/suite/debugger.test.ts

-48
Original file line numberDiff line numberDiff line change
@@ -112,54 +112,6 @@ suite("Debugger", () => {
112112
context.subscriptions.forEach((subscription) => subscription.dispose());
113113
});
114114

115-
test("Resolve configuration injects BUNDLE_GEMFILE if there's a custom bundle", async () => {
116-
const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(), "ruby-lsp-test-"));
117-
fs.mkdirSync(path.join(tmpPath, ".ruby-lsp"));
118-
fs.writeFileSync(path.join(tmpPath, ".ruby-lsp", "Gemfile"), "hello!");
119-
120-
const context = { subscriptions: [] } as unknown as vscode.ExtensionContext;
121-
const ruby = { env: { bogus: "hello!" } } as unknown as Ruby;
122-
const workspaceFolder = {
123-
name: "fake",
124-
uri: vscode.Uri.file(tmpPath),
125-
index: 0,
126-
};
127-
const debug = new Debugger(context, () => {
128-
return {
129-
ruby,
130-
workspaceFolder,
131-
} as Workspace;
132-
});
133-
const configs: any = await debug.resolveDebugConfiguration!(
134-
workspaceFolder,
135-
{
136-
type: "ruby_lsp",
137-
name: "Debug",
138-
request: "launch",
139-
// eslint-disable-next-line no-template-curly-in-string
140-
program: "ruby ${file}",
141-
env: { parallel: "1" },
142-
},
143-
);
144-
145-
assert.deepEqual(
146-
{
147-
parallel: "1",
148-
...ruby.env,
149-
BUNDLE_GEMFILE: vscode.Uri.joinPath(
150-
vscode.Uri.file(tmpPath),
151-
".ruby-lsp",
152-
"Gemfile",
153-
).fsPath,
154-
},
155-
configs.env,
156-
);
157-
158-
debug.dispose();
159-
context.subscriptions.forEach((subscription) => subscription.dispose());
160-
fs.rmSync(tmpPath, { recursive: true, force: true });
161-
});
162-
163115
test("Launching the debugger", async () => {
164116
// eslint-disable-next-line no-process-env
165117
const manager = process.env.CI

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

+17
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)