diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index 9994b62..2e97889 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -266,7 +266,7 @@ "devDependencies": { "@moonrepo/types": "^1.10.0", "@types/semver": "^7.5.5", - "@types/vscode": "^1.66.0", + "@types/vscode": "^1.75.0", "@vscode/test-electron": "^2.3.6", "esbuild": "^0.19.5", "vsce": "^2.15.0" diff --git a/packages/vscode-extension/src/workspace.ts b/packages/vscode-extension/src/workspace.ts index eababe8..9b6d8d1 100644 --- a/packages/vscode-extension/src/workspace.ts +++ b/packages/vscode-extension/src/workspace.ts @@ -9,15 +9,23 @@ export class Workspace { // Current vscode workspace folder folder: vscode.WorkspaceFolder | null = null; + // Channel for logging + logger: vscode.LogOutputChannel; + // Current moon workspace root root: string | null = null; constructor() { + this.logger = vscode.window.createOutputChannel('moon', { log: true }); + // When a file is opened, attempt to find the moon workspace vscode.workspace.onDidOpenTextDocument((text) => { + this.logger.appendLine('Opened a file, checking for workspace changes'); void this.findRoot(text.uri); }); + vscode.workspace.onDidCloseTextDocument((text) => { + this.logger.appendLine('Closed a file, checking for workspace changes'); void this.findRoot(text.uri); }); } @@ -27,20 +35,39 @@ export class Workspace { return; } + this.folder = null; + this.root = null; + this.binPath = null; + + this.logger.appendLine(`Attempting to find a VSC workspace folder for ${openUri.fsPath}`); + const workspaceFolder = vscode.workspace.getWorkspaceFolder(openUri); if (workspaceFolder) { + this.logger.appendLine( + `Found workspace folder ${workspaceFolder.uri.fsPath} (${workspaceFolder.name})`, + ); + + this.logger.appendLine('Attempting to find a moon installation'); + const files = await vscode.workspace.findFiles( new vscode.RelativePattern(workspaceFolder.uri, '.moon/*.yml'), ); this.folder = workspaceFolder; - this.root = files.length > 0 ? workspaceFolder.uri.fsPath : null; - this.binPath = this.root ? findMoonBin(this.root) : null; + + if (files.length > 0) { + this.root = workspaceFolder.uri.fsPath; + this.binPath = findMoonBin(this.root); + + this.logger.appendLine(`Found workspace root at ${this.root}`); + + if (this.binPath) { + this.logger.appendLine(`Found moon binary at ${this.binPath}`); + } + } } else { - this.folder = null; - this.root = null; - this.binPath = null; + this.logger.appendLine('Did not find a workspace folder, disabling moon'); } // Update context diff --git a/yarn.lock b/yarn.lock index af5885e..b92bbbb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3449,10 +3449,10 @@ __metadata: languageName: node linkType: hard -"@types/vscode@npm:^1.66.0": - version: 1.72.0 - resolution: "@types/vscode@npm:1.72.0" - checksum: 6c07295f6aa58afaaf2f2df556f5a1cfec22f160603ca212e616016d828a1e27402e821375ed19b4caa015c2635af8a240e616e5e048d23644e36cf5bf7a817a +"@types/vscode@npm:^1.75.0": + version: 1.85.0 + resolution: "@types/vscode@npm:1.85.0" + checksum: 100b4dc63629028212ad85d305db57f963ac2eb295c2a96044039f21bb4e68bb0374a9f35780d47c79de7e414b44c06a0d4dc8f3b3218814c4380cef5735818d languageName: node linkType: hard @@ -9583,7 +9583,7 @@ __metadata: "@moonrepo/report": "npm:^1.1.1" "@moonrepo/types": "npm:^1.10.0" "@types/semver": "npm:^7.5.5" - "@types/vscode": "npm:^1.66.0" + "@types/vscode": "npm:^1.75.0" "@vscode/test-electron": "npm:^2.3.6" esbuild: "npm:^0.19.5" execa: "npm:^5.1.1"