diff --git a/src/vs/workbench/browser/parts/overlay/pearOverlayPart.ts b/src/vs/workbench/browser/parts/overlay/pearOverlayPart.ts index 5bd2388c4e4cd..33d6a99b87c41 100644 --- a/src/vs/workbench/browser/parts/overlay/pearOverlayPart.ts +++ b/src/vs/workbench/browser/parts/overlay/pearOverlayPart.ts @@ -59,6 +59,10 @@ export class PearOverlayPart extends Part { this.initialize(); } + isVisible(): boolean { + return this.state === "open"; + } + private async initialize() { const extensionDescription: WebviewExtensionDescription = { id: new ExtensionIdentifier(PEAROVERLAY_ID), diff --git a/src/vs/workbench/browser/parts/overlay/pearOverlayService.ts b/src/vs/workbench/browser/parts/overlay/pearOverlayService.ts index ec6fa9a4ea2e8..9f7fd44284ed9 100644 --- a/src/vs/workbench/browser/parts/overlay/pearOverlayService.ts +++ b/src/vs/workbench/browser/parts/overlay/pearOverlayService.ts @@ -10,6 +10,7 @@ import { } from "vs/platform/instantiation/common/instantiation"; import { IEditorService } from "vs/workbench/services/editor/common/editorService"; import { ITerminalService } from "vs/workbench/contrib/terminal/browser/terminal"; +import { CommandsRegistry } from "vs/platform/commands/common/commands"; export const IPearOverlayService = createDecorator( "pearaiOverlayService", @@ -37,6 +38,11 @@ export interface IPearOverlayService extends IDisposable { * Toggles the visibility of the PearAI popup. */ toggle(): void; + + /** + * Returns true if the PearAI popup is visible. + */ + isVisible(): boolean; } export class PearOverlayService @@ -52,11 +58,13 @@ export class PearOverlayService private readonly instantiationService: IInstantiationService, @IEditorService private readonly _editorService: IEditorService, @ITerminalService private readonly _terminalService: ITerminalService, + // @ICommandService private readonly commandService: ICommandService, ) { super(); this._pearOverlayPart = this.instantiationService.createInstance(PearOverlayPart); this.registerListeners(); + this.registerCommands(); } private registerListeners(): void { @@ -73,6 +81,29 @@ export class PearOverlayService ); } + private registerCommands(): void { + // Register commands for external use e.g. in pearai submodule + CommandsRegistry.registerCommand('pearai.isOverlayVisible', (accessor) => { + const overlayService = accessor.get(IPearOverlayService); + return overlayService.isVisible(); + }); + + CommandsRegistry.registerCommand('pearai.showOverlay', (accessor) => { + const overlayService = accessor.get(IPearOverlayService); + overlayService.show(); + }); + + CommandsRegistry.registerCommand('pearai.hideOverlay', (accessor) => { + const overlayService = accessor.get(IPearOverlayService); + overlayService.hide(); + }); + + CommandsRegistry.registerCommand('pearai.toggleOverlay', (accessor) => { + const overlayService = accessor.get(IPearOverlayService); + overlayService.toggle(); + }); + } + get pearOverlayPart(): PearOverlayPart { return this._pearOverlayPart; } @@ -93,6 +124,11 @@ export class PearOverlayService super.dispose(); this._pearOverlayPart.dispose(); } + + isVisible(): boolean { + return this._pearOverlayPart.isVisible(); + } + } registerSingleton(