Skip to content

Commit 220d01e

Browse files
committed
feat(editor): Improve the status bar item for the VS Code extension by adding a tooltip. (#15819)
Also do a bit of refactoring. I found the stats bar item's behavior confusing initially, and I think adding a tooltip will be helpful to understanding what is meant by each state. <img width="173" height="89" alt="Screenshot 2025-11-17 at 5 10 47 PM" src="https://github.com/user-attachments/assets/f9b7be37-336b-4311-a1a0-bef40643d0a9" /> <img width="159" height="95" alt="Screenshot 2025-11-17 at 5 11 06 PM" src="https://github.com/user-attachments/assets/fe375a78-b564-4d68-ae23-27bce7b4d2e5" /> <img width="304" height="78" alt="Screenshot 2025-11-17 at 5 11 48 PM" src="https://github.com/user-attachments/assets/d5784d79-2936-41a1-840f-5f47919584a9" />
1 parent d4ff004 commit 220d01e

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

editors/vscode/client/extension.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const enum LspCommands {
4141

4242
let 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

337345
function 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

Comments
 (0)