Skip to content

Commit b011899

Browse files
committed
Move detection logic to the Shadowenv class
1 parent 5718057 commit b011899

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

vscode/src/ruby.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,6 @@ export class Ruby implements RubyInterface {
320320
}
321321

322322
private async discoverVersionManager() {
323-
// For shadowenv, it wouldn't be enough to check for the executable's existence. We need to check if the project has
324-
// created a .shadowenv.d folder
325-
try {
326-
await vscode.workspace.fs.stat(vscode.Uri.joinPath(this.workspaceFolder.uri, ".shadowenv.d"));
327-
this.versionManager.identifier = ManagerIdentifier.Shadowenv;
328-
return;
329-
} catch (_error: any) {
330-
// If .shadowenv.d doesn't exist, then we check the other version managers
331-
}
332-
333323
// Check managers that have a detect() method
334324
for (const [identifier, ManagerClass] of Object.entries(VERSION_MANAGERS)) {
335325
if (ManagerClass.detect && (await ManagerClass.detect(this.workspaceFolder, this.outputChannel))) {

vscode/src/ruby/shadowenv.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,26 @@ import { VersionManager, ActivationResult } from "./versionManager";
1111
export class UntrustedWorkspaceError extends Error {}
1212

1313
export class Shadowenv extends VersionManager {
14-
async activate(): Promise<ActivationResult> {
14+
private static async shadowenvDirExists(workspaceUri: vscode.Uri): Promise<boolean> {
1515
try {
16-
await vscode.workspace.fs.stat(vscode.Uri.joinPath(this.bundleUri, ".shadowenv.d"));
16+
await vscode.workspace.fs.stat(vscode.Uri.joinPath(workspaceUri, ".shadowenv.d"));
17+
return true;
1718
} catch (_error: any) {
19+
return false;
20+
}
21+
}
22+
23+
static async detect(
24+
workspaceFolder: vscode.WorkspaceFolder,
25+
_outputChannel: vscode.LogOutputChannel,
26+
): Promise<vscode.Uri | undefined> {
27+
const exists = await Shadowenv.shadowenvDirExists(workspaceFolder.uri);
28+
return exists ? vscode.Uri.joinPath(workspaceFolder.uri, ".shadowenv.d") : undefined;
29+
}
30+
31+
async activate(): Promise<ActivationResult> {
32+
const exists = await Shadowenv.shadowenvDirExists(this.bundleUri);
33+
if (!exists) {
1834
throw new Error(
1935
"The Ruby LSP version manager is configured to be shadowenv, \
2036
but no .shadowenv.d directory was found in the workspace",

0 commit comments

Comments
 (0)