Skip to content

Commit

Permalink
Make Aux bar exclusive to PearAI extensions (#181)
Browse files Browse the repository at this point in the history
* Working no move

* Working register redirect
  • Loading branch information
nang-dev authored Feb 5, 2025
1 parent d94d8de commit 0c72d8e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/vs/workbench/common/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { registerIcon } from '../../platform/theme/common/iconRegistry.js';
import { CancellationToken } from '../../base/common/cancellation.js';
import { VSDataTransfer } from '../../base/common/dataTransfer.js';
import { ILocalizedString } from '../../platform/action/common/action.js';
import { auxiliaryBarAllowedViewContainerIDs } from '../services/views/pearai/pearaiViewsShared.js';

export const VIEWS_LOG_ID = 'views';
export const VIEWS_LOG_NAME = localize('views log', "Views");
Expand Down Expand Up @@ -255,7 +256,21 @@ class ViewContainersRegistryImpl extends Disposable implements IViewContainersRe
}
}

Registry.add(Extensions.ViewContainersRegistry, new ViewContainersRegistryImpl());

class PearAIViewContainersRegistryImpl extends ViewContainersRegistryImpl implements IViewContainersRegistry {
override registerViewContainer(viewContainerDescriptor: IViewContainerDescriptor, viewContainerLocation: ViewContainerLocation, options?: { isDefault?: boolean; doNotRegisterOpenCommand?: boolean }): ViewContainer {
// Register to sidebar instead of aux bar if non pearai integration
if (
viewContainerLocation === ViewContainerLocation.AuxiliaryBar &&
!auxiliaryBarAllowedViewContainerIDs.includes(viewContainerDescriptor.id)
) {
viewContainerLocation = ViewContainerLocation.Sidebar;
}
return super.registerViewContainer(viewContainerDescriptor, viewContainerLocation, options);
}
}

Registry.add(Extensions.ViewContainersRegistry, new PearAIViewContainersRegistryImpl());

export interface IViewDescriptor {

Expand Down
49 changes: 49 additions & 0 deletions src/vs/workbench/services/views/pearai/pearaiViews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ViewContainer, ViewContainerLocation } from '../../../common/views.js';

import { IExtensionService } from '../../extensions/common/extensions.js';
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
import { IViewDescriptorService } from '../../../common/views.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
import { IStorageService } from '../../../../platform/storage/common/storage.js';
import { ILoggerService } from '../../../../platform/log/common/log.js';
import { ViewDescriptorService } from '../browser/viewDescriptorService.js';
import { auxiliaryBarAllowedViewContainerIDs } from './pearaiViewsShared.js';

export class PearAIViewDescriptorService extends ViewDescriptorService implements IViewDescriptorService {
constructor(
@IInstantiationService instantiationService: IInstantiationService,
@IContextKeyService contextKeyService: IContextKeyService,
@IStorageService storageService: IStorageService,
@IExtensionService extensionService: IExtensionService,
@ITelemetryService telemetryService: ITelemetryService,
@ILoggerService loggerService: ILoggerService,
) {
super(instantiationService, contextKeyService, storageService, extensionService, telemetryService, loggerService);
}


override moveViewContainerToLocation(
viewContainer: ViewContainer,
location: ViewContainerLocation,
): void {

// Prevent other views to move into aux bar
if (
location === ViewContainerLocation.AuxiliaryBar &&
!auxiliaryBarAllowedViewContainerIDs.includes(viewContainer.id)
) {
return;
}

// Prevent PearAI integrations to move out of aux bar
if (
location !== ViewContainerLocation.AuxiliaryBar &&
auxiliaryBarAllowedViewContainerIDs.includes(viewContainer.id)
) {
return;
}
super.moveViewContainerToLocation(viewContainer, location);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const auxiliaryBarAllowedViewContainerIDs = ['workbench.view.extension.PearAI'];
4 changes: 3 additions & 1 deletion src/vs/workbench/workbench.common.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ registerSingleton(IContextKeyService, ContextKeyService, InstantiationType.Delay
registerSingleton(ITextResourceConfigurationService, TextResourceConfigurationService, InstantiationType.Delayed);
registerSingleton(IDownloadService, DownloadService, InstantiationType.Delayed);
registerSingleton(IOpenerService, OpenerService, InstantiationType.Delayed);
registerSingleton(IViewDescriptorService, PearAIViewDescriptorService, InstantiationType.Delayed);

//#endregion

Expand Down Expand Up @@ -402,6 +403,7 @@ import './contrib/inlineCompletions/browser/inlineCompletions.contribution.js';
// Drop or paste into
import './contrib/dropOrPasteInto/browser/dropOrPasteInto.contribution.js';
import { AllowedExtensionsService } from '../platform/extensionManagement/common/allowedExtensionsService.js';

import { IViewDescriptorService } from './common/views.js';
import { PearAIViewDescriptorService } from './services/views/pearai/pearaiViews.js';

//#endregion

0 comments on commit 0c72d8e

Please sign in to comment.