@@ -15,7 +15,10 @@ import {
15
15
DecorationOptions ,
16
16
DecorationRenderOptions ,
17
17
DiagnosticSeverity ,
18
- TextEditor
18
+ TextEditor ,
19
+ StatusBarAlignment ,
20
+ ThemeColor ,
21
+ StatusBarItem
19
22
} from "vscode" ;
20
23
21
24
import {
@@ -35,6 +38,8 @@ let next_terminal_id = 0;
35
38
let model_count = 0 ;
36
39
let decoration_type_good = undefined ;
37
40
let decoration_type_bad = undefined ;
41
+ let file_progress_sbi : StatusBarItem = undefined ;
42
+ let file_progress_text : string = "No tasks" ;
38
43
39
44
export function activate ( context_ : ExtensionContext ) {
40
45
context = context_ ;
@@ -106,6 +111,19 @@ export function activate(context_: ExtensionContext) {
106
111
languages . onDidChangeDiagnostics ( diagnostic_listener , undefined , [ ] ) ;
107
112
window . onDidChangeActiveTextEditor ( active_editor_listener , undefined , [ ] ) ;
108
113
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
+
109
127
restart ( true ) ;
110
128
}
111
129
@@ -126,12 +144,49 @@ function diagnostics_for_editor(editor: TextEditor) {
126
144
editor . setDecorations ( decoration_type_bad , all_bad ) ;
127
145
}
128
146
129
- function diagnostic_listener ( e : DiagnosticChangeEvent ) {
147
+ async function diagnostic_listener ( e : DiagnosticChangeEvent ) {
130
148
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 ( ) ;
131
154
}
132
155
133
- function active_editor_listener ( ) {
156
+ async function active_editor_listener ( ) {
134
157
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
+ } ) ;
135
190
}
136
191
137
192
export async function start ( ) {
@@ -213,7 +268,8 @@ export function check_all(): Thenable<void> | undefined {
213
268
return undefined ;
214
269
}
215
270
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 ( ) ] } ) ;
217
273
}
218
274
219
275
export function browse ( uri : string ) : Thenable < boolean > | undefined {
0 commit comments