Skip to content

Commit 281bf82

Browse files
committed
Refactor file path generation for Intelligent Update fallback to use vscode.workspace.asRelativePath
1 parent 3aded7e commit 281bf82

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/apply-chat-response-command.ts‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode'
22
import * as fs from 'fs'
3-
import * as path from 'path'
43
import { parse_response, ClipboardFile } from './utils/clipboard-parser'
54
import {
65
LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY,
@@ -742,24 +741,12 @@ export const apply_chat_response_command = (
742741

743742
if (choice == 'Apply') {
744743
const document = editor.document
745-
const workspaceFolder = vscode.workspace.getWorkspaceFolder(
746-
document.uri
747-
)
748-
const relativePath = (
749-
workspaceFolder
750-
? path.relative(
751-
workspaceFolder.uri.fsPath,
752-
document.uri.fsPath
753-
)
754-
: path.basename(document.uri.fsPath)
755-
).replace(/\\/g, '/')
756-
757-
const workspace_name = workspaceFolder?.name
758-
759-
const file_path_for_block =
760-
workspace_name && !is_single_root_folder_workspace
761-
? `${workspace_name}/${relativePath}`
762-
: relativePath
744+
const file_path_for_block = vscode.workspace
745+
.asRelativePath(
746+
document.uri,
747+
!is_single_root_folder_workspace
748+
)
749+
.replace(/\\/g, '/')
763750

764751
const fake_chat_response = `\`\`\`\n// ${file_path_for_block}\n${chat_response}\n\`\`\``
765752

0 commit comments

Comments
 (0)