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

feat: allow chat related file providers to specify a description at registration and for results #233731

Merged
merged 1 commit into from
Nov 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: allow chat related file providers to specify a description at r…
…egistration and for results
  • Loading branch information
joyceerhl committed Nov 12, 2024
commit fb5be1439183db7f5cee04585dbc68f52507d3d9
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadChatAgents2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
$registerRelatedFilesProvider(handle: number): void {
this._chatRelatedFilesProviders.set(handle, this._chatEditingService.registerRelatedFilesProvider(handle, {
provideRelatedFiles: async (request, token) => {
return (await this._proxy.$provideRelatedFiles(handle, request, token))?.map((v) => URI.from(v));
return (await this._proxy.$provideRelatedFiles(handle, request, token))?.map((v) => ({ uri: URI.from(v.uri), description: v.description })) ?? [];
}
}));
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,9 +1450,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension, 'chatParticipantAdditions');
return extHostChatAgents2.registerChatParticipantDetectionProvider(extension, provider);
},
registerRelatedFilesProvider(provider: vscode.ChatRelatedFilesProvider) {
registerRelatedFilesProvider(provider: vscode.ChatRelatedFilesProvider, metadata: vscode.ChatRelatedFilesProviderMetadata) {
checkProposedApiEnabled(extension, 'chatEditing');
return extHostChatAgents2.registerRelatedFilesProvider(extension, provider);
return extHostChatAgents2.registerRelatedFilesProvider(extension, provider, metadata);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { IRevealOptions, ITreeItem, IViewBadge } from '../../common/views.js';
import { CallHierarchyItem } from '../../contrib/callHierarchy/common/callHierarchy.js';
import { ChatAgentLocation, IChatAgentMetadata, IChatAgentRequest, IChatAgentResult, IChatWelcomeMessageContent } from '../../contrib/chat/common/chatAgents.js';
import { ICodeMapperRequest, ICodeMapperResult } from '../../contrib/chat/common/chatCodeMapperService.js';
import { IChatRequestDraft } from '../../contrib/chat/common/chatEditingService.js';
import { IChatRelatedFile, IChatRequestDraft } from '../../contrib/chat/common/chatEditingService.js';
import { IChatProgressHistoryResponseContent } from '../../contrib/chat/common/chatModel.js';
import { IChatContentInlineReference, IChatFollowup, IChatProgress, IChatResponseErrorDetails, IChatTask, IChatTaskDto, IChatUserActionEvent, IChatVoteAction } from '../../contrib/chat/common/chatService.js';
import { IChatRequestVariableValue, IChatVariableData, IChatVariableResolverProgress } from '../../contrib/chat/common/chatVariables.js';
Expand Down Expand Up @@ -1334,7 +1334,7 @@ export interface ExtHostChatAgentsShape2 {
$provideSampleQuestions(handle: number, location: ChatAgentLocation, token: CancellationToken): Promise<IChatFollowup[] | undefined>;
$releaseSession(sessionId: string): void;
$detectChatParticipant(handle: number, request: Dto<IChatAgentRequest>, context: { history: IChatAgentHistoryEntryDto[] }, options: { participants: IChatParticipantMetadata[]; location: ChatAgentLocation }, token: CancellationToken): Promise<IChatParticipantDetectionResult | null | undefined>;
$provideRelatedFiles(handle: number, request: Dto<IChatRequestDraft>, token: CancellationToken): Promise<UriComponents[] | undefined>;
$provideRelatedFiles(handle: number, request: Dto<IChatRequestDraft>, token: CancellationToken): Promise<Dto<IChatRelatedFile>[] | undefined>;
}
export interface IChatParticipantMetadata {
participant: string;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/api/common/extHostChatAgents2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { ExtHostLanguageModels } from './extHostLanguageModels.js';
import * as typeConvert from './extHostTypeConverters.js';
import * as extHostTypes from './extHostTypes.js';
import { isChatViewTitleActionContext } from '../../contrib/chat/common/chatActions.js';
import { IChatRequestDraft } from '../../contrib/chat/common/chatEditingService.js';
import { IChatRelatedFile, IChatRequestDraft } from '../../contrib/chat/common/chatEditingService.js';

class ChatAgentResponseStream {

Expand Down Expand Up @@ -366,7 +366,7 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
});
}

registerRelatedFilesProvider(extension: IExtensionDescription, provider: vscode.ChatRelatedFilesProvider): vscode.Disposable {
registerRelatedFilesProvider(extension: IExtensionDescription, provider: vscode.ChatRelatedFilesProvider, metadata: vscode.ChatRelatedFilesProviderMetadata): vscode.Disposable {
const handle = ExtHostChatAgents2._relatedFilesProviderIdPool++;
this._relatedFilesProviders.set(handle, new ExtHostRelatedFilesProvider(extension, provider));
this._proxy.$registerRelatedFilesProvider(handle);
Expand All @@ -376,7 +376,7 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
});
}

