Skip to content

Commit 96b4b42

Browse files
authored
fix(vscode): fix handle inline edit cancellation. (#3748)
1 parent 5a7558e commit 96b4b42

File tree

6 files changed

+189
-168
lines changed

6 files changed

+189
-168
lines changed

Diff for: clients/tabby-agent/src/chat/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ export async function showDocument(params: ShowDocumentParams, lspConnection: Co
231231
// [+] inserted
232232
// [-] deleted
233233
// [>] footer
234-
// [x] stopped
235234
// footer line
236235
// >>>>>>> End of changes
237236
export function generateChangesPreview(edit: Edit): string[] {
@@ -301,7 +300,7 @@ export function generateChangesPreview(edit: Edit): string[] {
301300
}
302301
if (inProgressChunk && lastDiff) {
303302
if (edit.state === "stopped") {
304-
pushDiffValue(lastDiff.value, "x");
303+
pushDiffValue(lastDiff.value, "+");
305304
} else {
306305
pushDiffValue(lastDiff.value, "|");
307306
}
@@ -312,7 +311,7 @@ export function generateChangesPreview(edit: Edit): string[] {
312311
break;
313312
}
314313
if (edit.state === "stopped") {
315-
pushDiffValue(diff.value, "x");
314+
pushDiffValue(diff.value, "=");
316315
} else {
317316
pushDiffValue(diff.value, ".");
318317
}

Diff for: clients/tabby-agent/src/codeLens.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class CodeLensProvider implements Feature {
9191
if (match && editId) {
9292
lineInPreviewBlock = -1;
9393

94-
if (previewBlockMarkers.includes(".")) {
94+
if (previewBlockMarkers.includes(".") || previewBlockMarkers.includes("|")) {
9595
lineCodeLenses.push({
9696
range: codeLensRange,
9797
command: {
@@ -115,7 +115,7 @@ export class CodeLensProvider implements Feature {
115115
line: changesPreviewLineType.header,
116116
},
117117
});
118-
} else if (!previewBlockMarkers.includes("x")) {
118+
} else {
119119
lineCodeLenses.push({
120120
range: codeLensRange,
121121
command: {

Diff for: clients/vscode/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@
397397
"command": "tabby.chat.edit.accept",
398398
"key": "ctrl+enter",
399399
"mac": "cmd+enter",
400-
"when": "tabby.chatEditResolving && editorTextFocus && !editorReadonly"
400+
"when": "tabby.chatEditResolving && !tabby.chatEditInProgress && editorTextFocus && !editorReadonly"
401401
},
402402
{
403403
"command": "tabby.chat.edit.discard",
404404
"key": "escape",
405-
"when": "tabby.chatEditResolving && editorTextFocus && !editorReadonly"
405+
"when": "tabby.chatEditResolving && !tabby.chatEditInProgress && editorTextFocus && !editorReadonly"
406406
},
407407
{
408408
"command": "tabby.chat.addRelevantContext",

Diff for: clients/vscode/src/code-action/QuickFix.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class QuickFixCodeActionProvider implements CodeActionProviderInterface {
6363
quickFixEditing.command = {
6464
command: "tabby.chat.edit.start",
6565
title: "Fix using Tabby",
66-
arguments: [quickFixCmd, mergedRange],
66+
arguments: [undefined, mergedRange, quickFixCmd],
6767
};
6868

6969
const explainErrorCmd = `\nHere is some error information that occurred in the selection:

Diff for: clients/vscode/src/commands/index.ts

+28-25
Original file line numberDiff line numberDiff line change
@@ -266,48 +266,51 @@ export class Commands {
266266
"chat.createPanel": async () => {
267267
await createChatPanel(this.context, this.client, this.gitProvider);
268268
},
269-
"chat.edit.start": async (userCommand?: string, range?: Range) => {
270-
const editor = window.activeTextEditor;
271-
if (!editor) {
269+
"chat.edit.start": async (
270+
fileUri?: string | undefined,
271+
range?: Range | undefined,
272+
userCommand?: string | undefined,
273+
) => {
274+
if (this.contextVariables.chatEditInProgress) {
275+
window.setStatusBarMessage("Edit is already in progress.", 3000);
272276
return;
273277
}
274278

275-
const editRange = range || editor.selection;
276-
277-
const editLocation = {
278-
uri: editor.document.uri.toString(),
279-
range: {
280-
start: { line: editRange.start.line, character: 0 },
281-
end: {
282-
line: editRange.end.character === 0 ? editRange.end.line : editRange.end.line + 1,
283-
character: 0,
284-
},
285-
},
286-
};
287-
288-
if (userCommand) {
279+
let editor: TextEditor | undefined;
280+
if (fileUri) {
289281
try {
290-
// when invoke from editor context menu, the first param `userCommand` is the current file path, we reset userCommand to undefined.
291-
// uri parse will throw error when no scheme can be parsed.
292-
Uri.parse(userCommand, true);
293-
userCommand = undefined;
282+
const uri = Uri.parse(fileUri, true);
283+
editor = window.visibleTextEditors.find((editor) => editor.document.uri.toString() === uri.toString());
294284
} catch {
295-
//
285+
// ignore
296286
}
297287
}
288+
if (!editor) {
289+
editor = window.activeTextEditor;
290+
}
291+
if (!editor) {
292+
return;
293+
}
294+
295+
const editRange = range ?? editor.selection;
298296

299297
const inlineEditController = new InlineEditController(
300298
this.client,
301299
this.config,
302300
this.contextVariables,
303301
editor,
304-
editLocation,
305-
userCommand,
302+
editRange,
306303
);
307-
inlineEditController.start();
304+
const cancellationTokenSource = new CancellationTokenSource();
305+
this.chatEditCancellationTokenSource = cancellationTokenSource;
306+
await inlineEditController.start(userCommand, cancellationTokenSource.token);
307+
cancellationTokenSource.dispose();
308+
this.chatEditCancellationTokenSource = null;
308309
},
309310
"chat.edit.stop": async () => {
310311
this.chatEditCancellationTokenSource?.cancel();
312+
this.chatEditCancellationTokenSource?.dispose();
313+
this.chatEditCancellationTokenSource = null;
311314
},
312315
"chat.edit.accept": async () => {
313316
const editor = window.activeTextEditor;

0 commit comments

Comments
 (0)