Skip to content

Commit 6e48de7

Browse files
committed
Make sure all version managers implement the detect logic
1 parent a6287f7 commit 6e48de7

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

vscode/src/ruby.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,20 @@ interface ManagerClass {
4040
manuallySelectRuby: () => Promise<void>,
4141
...args: any[]
4242
): VersionManager;
43-
detect?: (
44-
workspaceFolder: vscode.WorkspaceFolder,
45-
outputChannel: WorkspaceChannel,
46-
) => Promise<vscode.Uri | undefined>;
43+
detect: (workspaceFolder: vscode.WorkspaceFolder, outputChannel: WorkspaceChannel) => Promise<vscode.Uri | undefined>;
4744
}
4845

4946
const VERSION_MANAGERS: Record<ManagerIdentifier, ManagerClass> = {
47+
[ManagerIdentifier.Shadowenv]: Shadowenv,
5048
[ManagerIdentifier.Asdf]: Asdf,
51-
[ManagerIdentifier.Auto]: None, // Auto is handled specially
5249
[ManagerIdentifier.Chruby]: Chruby,
5350
[ManagerIdentifier.Rbenv]: Rbenv,
5451
[ManagerIdentifier.Rvm]: Rvm,
55-
[ManagerIdentifier.Shadowenv]: Shadowenv,
5652
[ManagerIdentifier.Mise]: Mise,
5753
[ManagerIdentifier.RubyInstaller]: RubyInstaller,
58-
[ManagerIdentifier.None]: None,
5954
[ManagerIdentifier.Custom]: Custom,
55+
[ManagerIdentifier.Auto]: None, // Auto is handled specially
56+
[ManagerIdentifier.None]: None, // None is last as the fallback
6057
};
6158

6259
export class Ruby implements RubyInterface {
@@ -319,16 +316,19 @@ export class Ruby implements RubyInterface {
319316
}
320317

321318
private async discoverVersionManager() {
322-
// Check managers that have a detect() method
323-
for (const [identifier, ManagerClass] of Object.entries(VERSION_MANAGERS)) {
324-
if (ManagerClass.detect && (await ManagerClass.detect(this.workspaceFolder, this.outputChannel))) {
325-
this.versionManager = identifier as ManagerIdentifier;
319+
// Check all managers for detection
320+
const entries = Object.entries(VERSION_MANAGERS) as [ManagerIdentifier, ManagerClass][];
321+
322+
for (const [identifier, ManagerClass] of entries) {
323+
if (identifier === ManagerIdentifier.Auto) {
324+
continue;
325+
}
326+
327+
if (await ManagerClass.detect(this.workspaceFolder, this.outputChannel)) {
328+
this.versionManager = identifier;
326329
return;
327330
}
328331
}
329-
330-
// If we can't find a version manager, just return None
331-
this.versionManager = ManagerIdentifier.None;
332332
}
333333

334334
private async handleRubyError(message: string) {

vscode/src/ruby/custom.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { VersionManager, ActivationResult } from "./versionManager";
88
// Users are allowed to define a shell script that runs before calling ruby, giving them the chance to modify the PATH,
99
// GEM_HOME and GEM_PATH as needed to find the correct Ruby runtime.
1010
export class Custom extends VersionManager {
11+
// eslint-disable-next-line @typescript-eslint/require-await
12+
static async detect(
13+
_workspaceFolder: vscode.WorkspaceFolder,
14+
_outputChannel: vscode.LogOutputChannel,
15+
): Promise<vscode.Uri | undefined> {
16+
return undefined;
17+
}
18+
1119
async activate(): Promise<ActivationResult> {
1220
const parsedResult = await this.runEnvActivationScript(`${this.customCommand()} && ruby`);
1321

vscode/src/ruby/none.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import { VersionManager, ActivationResult } from "./versionManager";
1313
// If you don't have Ruby automatically available in your PATH and are not using a version manager, look into
1414
// configuring custom Ruby activation
1515
export class None extends VersionManager {
16+
// eslint-disable-next-line @typescript-eslint/require-await
17+
static async detect(
18+
_workspaceFolder: vscode.WorkspaceFolder,
19+
_outputChannel: vscode.LogOutputChannel,
20+
): Promise<vscode.Uri | undefined> {
21+
// None always matches as the final fallback
22+
return vscode.Uri.file("none");
23+
}
24+
1625
private readonly rubyPath: string;
1726

1827
constructor(

0 commit comments

Comments
 (0)