Skip to content

Commit c86634c

Browse files
committed
Implement extraction and normalization of file paths containing backslashes
1 parent 70ca134 commit c86634c

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

packages/shared/src/utils/extract-path-from-line-of-code.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ describe('extract_path_from_line_of_code', () => {
77
)
88
})
99

10+
it('should extract filename from // comment with back slashes', () => {
11+
expect(extract_path_from_line_of_code('// path\\to\\file.ts')).toBe(
12+
'path/to/file.ts'
13+
)
14+
})
15+
1016
it('should extract filename with special characters in path components', () => {
1117
expect(extract_path_from_line_of_code('// [path]/(to)/file.ts')).toBe(
1218
'[path]/(to)/file.ts'

packages/shared/src/utils/extract-path-from-line-of-code.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export const extract_path_from_line_of_code = (line: string): string | null => {
1919
// Look for path pattern anywhere in comment with file extension
2020
// Matches sequences like "path/to/file.ext" or "./file.ext" or "../file.ext" or ".gitignore"
2121
const path_match = stripped.match(
22-
/(?:^|\s)((?:\.|[.\/\w\-\[\]\(\)]+\.)[\w\-]{1,10})(?:\s|$)/
22+
/(?:^|\s)((?:\.|[.\/\\\w\-\[\]\(\)]+\.)[\w\-]{1,10})(?:\s|$)/
2323
)
2424
if (path_match) {
25-
return path_match[1]
25+
// Normalize backslashes to forward slashes
26+
return path_match[1].replace(/\\/g, '/')
2627
}
2728

2829
return null

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ describe('clipboard-parser', () => {
119119
)
120120
expect(frontendFile).toBeUndefined()
121121
})
122+
123+
it('should parse paths with backslashes', () => {
124+
const text = load_clipboard_text('backslash-paths.txt')
125+
const result = parse_clipboard_multiple_files({
126+
clipboard_text: text,
127+
is_single_root_folder_workspace: true
128+
})
129+
130+
expect(result).toHaveLength(2)
131+
expect(result[0].file_path).toBe('src/index.ts')
132+
expect(result[0].content).toBe('console.log("hello")')
133+
expect(result[1].file_path).toBe('src/utils.py')
134+
expect(result[1].content).toBe(`print("hello")`)
135+
})
122136
})
123137

124138
describe('parse_file_content_only', () => {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```typescript
2+
// src\index.ts
3+
console.log("hello")
4+
```
5+
6+
```python
7+
# src\utils.py
8+
print("hello")
9+
```

packages/vscode/src/view/backend/message-handlers/handle-setup-api-tool-code-completions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ export const handle_setup_api_tool_code_completions = async (
182182
// Step 1: Select provider
183183
const provider_info = await select_provider()
184184
if (!provider_info) {
185-
return // User cancelled, return to main quick pick
185+
return // User cancelled
186186
}
187187

188188
// Step 2: Select model
189189
const model = await select_model(provider_info)
190190
if (!model) {
191-
return
191+
return // User cancelled
192192
}
193193

194194
const provider_model_exists = current_configs.some(
@@ -214,6 +214,8 @@ export const handle_setup_api_tool_code_completions = async (
214214

215215
current_configs.push(new_config)
216216
await providers_manager.save_code_completions_tool_configs(current_configs)
217+
218+
await edit_configuration(new_config)
217219
}
218220

219221
async function edit_configuration(config: ToolConfig) {
@@ -351,7 +353,6 @@ export const handle_setup_api_tool_code_completions = async (
351353
)
352354
} else {
353355
console.error('Could not find original config in array to update.')
354-
await edit_configuration(config)
355356
return
356357
}
357358
}

0 commit comments

Comments
 (0)