From 36579d2ea39fc7422ab7b7a06238783a6b23a7fe Mon Sep 17 00:00:00 2001 From: Mihai Popescu <34679869+MihaiPopescu1985@users.noreply.github.com> Date: Thu, 26 Mar 2026 16:03:16 +0200 Subject: [PATCH] Refactor moon installation detection logic Moon 2 supports the moon folder under .config workspace folder. But this was causing the extension to fail with the info that is not finding the moon binary. This was because it could not recognize the workspace. This fixes this behavior. --- packages/vscode-extension/src/workspace.ts | 34 +++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/vscode-extension/src/workspace.ts b/packages/vscode-extension/src/workspace.ts index 55716af..eb4ff1e 100644 --- a/packages/vscode-extension/src/workspace.ts +++ b/packages/vscode-extension/src/workspace.ts @@ -107,32 +107,45 @@ export class Workspace { if (workspaceFolder) { this.folder = workspaceFolder; - this.logger.appendLine(`Found workspace folder ${workspaceFolder.uri.fsPath}`); this.logger.appendLine('Attempting to find a moon installation'); const rootPrefixes = vscode.workspace .getConfiguration('moon') .get('rootPrefixes', [] as string[]); + + // Always include "." at the end rootPrefixes.push('.'); let foundRoot = false; for (const prefix of rootPrefixes) { - const moonDir = path.join(workspaceFolder.uri.fsPath, prefix, '.moon'); + // Moon v1: /.moon + const v1Path = path.join(workspaceFolder.uri.fsPath, prefix, '.moon'); + + // Moon v2: /.config/moon + const v2Path = path.join(workspaceFolder.uri.fsPath, prefix, '.config', 'moon'); + + const candidateDirs = [v1Path, v2Path]; - if (fs.existsSync(moonDir)) { - this.root = path.dirname(moonDir); - this.rootPrefix = prefix; - this.binPath = this.findMoonBin(); + for (const moonDir of candidateDirs) { + if (fs.existsSync(moonDir)) { + this.root = path.dirname(moonDir); + this.rootPrefix = prefix; + this.binPath = this.findMoonBin(); - this.logger.appendLine(`Found moon workspace root at ${this.root}`); + this.logger.appendLine(`Found moon workspace root at ${this.root}`); - if (this.binPath) { - this.logger.appendLine(`Found moon binary at ${this.binPath}`); + if (this.binPath) { + this.logger.appendLine(`Found moon binary at ${this.binPath}`); + } + + foundRoot = true; + break; } + } - foundRoot = true; + if (foundRoot) { break; } } @@ -148,7 +161,6 @@ export class Workspace { // Update context void vscode.commands.executeCommand('setContext', 'moon.inWorkspaceRoot', this.root !== null); - void vscode.commands.executeCommand( 'setContext', 'moon.hasBinary',