Skip to content

Commit afd3df6

Browse files
committed
Address comments, change list directory result format
1 parent 90b18ed commit afd3df6

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class FsRead {
6363
return this.handleFileRange(fileContents)
6464
} catch (error: any) {
6565
this.logger.error(`Failed to read "${this.fsPath}": ${error.message || error}`)
66-
throw new Error(`[fs_read] Failed to read "${this.fsPath}": ${error.message || error}`)
66+
throw new Error(`Failed to read "${this.fsPath}": ${error.message || error}`)
6767
}
6868
}
6969

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,28 @@ export class ListDirectory {
2323
}
2424

2525
public async validate(): Promise<void> {
26-
this.logger.debug(`Validating fsPath: ${this.fsPath}`)
2726
if (!this.fsPath || this.fsPath.trim().length === 0) {
2827
throw new Error('Path cannot be empty.')
2928
}
3029

3130
const sanitized = sanitizePath(this.fsPath)
3231
this.fsPath = sanitized
3332

34-
const fileUri = vscode.Uri.file(this.fsPath)
35-
let exists: boolean
33+
const pathUri = vscode.Uri.file(this.fsPath)
34+
let pathExists: boolean
3635
try {
37-
exists = await fs.exists(fileUri)
38-
if (!exists) {
36+
pathExists = await fs.existsDir(pathUri)
37+
if (!pathExists) {
3938
throw new Error(`Path: "${this.fsPath}" does not exist or cannot be accessed.`)
4039
}
4140
} catch (err) {
4241
throw new Error(`Path: "${this.fsPath}" does not exist or cannot be accessed. (${err})`)
4342
}
44-
45-
this.logger.debug(`Validation succeeded for path: ${this.fsPath}`)
4643
}
4744

4845
public queueDescription(updates: Writable): void {
4946
const fileName = path.basename(this.fsPath)
50-
updates.write(`Listing directory on: [${fileName}]`)
47+
updates.write(`Listing directory on filePath: ${fileName}`)
5148
updates.end()
5249
}
5350

@@ -58,7 +55,7 @@ export class ListDirectory {
5855
return this.createOutput(listing.join('\n'))
5956
} catch (error: any) {
6057
this.logger.error(`Failed to list directory "${this.fsPath}": ${error.message || error}`)
61-
throw new Error(`[fs_read] Failed to list directory "${this.fsPath}": ${error.message || error}`)
58+
throw new Error(`Failed to list directory "${this.fsPath}": ${error.message || error}`)
6259
}
6360
}
6461

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
"listDirectory": {
7777
"name": "listDirectory",
78-
"description": "List the contents of a directory.\n * Use this tool for discovery, before using more targeted tools like fsRead.\n *Useful to try to understand the file structure before diving deeper into specific files.\n *Can be used to explore the codebase.",
78+
"description": "List the contents of a directory.\n * Use this tool for discovery, before using more targeted tools like fsRead.\n *Useful to try to understand the file structure before diving deeper into specific files.\n *Can be used to explore the codebase.\n *Results clearly distinguish between files, directories or symlinks with [FILE], [DIR] and [LINK] prefixes.",
7979
"inputSchema": {
8080
"type": "object",
8181
"properties": {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,14 @@ export async function findStringInDirectory(searchStr: string, dirPath: string)
673673
}
674674

675675
/**
676-
* Returns a one-character tag for a directory ('d'), symlink ('l'), or file ('-').
676+
* Returns a prefix for a directory ('[DIR]'), symlink ('[LINK]'), or file ('[FILE]').
677677
*/
678678
export function formatListing(name: string, fileType: vscode.FileType, fullPath: string): string {
679-
let typeChar = '-'
679+
let typeChar = '[FILE]'
680680
if (fileType === vscode.FileType.Directory) {
681-
typeChar = 'd'
681+
typeChar = '[DIR]'
682682
} else if (fileType === vscode.FileType.SymbolicLink) {
683-
typeChar = 'l'
683+
typeChar = '[LINK]'
684684
}
685685
return `${typeChar} ${fullPath}`
686686
}

0 commit comments

Comments
 (0)