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

chat - race cancellation on EH side #195003

Merged
merged 1 commit into from
Oct 6, 2023
Merged
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
74 changes: 39 additions & 35 deletions src/vs/workbench/api/common/extHostInlineChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type * as vscode from 'vscode';
import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { IRange } from 'vs/editor/common/core/range';
import { IPosition } from 'vs/editor/common/core/position';
import { raceCancellation } from 'vs/base/common/async';

class ProviderWrapper {

Expand Down Expand Up @@ -170,50 +171,53 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
}
};

const task = entry.provider.provideInteractiveEditorResponse(sessionData.session, apiRequest, progress, token);
const task = Promise.resolve(entry.provider.provideInteractiveEditorResponse(sessionData.session, apiRequest, progress, token));

Promise.resolve(task).finally(() => done = true);
let res: vscode.InteractiveEditorResponse | vscode.InteractiveEditorMessageResponse | null | undefined;
try {
res = await raceCancellation(task, token);
} finally {
done = true;
}

const res = await task;
if (!res) {
return undefined;
}

if (res) {

const id = sessionData.responses.push(res) - 1;
const id = sessionData.responses.push(res) - 1;

const stub: Partial<IInlineChatResponseDto> = {
wholeRange: typeConvert.Range.from(res.wholeRange),
placeholder: res.placeholder,
};
const stub: Partial<IInlineChatResponseDto> = {
wholeRange: typeConvert.Range.from(res.wholeRange),
placeholder: res.placeholder,
};

if (ExtHostInteractiveEditor._isMessageResponse(res)) {
return {
...stub,
id,
type: InlineChatResponseType.Message,
message: typeConvert.MarkdownString.from(res.contents),
};
}
if (ExtHostInteractiveEditor._isMessageResponse(res)) {
return {
...stub,
id,
type: InlineChatResponseType.Message,
message: typeConvert.MarkdownString.from(res.contents),
};
}

const { edits } = res;
if (edits instanceof extHostTypes.WorkspaceEdit) {
return {
...stub,
id,
type: InlineChatResponseType.BulkEdit,
edits: typeConvert.WorkspaceEdit.from(edits),
};
const { edits } = res;
if (edits instanceof extHostTypes.WorkspaceEdit) {
return {
...stub,
id,
type: InlineChatResponseType.BulkEdit,
edits: typeConvert.WorkspaceEdit.from(edits),
};

} else if (Array.isArray(edits)) {
return {
...stub,
id,
type: InlineChatResponseType.EditorEdit,
edits: edits.map(typeConvert.TextEdit.from),
};
}
} else {
return {
...stub,
id,
type: InlineChatResponseType.EditorEdit,
edits: (<vscode.TextEdit[]>edits).map(typeConvert.TextEdit.from),
};
}

return undefined;
}

$handleFeedback(handle: number, sessionId: number, responseId: number, kind: InlineChatResponseFeedbackKind): void {
Expand Down