@@ -41,7 +41,7 @@ const enum LspCommands {
4141
4242let client : LanguageClient | undefined ;
4343
44- let myStatusBarItem : StatusBarItem ;
44+ let oxcStatusBarItem : StatusBarItem ;
4545
4646// Global flag to check if the user allows us to start the server.
4747// When `oxc.requireConfig` is `true`, make sure one `.oxlintrc.json` file is present.
@@ -276,7 +276,7 @@ export async function activate(context: ExtensionContext) {
276276 context . subscriptions . push ( onDidChangeWorkspaceFoldersDispose ) ;
277277
278278 configService . onConfigChange = async function onConfigChange ( event ) {
279- updateStatsBar ( context , this . vsCodeConfig . enable ) ;
279+ updateStatusBar ( context , this . vsCodeConfig . enable ) ;
280280
281281 if ( client === undefined ) {
282282 return ;
@@ -292,7 +292,7 @@ export async function activate(context: ExtensionContext) {
292292 }
293293 } ;
294294
295- updateStatsBar ( context , configService . vsCodeConfig . enable ) ;
295+ updateStatusBar ( context , configService . vsCodeConfig . enable ) ;
296296 if ( allowedToStartServer ) {
297297 if ( configService . vsCodeConfig . enable ) {
298298 await client . start ( ) ;
@@ -310,35 +310,43 @@ export async function deactivate(): Promise<void> {
310310 client = undefined ;
311311}
312312
313- function updateStatsBar ( context : ExtensionContext , enable : boolean ) {
314- if ( ! myStatusBarItem ) {
315- myStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Right , 100 ) ;
316- myStatusBarItem . command = OxcCommands . ToggleEnable ;
317- context . subscriptions . push ( myStatusBarItem ) ;
318- myStatusBarItem . show ( ) ;
319- }
320- let bgColor : string ;
321- let icon : string ;
313+ /**
314+ * Get the status bar state based on whether oxc is enabled and allowed to start.
315+ */
316+ function getStatusBarState ( enable : boolean ) : { bgColor : string ; icon : string ; tooltipText : string } {
322317 if ( ! allowedToStartServer ) {
323- bgColor = 'statusBarItem.offlineBackground' ;
324- icon = '$(circle-slash)' ;
318+ return {
319+ bgColor : 'statusBarItem.offlineBackground' ,
320+ icon : 'circle-slash' ,
321+ tooltipText : 'oxc is disabled (no .oxlintrc.json found)' ,
322+ } ;
325323 } else if ( ! enable ) {
326- bgColor = 'statusBarItem.warningBackground' ;
327- icon = '$(check)' ;
324+ return { bgColor : 'statusBarItem.warningBackground' , icon : 'check' , tooltipText : 'oxc is disabled' } ;
328325 } else {
329- bgColor = 'statusBarItem.activeBackground' ;
330- icon = '$(check-all)' ;
326+ return { bgColor : 'statusBarItem.activeBackground' , icon : 'check-all' , tooltipText : 'oxc is enabled' } ;
327+ }
328+ }
329+
330+ function updateStatusBar ( context : ExtensionContext , enable : boolean ) {
331+ if ( ! oxcStatusBarItem ) {
332+ oxcStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Right , 100 ) ;
333+ oxcStatusBarItem . command = OxcCommands . ToggleEnable ;
334+ context . subscriptions . push ( oxcStatusBarItem ) ;
335+ oxcStatusBarItem . show ( ) ;
331336 }
332337
333- myStatusBarItem . text = `${ icon } oxc` ;
334- myStatusBarItem . backgroundColor = new ThemeColor ( bgColor ) ;
338+ const { bgColor, icon, tooltipText } = getStatusBarState ( enable ) ;
339+
340+ oxcStatusBarItem . text = `$(${ icon } ) oxc` ;
341+ oxcStatusBarItem . backgroundColor = new ThemeColor ( bgColor ) ;
342+ oxcStatusBarItem . tooltip = tooltipText ;
335343}
336344
337345function generateActivatorByConfig ( config : VSCodeConfig , context : ExtensionContext ) : void {
338346 const watcher = workspace . createFileSystemWatcher ( '**/.oxlintrc.json' , false , true , ! config . requireConfig ) ;
339347 watcher . onDidCreate ( async ( ) => {
340348 allowedToStartServer = true ;
341- updateStatsBar ( context , config . enable ) ;
349+ updateStatusBar ( context , config . enable ) ;
342350 if ( client && ! client . isRunning ( ) && config . enable ) {
343351 await client . start ( ) ;
344352 }
@@ -348,7 +356,7 @@ function generateActivatorByConfig(config: VSCodeConfig, context: ExtensionConte
348356 // only can be called when config.requireConfig
349357 allowedToStartServer = ( await workspace . findFiles ( `**/.oxlintrc.json` , '**/node_modules/**' , 1 ) ) . length > 0 ;
350358 if ( ! allowedToStartServer ) {
351- updateStatsBar ( context , false ) ;
359+ updateStatusBar ( context , false ) ;
352360 if ( client && client . isRunning ( ) ) {
353361 await client . stop ( ) ;
354362 }
0 commit comments