Skip to content

Commit 5a2093f

Browse files
committed
Standardize additional path processing within the file collector
1 parent 3d86fa5 commit 5a2093f

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

packages/vscode/src/utils/files-collector.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ export class FilesCollector {
2828
additional_paths?: string[]
2929
no_context?: boolean
3030
}): Promise<string> {
31+
const additional_paths = (params?.additional_paths ?? []).map(p => {
32+
if (this.workspace_roots.length > 0) {
33+
return path.join(this.workspace_roots[0], p)
34+
}
35+
return p
36+
})
37+
3138
let context_files: string[] = []
3239

3340
if (params?.no_context) {
34-
context_files = params?.additional_paths ?? []
41+
context_files = additional_paths
3542
} else {
3643
const workspace_files = this.workspace_provider.get_checked_files()
3744
const open_editor_files =
3845
this.open_editors_provider?.get_checked_files() || []
3946

40-
context_files = Array.from(
41-
new Set([
42-
...workspace_files,
43-
...open_editor_files,
44-
...(params?.additional_paths ?? [])
45-
])
46-
)
47+
context_files = Array.from(new Set([...workspace_files, ...open_editor_files, ...additional_paths]))
4748
}
4849

4950
context_files.sort((a, b) => natural_sort(a, b))
@@ -69,7 +70,7 @@ export class FilesCollector {
6970

7071
const content = fs.readFileSync(file_path, 'utf8')
7172

72-
const workspace_root = this.get_workspace_root_for_file(file_path)
73+
const workspace_root = this._get_workspace_root_for_file(file_path)
7374

7475
if (!workspace_root) {
7576
collected_text += `<file path="${file_path}">\n<![CDATA[\n${content}\n]]>\n</file>\n`
@@ -95,7 +96,7 @@ export class FilesCollector {
9596
return collected_text
9697
}
9798

98-
private get_workspace_root_for_file(file_path: string): string | undefined {
99+
private _get_workspace_root_for_file(file_path: string): string | undefined {
99100
return this.workspace_provider.get_workspace_root_for_file(file_path)
100101
}
101102
}

packages/vscode/src/utils/natural-sort.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const natural_sort = (a: string, b: string): number => {
1616
const a_chunk = a_x[i] || ''
1717
const b_chunk = b_x[i] || ''
1818

19-
if (a_chunk !== b_chunk) {
19+
if (a_chunk != b_chunk) {
2020
const a_num = parseInt(a_chunk, 10)
2121
const b_num = parseInt(b_chunk, 10)
2222

0 commit comments

Comments
 (0)