Skip to content

Commit 317e544

Browse files
KJ7LNWEric Wheeler
andauthored
Fix list_code_definition_names to support files (#2046)
* feat: enhance list_code_definition_names to support files Fix 'cwd option must be a path to a directory' error. Add support for analyzing individual source files. Update tool description to clarify file and directory usage. Signed-off-by: Eric Wheeler <[email protected]> * test: updated system instruction snapshots Update system instruction snapshots for list_code_definition_names tool. The snapshots now reflect enhanced documentation that clarifies the tool can analyze both individual files and directories. Signed-off-by: Eric Wheeler <[email protected]> --------- Signed-off-by: Eric Wheeler <[email protected]> Co-authored-by: Eric Wheeler <[email protected]>
1 parent d4c7493 commit 317e544

File tree

3 files changed

+200
-72
lines changed

3 files changed

+200
-72
lines changed

src/core/Cline.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,10 +2508,10 @@ export class Cline extends EventEmitter<ClineEvents> {
25082508
}
25092509
}
25102510
case "list_code_definition_names": {
2511-
const relDirPath: string | undefined = block.params.path
2511+
const relPath: string | undefined = block.params.path
25122512
const sharedMessageProps: ClineSayTool = {
25132513
tool: "listCodeDefinitionNames",
2514-
path: getReadablePath(this.cwd, removeClosingTag("path", relDirPath)),
2514+
path: getReadablePath(this.cwd, removeClosingTag("path", relPath)),
25152515
}
25162516
try {
25172517
if (block.partial) {
@@ -2522,19 +2522,35 @@ export class Cline extends EventEmitter<ClineEvents> {
25222522
await this.ask("tool", partialMessage, block.partial).catch(() => {})
25232523
break
25242524
} else {
2525-
if (!relDirPath) {
2525+
if (!relPath) {
25262526
this.consecutiveMistakeCount++
25272527
pushToolResult(
25282528
await this.sayAndCreateMissingParamError("list_code_definition_names", "path"),
25292529
)
25302530
break
25312531
}
25322532
this.consecutiveMistakeCount = 0
2533-
const absolutePath = path.resolve(this.cwd, relDirPath)
2534-
const result = await parseSourceCodeForDefinitionsTopLevel(
2535-
absolutePath,
2536-
this.rooIgnoreController,
2537-
)
2533+
const absolutePath = path.resolve(this.cwd, relPath)
2534+
let result: string
2535+
try {
2536+
const stats = await fs.stat(absolutePath)
2537+
if (stats.isFile()) {
2538+
const fileResult = await parseSourceCodeDefinitionsForFile(
2539+
absolutePath,
2540+
this.rooIgnoreController,
2541+
)
2542+
result = fileResult ?? "No source code definitions found in this file."
2543+
} else if (stats.isDirectory()) {
2544+
result = await parseSourceCodeForDefinitionsTopLevel(
2545+
absolutePath,
2546+
this.rooIgnoreController,
2547+
)
2548+
} else {
2549+
result = "The specified path is neither a file nor a directory."
2550+
}
2551+
} catch {
2552+
result = `${absolutePath}: does not exist or cannot be accessed.`
2553+
}
25382554
const completeMessage = JSON.stringify({
25392555
...sharedMessageProps,
25402556
content: result,

0 commit comments

Comments
 (0)