Skip to content

Commit

Permalink
Emit for no workspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 31, 2023
1 parent d202a34 commit 0a9b67f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
8 changes: 6 additions & 2 deletions packages/vscode-extension/src/lastRunView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export class LastRunProvider implements vscode.WebviewViewProvider {
this.workspace = workspace;

workspace.onDidChangeWorkspace((folder) => {
this.renderView();

if (!folder) {
return undefined;
}

// When the report is changed, refresh view
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(folder.uri, workspace.getMoonDirPath('cache/runReport.json')),
Expand All @@ -28,8 +34,6 @@ export class LastRunProvider implements vscode.WebviewViewProvider {
watcher.onDidCreate(this.renderView, this);
watcher.onDidDelete(this.renderView, this);

this.renderView();

return watcher;
});
}
Expand Down
14 changes: 11 additions & 3 deletions packages/vscode-extension/src/projectsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
);

workspace.onDidChangeWorkspace((folder) => {
this.refresh();

if (!folder) {
return undefined;
}

// When `.moon/**/*.yml` is changed, refresh projects
const watcher1 = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(folder.uri, workspace.getMoonDirPath('**/*.yml')),
Expand All @@ -226,8 +232,6 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
watcher1.onDidChange(this.refresh, this);
watcher2.onDidChange(this.refresh, this);

this.refresh();

return Disposable.from(watcher1, watcher2);
});
}
Expand All @@ -241,7 +245,11 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
}

async getChildren(element?: TreeItem | undefined): Promise<TreeItem[]> {
if (element instanceof TaskItem || !this.workspace.root) {
if (!this.workspace.root) {
return [];
}

if (element instanceof TaskItem) {
return [];
}

Expand Down
16 changes: 7 additions & 9 deletions packages/vscode-extension/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Workspace {

rootPrefix: string = '';

onDidChangeWorkspaceEmitter: vscode.EventEmitter<vscode.WorkspaceFolder>;
onDidChangeWorkspaceEmitter: vscode.EventEmitter<vscode.WorkspaceFolder | null>;

disposables: vscode.Disposable[] = [];

Expand All @@ -49,7 +49,9 @@ export class Workspace {
});
}

onDidChangeWorkspace(listener: (folder: vscode.WorkspaceFolder) => vscode.Disposable | void) {
onDidChangeWorkspace(
listener: (folder: vscode.WorkspaceFolder | null) => vscode.Disposable | void,
) {
this.onDidChangeWorkspaceEmitter.event((folder) => {
const disposable = listener(folder);

Expand All @@ -60,10 +62,6 @@ export class Workspace {
}

fireDidChangeWorkspace() {
if (!this.folder) {
return;
}

// Remove previous watchers
this.disposables.forEach((disposable) => {
disposable.dispose();
Expand Down Expand Up @@ -139,9 +137,9 @@ export class Workspace {
}
}

if (foundRoot) {
this.fireDidChangeWorkspace();
} else {
this.fireDidChangeWorkspace();

if (!foundRoot) {
this.logger.appendLine('Did not find a moon installation, disabling');
}
} else {
Expand Down

0 comments on commit 0a9b67f

Please sign in to comment.