CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
214 stars 29 forks source link

Multiple Status Bar Item #307

Closed cemalgnlts closed 6 months ago

cemalgnlts commented 6 months ago

Hi,

I created a status bar item to open notifications:

await initialize({
  ...
});

// Notification status bar item.
const notifyService = await getService(INotificationService);

const getIcon = (dotIcon: boolean = false) => {
  const icon = ["bell"];

  if (notifyService.doNotDisturbMode) icon.push("-slash");
  if (dotIcon) icon.push("-dot");

  return `$(${icon.join("")})`;
};

const notifyItem = window.createStatusBarItem(StatusBarAlignment.Right, 1);
notifyItem.command = "notifications.showList";
notifyItem.name = "Notifications";
notifyItem.text = getIcon();

notifyService.onDidChangeDoNotDisturbMode(() => (notifyItem.text = getIcon()));
notifyService.onDidRemoveNotification(() => (notifyItem.text = getIcon()));
notifyService.onDidAddNotification(() => (notifyItem.text = getIcon(true)));

notifyItem.show();

This allows me to add a notification widget at the bottom right like in VSCode: Screenshot 2024-01-04 15 26 58

I then try to create another one for my extension running in worker.

import { StatusBarAlignment, commands, window } from "vscode";

function activate() {
  addStatusBarItem();

  commands.registerCommand("esbuild.test", () => {
    console.log("OK");
  });
}

function addStatusBarItem() {
  const item = window.createStatusBarItem(StatusBarAlignment.Left, 1);
  item.command = "esbuild.test";
  item.name = "esbuild";
  item.text = "$(zap) Build";
  item.show();
}

export { activate };

Instead of adding more than one place, they share one place.

Screen recording 2024-01-04 15.34.03.webm

CGNonofr commented 6 months ago

Indeed, it looks like a bug in VSCode, here's the bug report: https://github.com/microsoft/vscode/issues/201795

The workaround is to set the status bar item id

Here's the PR that adds the missing VSCode notification status bar item: https://github.com/CodinGame/monaco-vscode-api/pull/308

cemalgnlts commented 6 months ago

Thanks!