Skip to content

Commit

Permalink
fix: clear status bar only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Oct 3, 2022
1 parent b9c754c commit 39e35c8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-lobsters-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"phpstan-vscode": patch
---

Fix status bar on `clearCache` and `pauseFileWatcher` commands
5 changes: 4 additions & 1 deletion src/commands/analyse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ async function runAnalyse(ext: Ext, args?: string[]) {
try {
await waitForClose(childProcess);
} catch (error) {
if (skipCloseError) return;
if (skipCloseError) {
ext.clearStatusBar();
return;
}
throw error;
}
} finally {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/clearCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ export async function clearCache(ext: Ext) {
});

await waitForClose(childProcess);

ext.clearStatusBar();
}
12 changes: 7 additions & 5 deletions src/commands/pauseFileWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Ext } from "../extension";
import resumeFileWatcher from "./resumeFileWatcher";

export default function pauseFileWatcher(ext: Ext) {
ext.setStatusBar({
text: "$(debug-pause) PHPStan",
tooltip: "Resume file watcher",
command: resumeFileWatcher,
});
ext.setStatusBar(
(ext.store.fileWatcher.statusBarFixed = {
text: "$(debug-pause) PHPStan",
tooltip: "Resume file watcher",
command: resumeFileWatcher,
})
);
ext.store.fileWatcher.enabled = false;
}
10 changes: 8 additions & 2 deletions src/commands/resumeFileWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Ext } from "../extension";
import analyse from "./analyse";

export default function resumeFileWatcher(ext: Ext) {
export default async function resumeFileWatcher(ext: Ext) {
ext.setStatusBar({
text: "$(debug-pause) PHPStan",
tooltip: "Resume file watcher",
command: resumeFileWatcher,
});
ext.store.fileWatcher.statusBarFixed = undefined;
ext.store.fileWatcher.enabled = true;
analyse(ext, 0);
await analyse(ext, 0);
}
25 changes: 16 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ export type ExtStore = {
};
fileWatcher: {
enabled: boolean;
statusBarFixed?: StatusBarData | undefined;
};
};

export type StatusBarData = {
text: string;
tooltip?: string;
command?: string | ((ext: Ext) => void);
};

export class Ext<
T extends { analyse: ExtCommand; showOutput: ExtCommand } = {
analyse: ExtCommand;
Expand Down Expand Up @@ -157,11 +164,7 @@ export class Ext<
};
}

setStatusBar(data: {
text: string;
tooltip?: string;
command?: string | ((ext: Ext) => void);
}) {
setStatusBar(data: StatusBarData) {
this.statusBarItem.text = data.text;
this.statusBarItem.tooltip =
typeof data.tooltip === "string" ? data.tooltip : undefined;
Expand All @@ -176,10 +179,14 @@ export class Ext<
}

clearStatusBar() {
this.statusBarItem.text = "";
this.statusBarItem.tooltip = undefined;
this.statusBarItem.command = undefined;
this.statusBarItem.hide();
if (this.store.fileWatcher.statusBarFixed) {
this.setStatusBar(this.store.fileWatcher.statusBarFixed);
} else {
this.statusBarItem.text = "";
this.statusBarItem.tooltip = undefined;
this.statusBarItem.command = undefined;
this.statusBarItem.hide();
}
}

setStatusBarError(error: unknown, source: string) {
Expand Down

0 comments on commit 39e35c8

Please sign in to comment.