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 ChatResult to MappedEditsRequest #238479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/vs/workbench/api/browser/mainThreadChatCodeMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class MainThreadChatCodemapper extends Disposable implements MainThreadCo
requestId,
codeBlocks: uiRequest.codeBlocks,
chatRequestId: uiRequest.chatRequestId,
location: uiRequest.location
location: uiRequest.location,
result: uiRequest.result
};
try {
return await this._proxy.$mapCode(handle, extHostRequest, token).then((result) => result ?? undefined);
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/api/common/extHostCodeMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CancellationToken } from '../../../base/common/cancellation.js';
import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
import { ICodeMapperResult } from '../../contrib/chat/common/chatCodeMapperService.js';
import * as extHostProtocol from './extHost.protocol.js';
import { TextEdit } from './extHostTypeConverters.js';
import { TextEdit, ChatAgentResult } from './extHostTypeConverters.js';
import { URI } from '../../../base/common/uri.js';

export class ExtHostCodeMapper implements extHostProtocol.ExtHostCodeMapperShape {
Expand Down Expand Up @@ -50,7 +50,8 @@ export class ExtHostCodeMapper implements extHostProtocol.ExtHostCodeMapperShape
resource: URI.revive(block.resource),
markdownBeforeBlock: block.markdownBeforeBlock
};
})
}),
result: internalRequest.result ? ChatAgentResult.to(internalRequest.result) : undefined
};

const result = await provider.provideMappedEdits(request, stream, token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class ApplyCodeBlockOperation {
{ location: ProgressLocation.Notification, delay: 500, sticky: true, cancellable: true },
async progress => {
progress.report({ message: localize('applyCodeBlock.progress', "Applying code block using {0}...", codeMapper) });
const editsIterable = this.getEdits(codeBlock, cancellationTokenSource.token);
const editsIterable = this.getEdits(codeBlock, cancellationTokenSource.token, codeBlockContext);
return await this.waitForFirstElement(editsIterable);
},
() => cancellationTokenSource.cancel()
Expand All @@ -225,10 +225,15 @@ export class ApplyCodeBlockOperation {
};
}

private getEdits(codeBlock: ICodeMapperCodeBlock, token: CancellationToken): AsyncIterable<TextEdit[]> {
private getEdits(codeBlock: ICodeMapperCodeBlock, token: CancellationToken, codeBlockContext: ICodeBlockActionContext): AsyncIterable<TextEdit[]> {
return new AsyncIterableObject<TextEdit[]>(async executor => {
let chatResponseResult = undefined;
if (isResponseVM(codeBlockContext.element)) {
chatResponseResult = codeBlockContext.element;
}
const request: ICodeMapperRequest = {
codeBlocks: [codeBlock]
codeBlocks: [codeBlock],
result: chatResponseResult?.result
};
const response: ICodeMapperResponse = {
textEdit: (target: URI, edit: TextEdit[]) => {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/chat/common/chatCodeMapperService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IDisposable } from '../../../../base/common/lifecycle.js';
import { URI } from '../../../../base/common/uri.js';
import { TextEdit } from '../../../../editor/common/languages.js';
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
import { IChatAgentResult } from './chatAgents.js';

export interface ICodeMapperResponse {
textEdit: (resource: URI, textEdit: TextEdit[]) => void;
Expand All @@ -23,6 +24,7 @@ export interface ICodeMapperRequest {
readonly codeBlocks: ICodeMapperCodeBlock[];
readonly chatRequestId?: string;
readonly location?: string;
readonly result?: IChatAgentResult;
}

export interface ICodeMapperResult {
Expand Down
1 change: 1 addition & 0 deletions src/vscode-dts/vscode.proposed.mappedEditsProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ declare module 'vscode' {
readonly codeBlocks: { code: string; resource: Uri; markdownBeforeBlock?: string }[];
readonly location?: string;
readonly chatRequestId?: string;
readonly result?: ChatResult;
}

export interface MappedEditsResponseStream {
Expand Down