F3 SLICE-5 review fixes: fence-aware replacement extraction + editSelection guards (#6)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+17
-2
@@ -86,7 +86,12 @@ export function activate(context: vscode.ExtensionContext): CowritingApi | undef
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand("cowriting.editSelection", async () => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || editor.selection.isEmpty || !editor.document.uri.fsPath.startsWith(root)) {
|
||||
if (
|
||||
!editor ||
|
||||
editor.selection.isEmpty ||
|
||||
editor.document.uri.scheme !== "file" ||
|
||||
!editor.document.uri.fsPath.startsWith(root)
|
||||
) {
|
||||
void vscode.window.showWarningMessage("Cowriting: select some text in a workspace document first.");
|
||||
return;
|
||||
}
|
||||
@@ -95,6 +100,10 @@ export function activate(context: vscode.ExtensionContext): CowritingApi | undef
|
||||
placeHolder: "e.g. tighten this paragraph",
|
||||
});
|
||||
if (!instruction) return;
|
||||
if (editor.selection.isEmpty) {
|
||||
void vscode.window.showWarningMessage("Cowriting: select some text in a workspace document first.");
|
||||
return;
|
||||
}
|
||||
const document = editor.document;
|
||||
const selection = editor.selection;
|
||||
const expectedVersion = document.version;
|
||||
@@ -106,6 +115,12 @@ export function activate(context: vscode.ExtensionContext): CowritingApi | undef
|
||||
async () => {
|
||||
const { runEditTurn } = await import("./liveTurn");
|
||||
const turn = await runEditTurn(instruction, selectedText);
|
||||
if (turn.replacement === "") {
|
||||
void vscode.window.showWarningMessage(
|
||||
"Cowriting: Claude returned an empty replacement — nothing was applied.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
const ok = await attributionController.applyAgentEdit(
|
||||
document,
|
||||
new vscode.Range(selection.start, selection.end),
|
||||
@@ -119,7 +134,7 @@ export function activate(context: vscode.ExtensionContext): CowritingApi | undef
|
||||
);
|
||||
if (!ok) {
|
||||
void vscode.window.showWarningMessage(
|
||||
"Cowriting: the document changed while Claude was editing — nothing was applied.",
|
||||
"Cowriting: the edit could not be applied (the document changed during the turn, or the editor rejected the edit) — nothing was changed.",
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user