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

remove old slash commands proposal #190154

Merged
merged 1 commit into from
Aug 10, 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
18 changes: 0 additions & 18 deletions src/vs/workbench/api/browser/mainThreadChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 1 addition & 10 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1355,13 +1347,12 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
authentication,
commands,
comments,
chat,
debug,
env,
extensions,
interactive,
interactiveSlashCommands,
l10n,
chat,
languages,
notebooks,
scm,
Expand Down
6 changes: 0 additions & 6 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
35 changes: 1 addition & 34 deletions src/vs/workbench/api/common/extHostChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>();

Expand Down Expand Up @@ -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;
}
}
8 changes: 0 additions & 8 deletions src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
49 changes: 13 additions & 36 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
16 changes: 0 additions & 16 deletions src/vscode-dts/vscode.proposed.interactiveSlashCommands.d.ts

This file was deleted.