11import { promises as fsPromises } from 'node:fs' ;
22
3- import {
4- commands ,
5- ConfigurationChangeEvent ,
6- ExtensionContext ,
7- LogOutputChannel ,
8- StatusBarAlignment ,
9- StatusBarItem ,
10- ThemeColor ,
11- Uri ,
12- window ,
13- workspace ,
14- } from 'vscode' ;
3+ import { commands , ConfigurationChangeEvent , ExtensionContext , LogOutputChannel , Uri , window , workspace } from 'vscode' ;
154
165import { ConfigurationParams , ExecuteCommandRequest , ShowMessageNotification } from 'vscode-languageclient' ;
176
187import { Executable , LanguageClient , LanguageClientOptions , ServerOptions } from 'vscode-languageclient/node' ;
198
209import { join } from 'node:path' ;
21- import { ConfigService } from './ConfigService' ;
22- import { VSCodeConfig } from './VSCodeConfig' ;
2310import { OxcCommands } from './commands' ;
11+ import { ConfigService } from './ConfigService' ;
2412import { onClientNotification , runExecutable } from './lsp_helper' ;
13+ import StatusBarItemHandler from './StatusBarItemHandler' ;
14+ import { VSCodeConfig } from './VSCodeConfig' ;
2515
2616const languageClientName = 'oxc' ;
2717
@@ -31,8 +21,6 @@ const enum LspCommands {
3121
3222let client : LanguageClient | undefined ;
3323
34- let oxcStatusBarItem : StatusBarItem ;
35-
3624// Global flag to check if the user allows us to start the server.
3725// When `oxc.requireConfig` is `true`, make sure one `.oxlintrc.json` file is present.
3826let allowedToStartServer : boolean ;
@@ -41,6 +29,7 @@ export async function activate(
4129 context : ExtensionContext ,
4230 outputChannel : LogOutputChannel ,
4331 configService : ConfigService ,
32+ statusBarItemHandler : StatusBarItemHandler ,
4433) {
4534 allowedToStartServer = configService . vsCodeConfig . requireConfig
4635 ? ( await workspace . findFiles ( `**/.oxlintrc.json` , '**/node_modules/**' , 1 ) ) . length > 0
@@ -157,13 +146,13 @@ export async function activate(
157146
158147 context . subscriptions . push ( onDeleteFilesDispose ) ;
159148
160- updateStatusBar ( context , configService . vsCodeConfig . enable ) ;
149+ updateStatusBar ( statusBarItemHandler , configService . vsCodeConfig . enable ) ;
161150 if ( allowedToStartServer ) {
162151 if ( configService . vsCodeConfig . enable ) {
163152 await client . start ( ) ;
164153 }
165154 } else {
166- generateActivatorByConfig ( configService . vsCodeConfig , context ) ;
155+ generateActivatorByConfig ( configService . vsCodeConfig , context , statusBarItemHandler ) ;
167156 }
168157}
169158
@@ -192,26 +181,33 @@ function getStatusBarState(enable: boolean): { bgColor: string; icon: string; to
192181 }
193182}
194183
195- function updateStatusBar ( context : ExtensionContext , enable : boolean ) {
196- if ( ! oxcStatusBarItem ) {
197- oxcStatusBarItem = window . createStatusBarItem ( StatusBarAlignment . Right , 100 ) ;
198- oxcStatusBarItem . command = OxcCommands . ToggleEnable ;
199- context . subscriptions . push ( oxcStatusBarItem ) ;
200- oxcStatusBarItem . show ( ) ;
201- }
202-
184+ function updateStatusBar ( statusBarItemHandler : StatusBarItemHandler , enable : boolean ) {
203185 const { bgColor, icon, tooltipText } = getStatusBarState ( enable ) ;
204186
205- oxcStatusBarItem . text = `$(${ icon } ) oxc` ;
206- oxcStatusBarItem . backgroundColor = new ThemeColor ( bgColor ) ;
207- oxcStatusBarItem . tooltip = tooltipText ;
187+ let text =
188+ `**${ tooltipText } **\n\n` +
189+ `[$(terminal) Open Output](command:${ OxcCommands . ShowOutputChannel } )\n\n` +
190+ `[$(refresh) Restart Server](command:${ OxcCommands . RestartServer } )\n\n` ;
191+
192+ if ( enable ) {
193+ text += `[$(stop) Stop Server](command:${ OxcCommands . ToggleEnable } )\n\n` ;
194+ } else {
195+ text += `[$(play) Start Server](command:${ OxcCommands . ToggleEnable } )\n\n` ;
196+ }
197+
198+ statusBarItemHandler . setColorAndIcon ( bgColor , icon ) ;
199+ statusBarItemHandler . updateToolTooltip ( 'linter' , text ) ;
208200}
209201
210- function generateActivatorByConfig ( config : VSCodeConfig , context : ExtensionContext ) : void {
202+ function generateActivatorByConfig (
203+ config : VSCodeConfig ,
204+ context : ExtensionContext ,
205+ statusBarItemHandler : StatusBarItemHandler ,
206+ ) : void {
211207 const watcher = workspace . createFileSystemWatcher ( '**/.oxlintrc.json' , false , true , ! config . requireConfig ) ;
212208 watcher . onDidCreate ( async ( ) => {
213209 allowedToStartServer = true ;
214- updateStatusBar ( context , config . enable ) ;
210+ updateStatusBar ( statusBarItemHandler , config . enable ) ;
215211 if ( client && ! client . isRunning ( ) && config . enable ) {
216212 await client . start ( ) ;
217213 }
@@ -221,7 +217,7 @@ function generateActivatorByConfig(config: VSCodeConfig, context: ExtensionConte
221217 // only can be called when config.requireConfig
222218 allowedToStartServer = ( await workspace . findFiles ( `**/.oxlintrc.json` , '**/node_modules/**' , 1 ) ) . length > 0 ;
223219 if ( ! allowedToStartServer ) {
224- updateStatusBar ( context , false ) ;
220+ updateStatusBar ( statusBarItemHandler , false ) ;
225221 if ( client && client . isRunning ( ) ) {
226222 await client . stop ( ) ;
227223 }
@@ -266,11 +262,11 @@ export async function toggleClient(configService: ConfigService): Promise<void>
266262}
267263
268264export async function onConfigChange (
269- context : ExtensionContext ,
270265 event : ConfigurationChangeEvent ,
271266 configService : ConfigService ,
267+ statusBarItemHandler : StatusBarItemHandler ,
272268) : Promise < void > {
273- updateStatusBar ( context , configService . vsCodeConfig . enable ) ;
269+ updateStatusBar ( statusBarItemHandler , configService . vsCodeConfig . enable ) ;
274270
275271 if ( client === undefined ) {
276272 return ;
0 commit comments