Skip to content

Commit

Permalink
Add API that exposes interactive session provider name
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Apr 20, 2023
1 parent 233c88a commit 510f3ee
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class MainThreadInteractiveSession extends Disposable implements MainThre

const unreg = this._interactiveSessionService.registerProvider({
id,
displayName: registration.label,
prepareSession: async (initialState, token) => {
const session = await this._proxy.$prepareInteractiveSession(handle, initialState, token);
if (!session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ function installSlashCommandSupport(accessor: ServicesAccessor, editor: IActiveC

async function showMessageResponse(accessor: ServicesAccessor, query: string, response: string) {
const interactiveSessionService = accessor.get(IInteractiveSessionService);
const providerId = interactiveSessionService.getProviderIds()[0];
const providerId = interactiveSessionService.getProviderInfos()[0]?.id;

const interactiveSessionWidgetService = accessor.get(IInteractiveSessionWidgetService);
const widget = await interactiveSessionWidgetService.revealViewForProvider(providerId);
Expand All @@ -961,7 +961,7 @@ async function sendRequest(accessor: ServicesAccessor, query: string) {
const interactiveSessionService = accessor.get(IInteractiveSessionService);
const widgetService = accessor.get(IInteractiveSessionWidgetService);

const providerId = interactiveSessionService.getProviderIds()[0];
const providerId = interactiveSessionService.getProviderInfos()[0]?.id;
const widget = await widgetService.revealViewForProvider(providerId);
if (!widget) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type IInteractiveProgress =
export interface IPersistedInteractiveState { }
export interface IInteractiveProvider {
readonly id: string;
readonly displayName: string;
readonly iconUrl?: string;
prepareSession(initialState: IPersistedInteractiveState | undefined, token: CancellationToken): ProviderResult<IInteractiveSession | undefined>;
resolveRequest?(session: IInteractiveSession, context: any, token: CancellationToken): ProviderResult<IInteractiveRequest>;
Expand Down Expand Up @@ -151,12 +152,17 @@ export interface IInteractiveSessionCompleteResponse {
errorDetails?: IInteractiveResponseErrorDetails;
}

export interface IInteractiveProviderInfo {
id: string;
displayName: string;
}

export const IInteractiveSessionService = createDecorator<IInteractiveSessionService>('IInteractiveSessionService');

export interface IInteractiveSessionService {
_serviceBrand: undefined;
registerProvider(provider: IInteractiveProvider): IDisposable;
getProviderIds(): string[];
getProviderInfos(): IInteractiveProviderInfo[];
startSession(providerId: string, allowRestoringSession: boolean, token: CancellationToken): InteractiveSessionModel | undefined;
retrieveSession(sessionId: string): IInteractiveSessionModel | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { CONTEXT_PROVIDER_EXISTS } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionContextKeys';
import { ISerializableInteractiveSessionData, ISerializableInteractiveSessionsData, InteractiveSessionModel, InteractiveSessionWelcomeMessageModel } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionModel';
import { IInteractiveProgress, IInteractiveProvider, IInteractiveSession, IInteractiveSessionCompleteResponse, IInteractiveSessionDynamicRequest, IInteractiveSessionReplyFollowup, IInteractiveSessionService, IInteractiveSessionUserActionEvent, IInteractiveSlashCommand, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionService';
import { IInteractiveProgress, IInteractiveProvider, IInteractiveProviderInfo, IInteractiveSession, IInteractiveSessionCompleteResponse, IInteractiveSessionDynamicRequest, IInteractiveSessionReplyFollowup, IInteractiveSessionService, IInteractiveSessionUserActionEvent, IInteractiveSlashCommand, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';

const serializedInteractiveSessionKey = 'interactive.sessions';
Expand Down Expand Up @@ -534,7 +534,12 @@ export class InteractiveSessionService extends Disposable implements IInteractiv
});
}

getProviderIds(): string[] {
return Array.from(this._providers.keys());
getProviderInfos(): IInteractiveProviderInfo[] {
return Array.from(this._providers.values()).map(provider => {
return {
id: provider.id,
displayName: provider.displayName
};
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SimpleTestProvider extends Disposable implements IInteractiveProvider {

lastInitialState = undefined;

readonly displayName = 'Test';

private _onDidChangeState = this._register(new Emitter());

constructor(readonly id: string) {
Expand Down Expand Up @@ -107,6 +109,7 @@ suite('InteractiveSession', () => {
function getFailProvider(providerId: string) {
return new class implements IInteractiveProvider {
readonly id = providerId;
readonly displayName = 'Test';

lastInitialState = undefined;

Expand All @@ -133,6 +136,7 @@ suite('InteractiveSession', () => {
const id = 'testProvider';
testService.registerProvider({
id,
displayName: 'Test',
prepareSession: function (initialState: IPersistedInteractiveState | undefined, token: CancellationToken): ProviderResult<IInteractiveSession | undefined> {
throw new Error('Function not implemented.');
},
Expand All @@ -144,6 +148,7 @@ suite('InteractiveSession', () => {
assert.throws(() => {
testService.registerProvider({
id,
displayName: 'Test',
prepareSession: function (initialState: IPersistedInteractiveState | undefined, token: CancellationToken): ProviderResult<IInteractiveSession | undefined> {
throw new Error('Function not implemented.');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class CommandsQuickAccessProvider extends AbstractEditorCommandsQuickAcce
super({
showAlias: !Language.isDefaultVariant(),
noResultsPick: (filter) => {
return this.interactiveSessionService.getProviderIds().length
return this.interactiveSessionService.getProviderInfos().length
? {
label: localize('askXInInteractiveSession', "Ask '{0}' in an Interactive Session", filter),
commandId: AskInInteractiveAction.ID,
Expand Down Expand Up @@ -310,15 +310,16 @@ export class AskInInteractiveAction extends Action2 {
}

let providerId: string;
switch (interactiveSessionService.getProviderIds().length) {
const providerInfos = interactiveSessionService.getProviderInfos();
switch (providerInfos.length) {
case 0:
throw new Error('No interactive session provider found.');
case 1:
providerId = interactiveSessionService.getProviderIds()[0];
providerId = providerInfos[0].id;
break;
default:
logService.warn('Multiple interactive session providers found. Using the first one.');
providerId = interactiveSessionService.getProviderIds()[0];
providerId = providerInfos[0].id;
break;
}

Expand Down

0 comments on commit 510f3ee

Please sign in to comment.