Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d8b3cc7

Browse files
authored
Merge pull request #630 from codestoryai/features/open-file-before-editing
[ide] open file before editing
2 parents 14496f6 + 8f50f19 commit d8b3cc7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

extensions/codestory/src/server/applyEdits.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ export async function applyEdits(request: SidecarApplyEditsRequest): Promise<Sid
1717
const replacedText = request.edited_content;
1818
const range = new vscode.Range(new vscode.Position(startPosition.line, startPosition.character), new vscode.Position(endPosition.line, endPosition.character));
1919
const workspaceEdit = new vscode.WorkspaceEdit();
20+
const fileUri = vscode.Uri.file(filePath);
21+
22+
// we want to open the text document first
23+
await vscode.workspace.openTextDocument(fileUri);
2024
workspaceEdit.replace(
21-
vscode.Uri.file(filePath),
25+
fileUri,
2226
range,
2327
replacedText,
2428
);
29+
// apply the edits to it
2530
const success = await vscode.workspace.applyEdit(workspaceEdit);
31+
// we also want to save the file at this point after applying the edit
32+
const _ = await vscode.workspace.save(fileUri);
33+
34+
2635
// we calculate how many lines we get after replacing the text
2736
// once we make the edit on the range, the new range is presented to us
2837
// we have to calculate the new range and use that instead

0 commit comments

Comments
 (0)