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 19, 2024
1 parent be91265 commit 0915b82
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 70 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
23 changes: 1 addition & 22 deletions vscode/src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,7 @@ export class Debugger
name: workspace.workspaceFolder.name,
};

const customBundleUri = vscode.Uri.joinPath(workspaceUri, ".ruby-lsp");

return vscode.workspace.fs.readDirectory(customBundleUri).then(
(value) => {
if (value.some((entry) => entry[0] === "Gemfile")) {
debugConfiguration.env.BUNDLE_GEMFILE = vscode.Uri.joinPath(
customBundleUri,
"Gemfile",
).fsPath;
} else if (value.some((entry) => entry[0] === "gems.rb")) {
debugConfiguration.env.BUNDLE_GEMFILE = vscode.Uri.joinPath(
customBundleUri,
"gems.rb",
).fsPath;
}

return debugConfiguration;
},
() => {
return debugConfiguration;
},
);
return debugConfiguration;
}

// If the extension is deactivating, we need to ensure the debug process is terminated or else it may continue running
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,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
48 changes: 0 additions & 48 deletions vscode/src/test/suite/debugger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,54 +112,6 @@ suite("Debugger", () => {
context.subscriptions.forEach((subscription) => subscription.dispose());
});

test("Resolve configuration injects BUNDLE_GEMFILE if there's a custom bundle", async () => {
const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(), "ruby-lsp-test-"));
fs.mkdirSync(path.join(tmpPath, ".ruby-lsp"));
fs.writeFileSync(path.join(tmpPath, ".ruby-lsp", "Gemfile"), "hello!");

const context = { subscriptions: [] } as unknown as vscode.ExtensionContext;
const ruby = { env: { bogus: "hello!" } } as unknown as Ruby;
const workspaceFolder = {
name: "fake",
uri: vscode.Uri.file(tmpPath),
index: 0,
};
const debug = new Debugger(context, () => {
return {
ruby,
workspaceFolder,
} as Workspace;
});
const configs: any = await debug.resolveDebugConfiguration!(
workspaceFolder,
{
type: "ruby_lsp",
name: "Debug",
request: "launch",
// eslint-disable-next-line no-template-curly-in-string
program: "ruby ${file}",
env: { parallel: "1" },
},
);

assert.deepEqual(
{
parallel: "1",
...ruby.env,
BUNDLE_GEMFILE: vscode.Uri.joinPath(
vscode.Uri.file(tmpPath),
".ruby-lsp",
"Gemfile",
).fsPath,
},
configs.env,
);

debug.dispose();
context.subscriptions.forEach((subscription) => subscription.dispose());
fs.rmSync(tmpPath, { recursive: true, force: true });
});

test("Launching the debugger", async () => {
// eslint-disable-next-line no-process-env
const manager = process.env.CI
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 0915b82

Please sign in to comment.