remove old slash commands proposal (#190154)

This commit is contained in:
Johannes Rieken
2023-08-10 14:19:07 +02:00
committed by GitHub
parent 6c683c327c
commit bc4e606f7a
8 changed files with 15 additions and 129 deletions
@@ -40,24 +40,6 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape {
}));
}
async $registerSlashCommandProvider(handle: number, chatProviderId: string): Promise<void> {
const unreg = this._chatService.registerSlashCommandProvider({
chatProviderId,
provideSlashCommands: async token => {
return this._proxy.$provideProviderSlashCommands(handle, token);
},
resolveSlashCommand: async (command, token) => {
return this._proxy.$resolveSlashCommand(handle, command, token);
}
});
this._providerRegistrations.set(handle, unreg);
}
async $unregisterSlashCommandProvider(handle: number): Promise<void> {
this._providerRegistrations.deleteAndDispose(handle);
}
$transferChatSession(sessionId: number, toWorkspace: UriComponents): void {
const sessionIdStr = this._chatService.getSessionId(sessionId);
if (!sessionIdStr) {
@@ -1316,14 +1316,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
}
};
// namespace: interactiveSlashCommands
const interactiveSlashCommands: typeof vscode.interactiveSlashCommands = {
registerSlashCommandProvider(chatProviderId: string, provider: vscode.InteractiveSlashCommandProvider) {
checkProposedApiEnabled(extension, 'interactiveSlashCommands');
return extHostChat.registerSlashCommandProvider(extension, chatProviderId, provider);
}
};
// namespace: ai
const ai: typeof vscode.ai = {
registerSemanticSimilarityProvider(provider: vscode.SemanticSimilarityProvider) {
@@ -1355,13 +1347,12 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
authentication,
commands,
comments,
chat,
debug,
env,
extensions,
interactive,
interactiveSlashCommands,
l10n,
chat,
languages,
notebooks,
scm,
@@ -1203,9 +1203,6 @@ export interface MainThreadChatShape extends IDisposable {
$unregisterChatProvider(handle: number): Promise<void>;
$acceptResponseProgress(handle: number, sessionId: number, progress: IChatResponseProgressDto, responsePartHandle?: number): Promise<number | void>;
$transferChatSession(sessionId: number, toWorkspace: UriComponents): void;
$registerSlashCommandProvider(handle: number, chatProviderId: string): Promise<void>;
$unregisterSlashCommandProvider(handle: number): Promise<void>;
}
export interface ExtHostChatShape {
@@ -1218,9 +1215,6 @@ export interface ExtHostChatShape {
$provideSlashCommands(handle: number, sessionId: number, token: CancellationToken): Promise<ISlashCommand[] | undefined>;
$releaseSession(sessionId: number): void;
$onDidPerformUserAction(event: IChatUserActionEvent): Promise<void>;
$provideProviderSlashCommands(handle: number, token: CancellationToken): Promise<ISlashCommand[] | undefined>;
$resolveSlashCommand(handle: number, command: string, token: CancellationToken): Promise<string | undefined>;
}
export interface ExtHostUrlsShape {
+1 -34
View File
@@ -33,7 +33,7 @@ export class ExtHostChat implements ExtHostChatShape {
private static _nextId = 0;
private readonly _chatProvider = new Map<number, ChatProviderWrapper<vscode.InteractiveSessionProvider>>();
private readonly _slashCommandProvider = new Map<number, ChatProviderWrapper<vscode.InteractiveSlashCommandProvider>>();
private readonly _chatSessions = new Map<number, vscode.InteractiveSession>();
// private readonly _providerResponsesByRequestId = new Map<number, { response: vscode.ProviderResult<vscode.InteractiveResponse | vscode.InteractiveResponseForProgress>; sessionId: number }>();
@@ -286,37 +286,4 @@ export class ExtHostChat implements ExtHostChatShape {
}
//#endregion
registerSlashCommandProvider(extension: Readonly<IRelaxedExtensionDescription>, chatProviderId: string, provider: vscode.InteractiveSlashCommandProvider): vscode.Disposable {
const wrapper = new ChatProviderWrapper(extension, provider);
this._slashCommandProvider.set(wrapper.handle, wrapper);
this._proxy.$registerSlashCommandProvider(wrapper.handle, chatProviderId);
return toDisposable(() => {
this._proxy.$unregisterSlashCommandProvider(wrapper.handle);
this._slashCommandProvider.delete(wrapper.handle);
});
}
async $provideProviderSlashCommands(handle: number, token: CancellationToken): Promise<ISlashCommand[] | undefined> {
const entry = this._slashCommandProvider.get(handle);
if (!entry) {
return undefined;
}
const slashCommands = await entry.provider.provideSlashCommands(token);
return slashCommands?.map(c => (<ISlashCommand>{
...c,
kind: typeConvert.CompletionItemKind.from(c.kind)
}));
}
async $resolveSlashCommand(handle: number, command: string, token: CancellationToken): Promise<string | undefined> {
const entry = this._slashCommandProvider.get(handle);
if (!entry) {
return undefined;
}
const resolved = await entry.provider.resolveSlashCommand(command, token);
return resolved ?? undefined;
}
}
@@ -65,15 +65,8 @@ export interface IChatProvider {
removeRequest?(session: IChat, requestId: string): void;
}
export interface ISlashCommandProvider {
chatProviderId: string;
provideSlashCommands(token: CancellationToken): ProviderResult<ISlashCommand[]>;
resolveSlashCommand(command: string, token: CancellationToken): ProviderResult<string>;
}
export interface ISlashCommand {
command: string;
provider?: ISlashCommandProvider;
sortText?: string;
detail?: string;
@@ -208,7 +201,6 @@ export interface IChatService {
onDidSubmitSlashCommand: Event<{ slashCommand: string; sessionId: string }>;
registerProvider(provider: IChatProvider): IDisposable;
registerSlashCommandProvider(provider: ISlashCommandProvider): IDisposable;
getProviderInfos(): IChatProviderInfo[];
startSession(providerId: string, token: CancellationToken): ChatModel | undefined;
getSession(sessionId: string): IChatModel | undefined;
@@ -24,7 +24,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { CONTEXT_PROVIDER_EXISTS } from 'vs/workbench/contrib/chat/common/chatContextKeys';
import { ChatModel, ChatWelcomeMessageModel, IChatModel, ISerializableChatData, ISerializableChatsData } from 'vs/workbench/contrib/chat/common/chatModel';
import { ChatMessageRole, IChatMessage } from 'vs/workbench/contrib/chat/common/chatProvider';
import { IChat, IChatCompleteResponse, IChatDetail, IChatDynamicRequest, IChatProgress, IChatProvider, IChatProviderInfo, IChatReplyFollowup, IChatResponse, IChatService, IChatTransferredSessionData, IChatUserActionEvent, ISlashCommand, ISlashCommandProvider, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
import { IChat, IChatCompleteResponse, IChatDetail, IChatDynamicRequest, IChatProgress, IChatProvider, IChatProviderInfo, IChatReplyFollowup, IChatResponse, IChatService, IChatTransferredSessionData, IChatUserActionEvent, ISlashCommand, InteractiveSessionCopyKind, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatSlashCommandService, IChatSlashFragment } from 'vs/workbench/contrib/chat/common/chatSlashCommands';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@@ -125,7 +125,7 @@ export class ChatService extends Disposable implements IChatService {
declare _serviceBrand: undefined;
private readonly _providers = new Map<string, IChatProvider>();
private readonly _slashCommandProviders = new Set<ISlashCommandProvider>();
private readonly _sessionModels = new Map<string, ChatModel>();
private readonly _pendingRequests = new Map<string, CancelablePromise<void>>();
private readonly _persistedSessions: ISerializableChatsData;
@@ -559,13 +559,8 @@ export class ChatService extends Disposable implements IChatService {
private async handleSlashCommand(sessionId: string, command: string): Promise<string> {
const slashCommands = await this.getSlashCommands(sessionId, CancellationToken.None);
for (const slashCommand of slashCommands ?? []) {
if (command.startsWith(`/${slashCommand.command}`)) {
if (slashCommand.provider) {
return await slashCommand.provider.resolveSlashCommand(command, CancellationToken.None) ?? command;
} else if (this.chatSlashCommandService.hasCommand(slashCommand.command)) {
return slashCommand.command;
}
if (command.startsWith(`/${slashCommand.command}`) && this.chatSlashCommandService.hasCommand(slashCommand.command)) {
return slashCommand.command;
}
}
return command;
@@ -583,18 +578,6 @@ export class ChatService extends Disposable implements IChatService {
throw new Error(`Unknown provider: ${model.providerId}`);
}
if (!provider.provideSlashCommands) {
return;
}
const mainProviderRequest = provider.provideSlashCommands(model.session!, token);
const slashCommandProviders = Array.from(this._slashCommandProviders).filter(p => p.chatProviderId === model.providerId);
const providerResults = Promise.all([
mainProviderRequest,
...slashCommandProviders.map(p => Promise.resolve(p.provideSlashCommands(token))
.then(commands => commands?.map(c => ({ ...c, provider: p }))))
]);
const serviceResults = this.chatSlashCommandService.getCommands().map(data => {
return <ISlashCommand>{
command: data.command,
@@ -604,14 +587,18 @@ export class ChatService extends Disposable implements IChatService {
};
});
const mainProviderRequest = provider.provideSlashCommands?.(model.session!, token);
try {
const slashCommands = (await providerResults).filter(c => !!c) as ISlashCommand[][];
return slashCommands.flat().concat(serviceResults);
const providerResults = await mainProviderRequest;
if (providerResults) {
return providerResults.concat(serviceResults);
}
return serviceResults;
} catch (e) {
this.logService.error(e);
// If one of the other contributed providers fails, return the main provider's result
return await mainProviderRequest ?? undefined;
return serviceResults;
}
}
@@ -712,16 +699,6 @@ export class ChatService extends Disposable implements IChatService {
});
}
registerSlashCommandProvider(provider: ISlashCommandProvider): IDisposable {
this.trace('registerProvider', `Adding new slash command provider`);
this._slashCommandProviders.add(provider);
return toDisposable(() => {
this.trace('registerProvider', `Disposing slash command provider`);
this._slashCommandProviders.delete(provider);
});
}
getProviderInfos(): IChatProviderInfo[] {
return Array.from(this._providers.values()).map(provider => {
return {
@@ -53,7 +53,6 @@ export const allApiProposals = Object.freeze({
indentSize: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.indentSize.d.ts',
inlineCompletionsAdditions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts',
interactive: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactive.d.ts',
interactiveSlashCommands: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveSlashCommands.d.ts',
interactiveUserActions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveUserActions.d.ts',
interactiveWindow: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveWindow.d.ts',
ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts',
@@ -1,16 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
export interface InteractiveSlashCommandProvider {
provideSlashCommands(token: CancellationToken): ProviderResult<InteractiveSessionSlashCommand[]>;
resolveSlashCommand(command: string, token: CancellationToken): ProviderResult<string>;
}
export namespace interactiveSlashCommands {
export function registerSlashCommandProvider(chatProviderId: string, provider: InteractiveSlashCommandProvider): Disposable;
}
}