Skip to content

Commit d12bb5f

Browse files
committed
Make maxDepth parameter optional
1 parent 0ac1ff8 commit d12bb5f

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

packages/core/src/codewhispererChat/tools/listDirectory.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import path from 'path'
1212

1313
export interface ListDirectoryParams {
1414
path: string
15-
maxDepth: number
15+
maxDepth?: number
1616
}
1717

1818
export class ListDirectory {
1919
private fsPath: string
20-
private maxDepth: number
20+
private maxDepth?: number
2121
private readonly logger = getLogger('listDirectory')
2222

2323
constructor(params: ListDirectoryParams) {
@@ -47,10 +47,13 @@ export class ListDirectory {
4747

4848
public queueDescription(updates: Writable): void {
4949
const fileName = path.basename(this.fsPath)
50-
if (this.maxDepth === -1) {
50+
if (this.maxDepth === undefined) {
5151
updates.write(`Listing directory recursively: ${fileName}`)
52+
} else if (this.maxDepth === 0) {
53+
updates.write(`Listing directory: ${fileName}`)
5254
} else {
53-
updates.write(`Listing directory: ${fileName} with a depth of ${this.maxDepth}`)
55+
const level = this.maxDepth > 1 ? 'levels' : 'level'
56+
updates.write(`Listing directory: ${fileName} limited to ${this.maxDepth} subfolder ${level}`)
5457
}
5558
updates.end()
5659
}

packages/core/src/codewhispererChat/tools/tool_index.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@
8989
},
9090
"maxDepth": {
9191
"type": "integer",
92-
"description": "Maximum depth to traverse when listing directories. Use `0` to list only the specified directory, `1` to include immediate subdirectories, etc. Use `-1` for unlimited depth (to list all subdirectories recursively)."
92+
"description": "Maximum depth to traverse when listing directories. Use `0` to list only the specified directory, `1` to include immediate subdirectories, etc. If it's not provided, it will list all subdirectories recursively."
9393
}
9494
},
95-
"required": ["path", "maxDepth"]
95+
"required": ["path"]
9696
}
9797
}
9898
}

packages/core/src/shared/utilities/workspaceUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,16 @@ export function formatListing(name: string, fileType: vscode.FileType, fullPath:
693693
* You can either pass a custom callback or rely on the default `formatListing`.
694694
*
695695
* @param dirUri The folder to begin traversing
696-
* @param maxDepth Maximum depth to descend (0 => just this folder, -1 => unlimited depth)
696+
* @param maxDepth Maximum depth to descend (0 => just this folder, if it's missing -> recursively)
697697
* @param customFormatCallback Optional. If given, it will override the default line-formatting
698698
*/
699699
export async function readDirectoryRecursively(
700700
dirUri: vscode.Uri,
701-
maxDepth: number,
701+
maxDepth?: number,
702702
customFormatCallback?: (name: string, fileType: vscode.FileType, fullPath: string) => string
703703
): Promise<string[]> {
704704
const logger = getLogger()
705+
maxDepth = maxDepth ?? -1
705706
const depthDescription = maxDepth < 0 ? 'unlimited' : maxDepth
706707
logger.info(`Reading directory: ${dirUri.fsPath} to max depth: ${depthDescription}`)
707708

packages/core/src/test/codewhispererChat/tools/listDirectory.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('ListDirectory Tool', () => {
4242
await testFolder.write('fileA.txt', 'fileA content')
4343
await testFolder.write(path.join('subfolder', 'fileB.md'), '# fileB')
4444

45-
const listDirectory = new ListDirectory({ path: testFolder.path, maxDepth: -1 })
45+
const listDirectory = new ListDirectory({ path: testFolder.path })
4646
await listDirectory.validate()
4747
const result = await listDirectory.invoke(process.stdout)
4848

0 commit comments

Comments
 (0)