Skip to content

Commit afe3705

Browse files
authored
Allow individual version managers to trigger manual Ruby selection (#2835)
### Motivation First step for #2793 This PR passes down the `manuallySelectRuby` function to version managers in order to allow specific version managers to offer configuring fallbacks under certain situations. ### Implementation This PR only starts passing the function down to managers. The next PR in the stack starts using it. ### Automated Tests Updated existing tests.
1 parent 5704eb3 commit afe3705

File tree

13 files changed

+122
-39
lines changed

13 files changed

+122
-39
lines changed

vscode/src/ruby.ts

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ export class Ruby implements RubyInterface {
114114
if (workspaceRubyPath) {
115115
// If a workspace specific Ruby path is configured, then we use that to activate the environment
116116
await this.runActivation(
117-
new None(this.workspaceFolder, this.outputChannel, workspaceRubyPath),
117+
new None(
118+
this.workspaceFolder,
119+
this.outputChannel,
120+
this.manuallySelectRuby.bind(this),
121+
workspaceRubyPath,
122+
),
118123
);
119124
} else {
120125
// If the version manager is auto, discover the actual manager before trying to activate anything
@@ -139,7 +144,12 @@ export class Ruby implements RubyInterface {
139144

140145
if (globalRubyPath) {
141146
await this.runActivation(
142-
new None(this.workspaceFolder, this.outputChannel, globalRubyPath),
147+
new None(
148+
this.workspaceFolder,
149+
this.outputChannel,
150+
this.manuallySelectRuby.bind(this),
151+
globalRubyPath,
152+
),
143153
);
144154
} else {
145155
this._error = true;
@@ -266,47 +276,83 @@ export class Ruby implements RubyInterface {
266276
switch (this.versionManager.identifier) {
267277
case ManagerIdentifier.Asdf:
268278
await this.runActivation(
269-
new Asdf(this.workspaceFolder, this.outputChannel),
279+
new Asdf(
280+
this.workspaceFolder,
281+
this.outputChannel,
282+
this.manuallySelectRuby.bind(this),
283+
),
270284
);
271285
break;
272286
case ManagerIdentifier.Chruby:
273287
await this.runActivation(
274-
new Chruby(this.workspaceFolder, this.outputChannel),
288+
new Chruby(
289+
this.workspaceFolder,
290+
this.outputChannel,
291+
this.manuallySelectRuby.bind(this),
292+
),
275293
);
276294
break;
277295
case ManagerIdentifier.Rbenv:
278296
await this.runActivation(
279-
new Rbenv(this.workspaceFolder, this.outputChannel),
297+
new Rbenv(
298+
this.workspaceFolder,
299+
this.outputChannel,
300+
this.manuallySelectRuby.bind(this),
301+
),
280302
);
281303
break;
282304
case ManagerIdentifier.Rvm:
283305
await this.runActivation(
284-
new Rvm(this.workspaceFolder, this.outputChannel),
306+
new Rvm(
307+
this.workspaceFolder,
308+
this.outputChannel,
309+
this.manuallySelectRuby.bind(this),
310+
),
285311
);
286312
break;
287313
case ManagerIdentifier.Mise:
288314
await this.runActivation(
289-
new Mise(this.workspaceFolder, this.outputChannel),
315+
new Mise(
316+
this.workspaceFolder,
317+
this.outputChannel,
318+
this.manuallySelectRuby.bind(this),
319+
),
290320
);
291321
break;
292322
case ManagerIdentifier.RubyInstaller:
293323
await this.runActivation(
294-
new RubyInstaller(this.workspaceFolder, this.outputChannel),
324+
new RubyInstaller(
325+
this.workspaceFolder,
326+
this.outputChannel,
327+
this.manuallySelectRuby.bind(this),
328+
),
295329
);
296330
break;
297331
case ManagerIdentifier.Custom:
298332
await this.runActivation(
299-
new Custom(this.workspaceFolder, this.outputChannel),
333+
new Custom(
334+
this.workspaceFolder,
335+
this.outputChannel,
336+
this.manuallySelectRuby.bind(this),
337+
),
300338
);
301339
break;
302340
case ManagerIdentifier.None:
303341
await this.runActivation(
304-
new None(this.workspaceFolder, this.outputChannel),
342+
new None(
343+
this.workspaceFolder,
344+
this.outputChannel,
345+
this.manuallySelectRuby.bind(this),
346+
),
305347
);
306348
break;
307349
default:
308350
await this.runActivation(
309-
new Shadowenv(this.workspaceFolder, this.outputChannel),
351+
new Shadowenv(
352+
this.workspaceFolder,
353+
this.outputChannel,
354+
this.manuallySelectRuby.bind(this),
355+
),
310356
);
311357
break;
312358
}

vscode/src/ruby/chruby.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ export class Chruby extends VersionManager {
2929
constructor(
3030
workspaceFolder: vscode.WorkspaceFolder,
3131
outputChannel: WorkspaceChannel,
32+
manuallySelectRuby: () => Promise<void>,
3233
) {
33-
super(workspaceFolder, outputChannel);
34+
super(workspaceFolder, outputChannel, manuallySelectRuby);
3435

3536
const configuredRubies = vscode.workspace
3637
.getConfiguration("rubyLsp")

vscode/src/ruby/none.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export class None extends VersionManager {
1919
constructor(
2020
workspaceFolder: vscode.WorkspaceFolder,
2121
outputChannel: WorkspaceChannel,
22+
manuallySelectRuby: () => Promise<void>,
2223
rubyPath?: string,
2324
) {
24-
super(workspaceFolder, outputChannel);
25+
super(workspaceFolder, outputChannel, manuallySelectRuby);
2526
this.rubyPath = rubyPath ?? "ruby";
2627
}
2728

vscode/src/ruby/versionManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ export abstract class VersionManager {
2626
protected readonly outputChannel: WorkspaceChannel;
2727
protected readonly workspaceFolder: vscode.WorkspaceFolder;
2828
protected readonly bundleUri: vscode.Uri;
29+
protected readonly manuallySelectRuby: () => Promise<void>;
2930

3031
private readonly customBundleGemfile?: string;
3132

3233
constructor(
3334
workspaceFolder: vscode.WorkspaceFolder,
3435
outputChannel: WorkspaceChannel,
36+
manuallySelectRuby: () => Promise<void>,
3537
) {
3638
this.workspaceFolder = workspaceFolder;
3739
this.outputChannel = outputChannel;
40+
this.manuallySelectRuby = manuallySelectRuby;
3841
const customBundleGemfile: string = vscode.workspace
3942
.getConfiguration("rubyLsp")
4043
.get("bundleGemfile")!;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ suite("Asdf", () => {
2626
index: 0,
2727
};
2828
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
29-
const asdf = new Asdf(workspaceFolder, outputChannel);
29+
const asdf = new Asdf(workspaceFolder, outputChannel, async () => {});
3030
const envStub = {
3131
env: { ANY: "true" },
3232
yjit: true,
@@ -75,7 +75,7 @@ suite("Asdf", () => {
7575
index: 0,
7676
};
7777
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
78-
const asdf = new Asdf(workspaceFolder, outputChannel);
78+
const asdf = new Asdf(workspaceFolder, outputChannel, async () => {});
7979
const envStub = {
8080
env: { ANY: "true" },
8181
yjit: true,

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ suite("Chruby", () => {
7474
test("Finds Ruby when .ruby-version is inside workspace", async () => {
7575
fs.writeFileSync(path.join(workspacePath, ".ruby-version"), RUBY_VERSION);
7676

77-
const chruby = new Chruby(workspaceFolder, outputChannel);
77+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
7878
chruby.rubyInstallationUris = [
7979
vscode.Uri.file(path.join(rootPath, "opt", "rubies")),
8080
];
@@ -90,7 +90,7 @@ suite("Chruby", () => {
9090
test("Finds Ruby when .ruby-version is inside on parent directories", async () => {
9191
fs.writeFileSync(path.join(rootPath, ".ruby-version"), RUBY_VERSION);
9292

93-
const chruby = new Chruby(workspaceFolder, outputChannel);
93+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
9494
chruby.rubyInstallationUris = [
9595
vscode.Uri.file(path.join(rootPath, "opt", "rubies")),
9696
];
@@ -126,7 +126,7 @@ suite("Chruby", () => {
126126

127127
fs.writeFileSync(path.join(rootPath, ".ruby-version"), RUBY_VERSION);
128128

129-
const chruby = new Chruby(workspaceFolder, outputChannel);
129+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
130130
chruby.rubyInstallationUris = [
131131
vscode.Uri.file(path.join(rootPath, "opt", "rubies")),
132132
];
@@ -171,7 +171,7 @@ suite("Chruby", () => {
171171
`${RUBY_VERSION}-rc1`,
172172
);
173173

174-
const chruby = new Chruby(workspaceFolder, outputChannel);
174+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
175175
chruby.rubyInstallationUris = [
176176
vscode.Uri.file(path.join(rootPath, "opt", "rubies")),
177177
];
@@ -201,7 +201,7 @@ suite("Chruby", () => {
201201

202202
fs.writeFileSync(path.join(rootPath, ".ruby-version"), RUBY_VERSION);
203203

204-
const chruby = new Chruby(workspaceFolder, outputChannel);
204+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
205205
chruby.rubyInstallationUris = [vscode.Uri.file(rubyHome)];
206206

207207
const { env, version, yjit } = await chruby.activate();
@@ -223,7 +223,7 @@ suite("Chruby", () => {
223223
: "",
224224
} as any);
225225

226-
const chruby = new Chruby(workspaceFolder, outputChannel);
226+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
227227
configStub.restore();
228228

229229
const { env, version, yjit } = await chruby.activate();
@@ -247,7 +247,7 @@ suite("Chruby", () => {
247247
`${major}.${minor}`,
248248
);
249249

250-
const chruby = new Chruby(workspaceFolder, outputChannel);
250+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
251251
chruby.rubyInstallationUris = [
252252
vscode.Uri.file(path.join(rootPath, "opt", "rubies")),
253253
];
@@ -278,7 +278,7 @@ suite("Chruby", () => {
278278
`${major}.${minor}`,
279279
);
280280

281-
const chruby = new Chruby(workspaceFolder, outputChannel);
281+
const chruby = new Chruby(workspaceFolder, outputChannel, async () => {});
282282
chruby.rubyInstallationUris = [
283283
vscode.Uri.file(path.join(rootPath, ".rubies")),
284284
vscode.Uri.file(path.join(rootPath, "opt", "rubies")),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite("Custom", () => {
2323
index: 0,
2424
};
2525
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
26-
const custom = new Custom(workspaceFolder, outputChannel);
26+
const custom = new Custom(workspaceFolder, outputChannel, async () => {});
2727

2828
const envStub = {
2929
env: { ANY: "true" },

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite("Mise", () => {
2727
index: 0,
2828
};
2929
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
30-
const mise = new Mise(workspaceFolder, outputChannel);
30+
const mise = new Mise(workspaceFolder, outputChannel, async () => {});
3131

3232
const envStub = {
3333
env: { ANY: "true" },
@@ -82,7 +82,7 @@ suite("Mise", () => {
8282
index: 0,
8383
};
8484
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
85-
const mise = new Mise(workspaceFolder, outputChannel);
85+
const mise = new Mise(workspaceFolder, outputChannel, async () => {});
8686

8787
const envStub = {
8888
env: { ANY: "true" },

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite("None", () => {
2323
index: 0,
2424
};
2525
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
26-
const none = new None(workspaceFolder, outputChannel);
26+
const none = new None(workspaceFolder, outputChannel, async () => {});
2727

2828
const envStub = {
2929
env: { ANY: "true" },

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite("Rbenv", () => {
2727
index: 0,
2828
};
2929
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
30-
const rbenv = new Rbenv(workspaceFolder, outputChannel);
30+
const rbenv = new Rbenv(workspaceFolder, outputChannel, async () => {});
3131

3232
const envStub = {
3333
env: { ANY: "true" },
@@ -70,7 +70,7 @@ suite("Rbenv", () => {
7070
index: 0,
7171
};
7272
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
73-
const rbenv = new Rbenv(workspaceFolder, outputChannel);
73+
const rbenv = new Rbenv(workspaceFolder, outputChannel, async () => {});
7474

7575
const envStub = {
7676
env: { ANY: "true" },
@@ -129,7 +129,7 @@ suite("Rbenv", () => {
129129
index: 0,
130130
};
131131
const outputChannel = new WorkspaceChannel("fake", common.LOG_CHANNEL);
132-
const rbenv = new Rbenv(workspaceFolder, outputChannel);
132+
const rbenv = new Rbenv(workspaceFolder, outputChannel, async () => {});
133133

134134
const execStub = sinon.stub(common, "asyncExec").resolves({
135135
stdout: "",

0 commit comments

Comments
 (0)