Skip to content

Commit 39e35c8

Browse files
committed
fix: clear status bar only when necessary
1 parent b9c754c commit 39e35c8

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

.changeset/eight-lobsters-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"phpstan-vscode": patch
3+
---
4+
5+
Fix status bar on `clearCache` and `pauseFileWatcher` commands

src/commands/analyse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ async function runAnalyse(ext: Ext, args?: string[]) {
115115
try {
116116
await waitForClose(childProcess);
117117
} catch (error) {
118-
if (skipCloseError) return;
118+
if (skipCloseError) {
119+
ext.clearStatusBar();
120+
return;
121+
}
119122
throw error;
120123
}
121124
} finally {

src/commands/clearCache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ export async function clearCache(ext: Ext) {
3434
});
3535

3636
await waitForClose(childProcess);
37+
38+
ext.clearStatusBar();
3739
}

src/commands/pauseFileWatcher.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Ext } from "../extension";
22
import resumeFileWatcher from "./resumeFileWatcher";
33

44
export default function pauseFileWatcher(ext: Ext) {
5-
ext.setStatusBar({
6-
text: "$(debug-pause) PHPStan",
7-
tooltip: "Resume file watcher",
8-
command: resumeFileWatcher,
9-
});
5+
ext.setStatusBar(
6+
(ext.store.fileWatcher.statusBarFixed = {
7+
text: "$(debug-pause) PHPStan",
8+
tooltip: "Resume file watcher",
9+
command: resumeFileWatcher,
10+
})
11+
);
1012
ext.store.fileWatcher.enabled = false;
1113
}

src/commands/resumeFileWatcher.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { Ext } from "../extension";
22
import analyse from "./analyse";
33

4-
export default function resumeFileWatcher(ext: Ext) {
4+
export default async function resumeFileWatcher(ext: Ext) {
5+
ext.setStatusBar({
6+
text: "$(debug-pause) PHPStan",
7+
tooltip: "Resume file watcher",
8+
command: resumeFileWatcher,
9+
});
10+
ext.store.fileWatcher.statusBarFixed = undefined;
511
ext.store.fileWatcher.enabled = true;
6-
analyse(ext, 0);
12+
await analyse(ext, 0);
713
}

src/extension.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ export type ExtStore = {
4949
};
5050
fileWatcher: {
5151
enabled: boolean;
52+
statusBarFixed?: StatusBarData | undefined;
5253
};
5354
};
5455

56+
export type StatusBarData = {
57+
text: string;
58+
tooltip?: string;
59+
command?: string | ((ext: Ext) => void);
60+
};
61+
5562
export class Ext<
5663
T extends { analyse: ExtCommand; showOutput: ExtCommand } = {
5764
analyse: ExtCommand;
@@ -157,11 +164,7 @@ export class Ext<
157164
};
158165
}
159166

160-
setStatusBar(data: {
161-
text: string;
162-
tooltip?: string;
163-
command?: string | ((ext: Ext) => void);
164-
}) {
167+
setStatusBar(data: StatusBarData) {
165168
this.statusBarItem.text = data.text;
166169
this.statusBarItem.tooltip =
167170
typeof data.tooltip === "string" ? data.tooltip : undefined;
@@ -176,10 +179,14 @@ export class Ext<
176179
}
177180

178181
clearStatusBar() {
179-
this.statusBarItem.text = "";
180-
this.statusBarItem.tooltip = undefined;
181-
this.statusBarItem.command = undefined;
182-
this.statusBarItem.hide();
182+
if (this.store.fileWatcher.statusBarFixed) {
183+
this.setStatusBar(this.store.fileWatcher.statusBarFixed);
184+
} else {
185+
this.statusBarItem.text = "";
186+
this.statusBarItem.tooltip = undefined;
187+
this.statusBarItem.command = undefined;
188+
this.statusBarItem.hide();
189+
}
183190
}
184191

185192
setStatusBarError(error: unknown, source: string) {

0 commit comments

Comments
 (0)