Skip to content

Commit 73bf3f3

Browse files
amungerCopilot
andauthored
use a relative path in edit traces for replays (#1169)
* use a relative path in edit traces for replays * Update src/extension/intents/node/chatReplayIntent.ts Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent eba71b0 commit 73bf3f3

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/extension/intents/node/chatReplayIntent.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ export class ChatReplayIntent implements IIntent {
9393
}
9494

9595
private async makeEdit(edits: FileEdits, stream: vscode.ChatResponseStream) {
96-
const uri = Uri.file(edits.path);
96+
let uri: Uri;
97+
if (!edits.path.startsWith('/') && !edits.path.match(/^[a-zA-Z]:/)) {
98+
// Relative path - join with first workspace folder
99+
const workspaceFolders = this.workspaceService.getWorkspaceFolders();
100+
if (workspaceFolders.length > 0) {
101+
uri = Uri.joinPath(workspaceFolders[0], edits.path);
102+
} else {
103+
throw new Error('No workspace folder available to resolve relative path: ' + edits.path);
104+
}
105+
} else {
106+
// Absolute path
107+
uri = Uri.file(edits.path);
108+
}
97109
await this.ensureFileExists(uri);
98110

99111
stream.markdown('\n```\n');

src/extension/prompt/vscode-node/workspaceEditRecorder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
6+
import * as vscode from 'vscode';
77
import { ObservableGit } from '../../../platform/inlineEdits/common/observableGit';
88
import { WorkspaceDocumentEditHistory } from '../../../platform/inlineEdits/common/workspaceEditTracker/workspaceDocumentEditTracker';
99
import { Disposable } from '../../../util/vs/base/common/lifecycle';
@@ -30,8 +30,10 @@ export class WorkspaceEditRecorder extends Disposable {
3030
this._workspace.openDocuments.get().forEach(doc => {
3131
const edits = this._workspaceDocumentEditHistory.getRecentEdits(doc.id);
3232
if (edits && edits.edits.replacements.length > 0) {
33+
const docUri = vscode.Uri.parse(doc.id.path);
34+
const relativePath = vscode.workspace.asRelativePath(docUri, false);
3335
serializedEdits.push({
34-
path: doc.id.path,
36+
path: relativePath,
3537
edits: JSON.stringify(edits.edits)
3638
});
3739
}

0 commit comments

Comments
 (0)