Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API that exposes interactive session provider name #180437

Merged
merged 2 commits into from Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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
};
});
}
}
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
Expand Up @@ -85,9 +85,10 @@ export class CommandsQuickAccessProvider extends AbstractEditorCommandsQuickAcce
super({
showAlias: !Language.isDefaultVariant(),
noResultsPick: (filter) => {
return this.interactiveSessionService.getProviderIds().length
const info = this.interactiveSessionService.getProviderInfos()[0];
return info
? {
label: localize('askXInInteractiveSession', "Ask '{0}' in an Interactive Session", filter),
label: localize('askXInInteractiveSession', "Ask {0} '{1}'", info.displayName, filter),
commandId: AskInInteractiveAction.ID,
accept: () => commandService.executeCommand(AskInInteractiveAction.ID, filter)
}
Expand Down Expand Up @@ -310,15 +311,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