Skip to content

Commit b5690c0

Browse files
Whole-file progress indicator (#19)
1 parent 027804b commit b5690c0

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publisher": "Imandra",
77
"icon": "assets/vscode-imandra-avatar.png",
88
"license": "MIT",
9-
"version": "0.0.12",
9+
"version": "0.0.13",
1010
"repository": {
1111
"type": "git",
1212
"url": "https://github.com/imandra-ai/imandrax-vscode"

src/extension.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
DecorationOptions,
1616
DecorationRenderOptions,
1717
DiagnosticSeverity,
18-
TextEditor
18+
TextEditor,
19+
StatusBarAlignment,
20+
ThemeColor,
21+
StatusBarItem
1922
} from "vscode";
2023

2124
import {
@@ -35,6 +38,8 @@ let next_terminal_id = 0;
3538
let model_count = 0;
3639
let decoration_type_good = undefined;
3740
let decoration_type_bad = undefined;
41+
let file_progress_sbi: StatusBarItem = undefined;
42+
let file_progress_text: string = "No tasks";
3843

3944
export function activate(context_: ExtensionContext) {
4045
context = context_;
@@ -106,6 +111,19 @@ export function activate(context_: ExtensionContext) {
106111
languages.onDidChangeDiagnostics(diagnostic_listener, undefined, []);
107112
window.onDidChangeActiveTextEditor(active_editor_listener, undefined, []);
108113

114+
const fileProgressCmdId = "file-progress-cmd";
115+
context.subscriptions.push(commands.registerCommand(fileProgressCmdId, () => {
116+
window.showInformationMessage(file_progress_text);
117+
}));
118+
119+
file_progress_sbi = window.createStatusBarItem(StatusBarAlignment.Right, 0);
120+
file_progress_sbi.text = "100%";
121+
file_progress_sbi.command = fileProgressCmdId;
122+
file_progress_sbi.backgroundColor = undefined;
123+
context.subscriptions.push(file_progress_sbi);
124+
125+
file_progress_sbi.show();
126+
109127
restart(true);
110128
}
111129

@@ -126,12 +144,49 @@ function diagnostics_for_editor(editor: TextEditor) {
126144
editor.setDecorations(decoration_type_bad, all_bad);
127145
}
128146

129-
function diagnostic_listener(e: DiagnosticChangeEvent) {
147+
async function diagnostic_listener(e: DiagnosticChangeEvent) {
130148
diagnostics_for_editor(window.activeTextEditor);
149+
const file_uri = window.activeTextEditor.document.uri;
150+
if (file_uri.scheme == "file")
151+
req_file_progress(file_uri);
152+
else
153+
file_progress_sbi.hide();
131154
}
132155

133-
function active_editor_listener() {
156+
async function active_editor_listener() {
134157
diagnostics_for_editor(window.activeTextEditor);
158+
const file_uri = window.activeTextEditor.document.uri;
159+
if (file_uri.scheme == "file")
160+
req_file_progress(file_uri);
161+
else
162+
file_progress_sbi.hide();
163+
}
164+
165+
async function req_file_progress(uri: Uri) {
166+
client.sendRequest<string>("$imandrax/req-file-progress", { "uri": uri.path }).then((rsp) => {
167+
const task_stats = rsp["task_stats"];
168+
const finished = parseInt(task_stats["finished"]);
169+
const successful = parseInt(task_stats["successful"]);
170+
const failed = parseInt(task_stats["failed"]);
171+
const started = parseInt(task_stats["started"]);
172+
const total = parseInt(task_stats["total"]);
173+
if (total == 0) {
174+
file_progress_sbi.text = "100%";
175+
file_progress_sbi.backgroundColor = undefined;
176+
file_progress_text = "No tasks";
177+
}
178+
else {
179+
file_progress_sbi.text = `${successful}/${total}`;
180+
if (failed != 0)
181+
file_progress_sbi.backgroundColor = new ThemeColor('statusBarItem.errorBackground');
182+
else if (successful != total)
183+
file_progress_sbi.backgroundColor = new ThemeColor('statusBarItem.warningBackground');
184+
else
185+
file_progress_sbi.backgroundColor = undefined;
186+
file_progress_text = `${started} started, ${finished} finished, ${successful} successful, ${failed} failed, ${total} total tasks.`;
187+
}
188+
file_progress_sbi.show();
189+
});
135190
}
136191

137192
export async function start() {
@@ -213,7 +268,8 @@ export function check_all(): Thenable<void> | undefined {
213268
return undefined;
214269
}
215270
const file_uri = window.activeTextEditor.document.uri;
216-
client.sendRequest("workspace/executeCommand", { "command": "check-all", "arguments": [file_uri.toString()] });
271+
if (file_uri.scheme == "file")
272+
client.sendRequest("workspace/executeCommand", { "command": "check-all", "arguments": [file_uri.toString()] });
217273
}
218274

219275
export function browse(uri: string): Thenable<boolean> | undefined {

0 commit comments

Comments
 (0)