Skip to content

Commit 8456749

Browse files
author
Kapil Borle
committed
Add animated formatting status
1 parent 3ca0e93 commit 8456749

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

src/features/DocumentFormatter.ts

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,66 @@ function editComparer(leftOperand: ScriptRegion, rightOperand: ScriptRegion): nu
8080
}
8181
}
8282

83+
class AnimatedStatuBarItem {
84+
private statusBarItem: vscode.StatusBarItem;
85+
private maxCount: number;
86+
private counter: number;
87+
private baseText: string;
88+
private text: string;
89+
private timerInterval: number;
90+
private ticks: number;
91+
private intervalId: NodeJS.Timer;
92+
93+
constructor() {
94+
this.statusBarItem = Window.createStatusBarItem();
95+
this.baseText = "formatting";
96+
this.maxCount = 4;
97+
this.counter = 0;
98+
this.timerInterval = 300;
99+
this.ticks = 0;
100+
}
101+
102+
updateCounter() {
103+
this.counter = (this.counter + 1) % this.maxCount;
104+
this.ticks = this.ticks + 1;
105+
}
106+
107+
updateText() {
108+
this.text = this.baseText + ".".repeat(this.counter) + " ".repeat(this.maxCount - this.counter - 1);
109+
}
110+
111+
update() {
112+
this.updateCounter();
113+
this.updateText();
114+
this.statusBarItem.text = this.text;
115+
}
116+
117+
reset() {
118+
this.counter = 0;
119+
}
120+
121+
start(hideWhenDone?: Thenable<any>) {
122+
this.intervalId = setInterval(() => this.update(), this.timerInterval);
123+
this.show();
124+
if (hideWhenDone !== undefined) {
125+
hideWhenDone.then(() => this.stop());
126+
}
127+
}
128+
129+
stop() {
130+
clearInterval(this.intervalId);
131+
this.hide();
132+
}
133+
134+
show() {
135+
this.statusBarItem.show();
136+
}
137+
138+
hide() {
139+
this.statusBarItem.hide();
140+
}
141+
}
142+
83143
class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider {
84144
private languageClient: LanguageClient;
85145

@@ -110,8 +170,10 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
110170
range: Range,
111171
options: FormattingOptions,
112172
token: CancellationToken): TextEdit[] | Thenable<TextEdit[]> {
113-
let textEdits = this.executeRulesInOrder(document, range, options, 0);
114-
Window.setStatusBarMessage("formatting...", textEdits);
173+
174+
let status: AnimatedStatuBarItem = new AnimatedStatuBarItem();
175+
let textEdits: Thenable<TextEdit[]> = this.executeRulesInOrder(document, range, options, 0);
176+
status.start(textEdits);
115177
return textEdits;
116178
}
117179

@@ -174,7 +236,7 @@ class PSDocumentFormattingEditProvider implements DocumentFormattingEditProvider
174236
return this.executeRulesInOrder(document, range, options, index + 1);
175237
});
176238
} else {
177-
return Promise.resolve(new TextEdit[0]);
239+
return Promise.resolve(TextEdit[0]);
178240
}
179241
}
180242

0 commit comments

Comments
 (0)