async $provideRelatedFiles(handle: number, request: IChatRequestDraft, token: CancellationToken): Promise<URI[] | undefined> {
async $provideRelatedFiles(handle: number, request: IChatRequestDraft, token: CancellationToken): Promise<Dto<IChatRelatedFile>[] | undefined> {
const provider = this._relatedFilesProviders.get(handle);
if (!provider) {
return Promise.resolve([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { MultiDiffEditorInput } from '../../../multiDiffEditor/browser/multiDiff
import { IMultiDiffSourceResolver, IMultiDiffSourceResolverService, IResolvedMultiDiffSource, MultiDiffEditorItem } from '../../../multiDiffEditor/browser/multiDiffSourceResolverService.js';
import { ChatAgentLocation, IChatAgentService } from '../../common/chatAgents.js';
import { ChatContextKeys } from '../../common/chatContextKeys.js';
import { applyingChatEditsContextKey, applyingChatEditsFailedContextKey, CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME, chatEditingMaxFileAssignmentName, chatEditingResourceContextKey, ChatEditingSessionState, decidedChatEditingResourceContextKey, defaultChatEditingMaxFileLimit, hasAppliedChatEditsContextKey, hasUndecidedChatEditingResourceContextKey, IChatEditingService, IChatEditingSession, IChatEditingSessionStream, IChatRelatedFilesProvider, IModifiedFileEntry, inChatEditingSessionContextKey, WorkingSetEntryState } from '../../common/chatEditingService.js';
import { applyingChatEditsContextKey, applyingChatEditsFailedContextKey, CHAT_EDITING_MULTI_DIFF_SOURCE_RESOLVER_SCHEME, chatEditingMaxFileAssignmentName, chatEditingResourceContextKey, ChatEditingSessionState, decidedChatEditingResourceContextKey, defaultChatEditingMaxFileLimit, hasAppliedChatEditsContextKey, hasUndecidedChatEditingResourceContextKey, IChatEditingService, IChatEditingSession, IChatEditingSessionStream, IChatRelatedFile, IChatRelatedFilesProvider, IModifiedFileEntry, inChatEditingSessionContextKey, WorkingSetEntryState } from '../../common/chatEditingService.js';
import { IChatResponseModel, IChatTextEditGroup } from '../../common/chatModel.js';
import { IChatService } from '../../common/chatService.js';
import { ChatEditingSession } from './chatEditingSession.js';
Expand Down Expand Up @@ -394,7 +394,7 @@ export class ChatEditingService extends Disposable implements IChatEditingServic
});
}

async getRelatedFiles(chatSessionId: string, prompt: string, token: CancellationToken): Promise<readonly URI[] | undefined> {
async getRelatedFiles(chatSessionId: string, prompt: string, token: CancellationToken): Promise<readonly IChatRelatedFile[] | undefined> {
const currentSession = this._currentSessionObs.get();
if (!currentSession || chatSessionId !== currentSession.chatSessionId) {
return undefined;
Expand All @@ -410,7 +410,7 @@ export class ChatEditingService extends Disposable implements IChatEditingServic
}
}));

return result.reduce<URI[]>((acc, cur) => {
return result.reduce<IChatRelatedFile[]>((acc, cur) => {
if (cur) {
acc.push(...cur);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,10 @@ class BuiltinDynamicCompletions extends Disposable {
// RELATED FILES
if (widget.location === ChatAgentLocation.EditingSession && widget.viewModel && this._chatEditingService.currentEditingSessionObs.get()?.chatSessionId === widget.viewModel?.sessionId) {
for (const relatedFile of (await this._chatEditingService.getRelatedFiles(widget.viewModel.sessionId, widget.getInput(), token) ?? [])) {
if (seen.has(relatedFile)) {
if (seen.has(relatedFile.uri)) {
continue;
}
result.suggestions.push(makeFileCompletionItem(relatedFile));
result.suggestions.push(makeFileCompletionItem(relatedFile.uri));
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/contrib/chat/common/chatEditingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ export interface IChatEditingService {
restoreSnapshot(requestId: string | undefined): Promise<void>;

registerRelatedFilesProvider(handle: number, provider: IChatRelatedFilesProvider): IDisposable;
getRelatedFiles(chatSessionId: string, prompt: string, token: CancellationToken): Promise<readonly URI[] | undefined>;
getRelatedFiles(chatSessionId: string, prompt: string, token: CancellationToken): Promise<readonly IChatRelatedFile[] | undefined>;
}

export interface IChatRequestDraft {
readonly prompt: string;
readonly files: readonly URI[];
}

export interface IChatRelatedFile {
readonly uri: URI;
readonly description: string;
}

export interface IChatRelatedFilesProvider {
provideRelatedFiles(chatRequest: IChatRequestDraft, token: CancellationToken): Promise<URI[] | undefined>;
provideRelatedFiles(chatRequest: IChatRequestDraft, token: CancellationToken): Promise<IChatRelatedFile[] | undefined>;
}

export interface IChatEditingSession {
Expand Down
13 changes: 11 additions & 2 deletions src/vscode-dts/vscode.proposed.chatEditing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ declare module 'vscode' {
readonly files: readonly Uri[];
}

export interface ChatRelatedFile {
readonly uri: Uri;
readonly description: string;
}

export interface ChatRelatedFilesProviderMetadata {
readonly description: string;
}

export interface ChatRelatedFilesProvider {
provideRelatedFiles(chatRequest: ChatRequestDraft, token: CancellationToken): ProviderResult<Uri[]>;
provideRelatedFiles(chatRequest: ChatRequestDraft, token: CancellationToken): ProviderResult<ChatRelatedFile[]>;
}

export namespace chat {
export function registerRelatedFilesProvider(provider: ChatRelatedFilesProvider): Disposable;
export function registerRelatedFilesProvider(provider: ChatRelatedFilesProvider, metadata: ChatRelatedFilesProviderMetadata): Disposable;
}
}
Loading