Skip to content

Commit

Permalink
Add logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 31, 2023
1 parent d4cb037 commit af82eff
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 32 additions & 5 deletions packages/vscode-extension/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit af82eff

Please sign in to comment.