@@ -14,6 +14,7 @@ import {
14
14
CodeActionKind ,
15
15
Diagnostic ,
16
16
} from "vscode" ;
17
+ import { ThemeColor } from "vscode" ;
17
18
18
19
import {
19
20
LanguageClient ,
@@ -188,6 +189,120 @@ export function activate(context: ExtensionContext) {
188
189
StatusBarAlignment . Right ,
189
190
) ;
190
191
192
+ let compilationStatusBarItem = window . createStatusBarItem (
193
+ StatusBarAlignment . Right ,
194
+ ) ;
195
+ context . subscriptions . push ( compilationStatusBarItem ) ;
196
+
197
+ let compileStatusEnabled : boolean = workspace
198
+ . getConfiguration ( "rescript.settings" )
199
+ . get < boolean > ( "compileStatus.enable" , true ) ;
200
+
201
+ type ClientCompileStatus = {
202
+ status : "compiling" | "success" | "error" | "warning" ;
203
+ project : string ;
204
+ errorCount : number ;
205
+ warningCount : number ;
206
+ } ;
207
+ const projectStatuses : Map < string , ClientCompileStatus > = new Map ( ) ;
208
+
209
+ const refreshCompilationStatusItem = ( ) => {
210
+ if ( ! compileStatusEnabled ) {
211
+ compilationStatusBarItem . hide ( ) ;
212
+ compilationStatusBarItem . tooltip = undefined ;
213
+ compilationStatusBarItem . backgroundColor = undefined ;
214
+ compilationStatusBarItem . command = undefined ;
215
+ return ;
216
+ }
217
+ const entries = [ ...projectStatuses . values ( ) ] ;
218
+ const compiling = entries . filter ( ( e ) => e . status === "compiling" ) ;
219
+ const errors = entries . filter ( ( e ) => e . status === "error" ) ;
220
+ const warnings = entries . filter ( ( e ) => e . status === "warning" ) ;
221
+
222
+ if ( compiling . length > 0 ) {
223
+ compilationStatusBarItem . text = `$(loading~spin) ReScript` ;
224
+ compilationStatusBarItem . tooltip = compiling
225
+ . map ( ( e ) => e . project )
226
+ . join ( ", " ) ;
227
+ compilationStatusBarItem . backgroundColor = undefined ;
228
+ compilationStatusBarItem . command = undefined ;
229
+ compilationStatusBarItem . show ( ) ;
230
+ return ;
231
+ }
232
+
233
+ if ( errors . length > 0 ) {
234
+ compilationStatusBarItem . text = `$(alert) ReScript: Failed` ;
235
+ compilationStatusBarItem . backgroundColor = new ThemeColor (
236
+ "statusBarItem.errorBackground" ,
237
+ ) ;
238
+ compilationStatusBarItem . command = "rescript-vscode.showProblems" ;
239
+ const byProject = errors . map ( ( e ) => `${ e . project } (${ e . errorCount } )` ) ;
240
+ compilationStatusBarItem . tooltip = `Failed: ${ byProject . join ( ", " ) } ` ;
241
+ compilationStatusBarItem . show ( ) ;
242
+ return ;
243
+ }
244
+
245
+ if ( warnings . length > 0 ) {
246
+ compilationStatusBarItem . text = `$(warning) ReScript: Warnings` ;
247
+ compilationStatusBarItem . backgroundColor = undefined ;
248
+ compilationStatusBarItem . color = new ThemeColor (
249
+ "statusBarItem.warningBackground" ,
250
+ ) ;
251
+ compilationStatusBarItem . command = "rescript-vscode.showProblems" ;
252
+ const byProject = warnings . map ( ( e ) => `${ e . project } (${ e . warningCount } )` ) ;
253
+ compilationStatusBarItem . tooltip = `Warnings: ${ byProject . join ( ", " ) } ` ;
254
+ compilationStatusBarItem . show ( ) ;
255
+ return ;
256
+ }
257
+
258
+ const successes = entries . filter ( ( e ) => e . status === "success" ) ;
259
+ if ( successes . length > 0 ) {
260
+ // Compact success display: project label plus a green check emoji
261
+ compilationStatusBarItem . text = `$(check) ReScript: Ok` ;
262
+ compilationStatusBarItem . backgroundColor = undefined ;
263
+ compilationStatusBarItem . color = null ;
264
+ compilationStatusBarItem . command = undefined ;
265
+ const projects = successes . map ( ( e ) => e . project ) . join ( ", " ) ;
266
+ compilationStatusBarItem . tooltip = projects
267
+ ? `Compilation Succeeded: ${ projects } `
268
+ : `Compilation Succeeded` ;
269
+ compilationStatusBarItem . show ( ) ;
270
+ return ;
271
+ }
272
+
273
+ compilationStatusBarItem . hide ( ) ;
274
+ compilationStatusBarItem . tooltip = undefined ;
275
+ compilationStatusBarItem . backgroundColor = undefined ;
276
+ compilationStatusBarItem . command = undefined ;
277
+ } ;
278
+
279
+ context . subscriptions . push (
280
+ client . onDidChangeState ( ( { newState } ) => {
281
+ if ( newState === State . Running ) {
282
+ context . subscriptions . push (
283
+ client . onNotification (
284
+ "rescript/compilationStatus" ,
285
+ ( payload : {
286
+ project : string ;
287
+ projectRootPath : string ;
288
+ status : "compiling" | "success" | "error" | "warning" ;
289
+ errorCount : number ;
290
+ warningCount : number ;
291
+ } ) => {
292
+ projectStatuses . set ( payload . projectRootPath , {
293
+ status : payload . status ,
294
+ project : payload . project ,
295
+ errorCount : payload . errorCount ,
296
+ warningCount : payload . warningCount ,
297
+ } ) ;
298
+ refreshCompilationStatusItem ( ) ;
299
+ } ,
300
+ ) ,
301
+ ) ;
302
+ }
303
+ } ) ,
304
+ ) ;
305
+
191
306
let inCodeAnalysisState : {
192
307
active : boolean ;
193
308
activatedFromDirectory : string | null ;
@@ -256,6 +371,14 @@ export function activate(context: ExtensionContext) {
256
371
customCommands . dumpDebug ( context , debugDumpStatusBarItem ) ;
257
372
} ) ;
258
373
374
+ commands . registerCommand ( "rescript-vscode.showProblems" , async ( ) => {
375
+ try {
376
+ await commands . executeCommand ( "workbench.actions.view.problems" ) ;
377
+ } catch {
378
+ outputChannel . show ( ) ;
379
+ }
380
+ } ) ;
381
+
259
382
commands . registerCommand ( "rescript-vscode.debug-dump-retrigger" , ( ) => {
260
383
customCommands . dumpDebugRetrigger ( ) ;
261
384
} ) ;
@@ -346,6 +469,12 @@ export function activate(context: ExtensionContext) {
346
469
) {
347
470
commands . executeCommand ( "rescript-vscode.restart_language_server" ) ;
348
471
} else {
472
+ if ( affectsConfiguration ( "rescript.settings.compileStatus.enable" ) ) {
473
+ compileStatusEnabled = workspace
474
+ . getConfiguration ( "rescript.settings" )
475
+ . get < boolean > ( "compileStatus.enable" , true ) ;
476
+ refreshCompilationStatusItem ( ) ;
477
+ }
349
478
// Send a general message that configuration has updated. Clients
350
479
// interested can then pull the new configuration as they see fit.
351
480
client
0 commit comments