Skip to content

Commit 5c7a773

Browse files
committed
fix: path display concatenation and add startLine for file navigation
- Fix formatPathTooltip to add space before additionalContent (fixes display bug where 'index.ts' + 'up to 50 lines' showed as 'index.tsup to 50 lines') - Add startLine field to ClineSayTool type for read_file operations - Update ReadFileTool to include startLine in the message - Update ChatRow to pass startLine to openFile for navigation to the correct line
1 parent afa6cf9 commit 5c7a773

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

packages/types/src/vscode-extension-host.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ export interface ClineSayTool {
801801
isProtected?: boolean
802802
additionalFileCount?: number // Number of additional files in the same read_file request
803803
lineNumber?: number
804+
startLine?: number // Starting line for read_file operations (for navigation on click)
804805
query?: string
805806
batchFiles?: Array<{
806807
path: string

src/core/tools/ReadFileTool.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,15 @@ export class ReadFileTool extends BaseTool<"read_file"> {
461461
const isOutsideWorkspace = isPathOutsideWorkspace(fullPath)
462462
const lineSnippet = this.getLineSnippet(fileResult.entry!)
463463

464+
const startLine = this.getStartLine(fileResult.entry!)
465+
464466
const completeMessage = JSON.stringify({
465467
tool: "readFile",
466468
path: getReadablePath(task.cwd, relPath),
467469
isOutsideWorkspace,
468470
content: fullPath,
469471
reason: lineSnippet,
472+
startLine,
470473
} satisfies ClineSayTool)
471474

472475
const { response, text, images } = await task.ask("tool", completeMessage, false)
@@ -487,6 +490,17 @@ export class ReadFileTool extends BaseTool<"read_file"> {
487490
}
488491
}
489492

493+
/**
494+
* Get the starting line number for navigation purposes.
495+
*/
496+
private getStartLine(entry: InternalFileEntry): number | undefined {
497+
if (entry.mode === "indentation" && entry.anchor_line !== undefined) {
498+
return entry.anchor_line
499+
}
500+
const offset = entry.offset ?? 1
501+
return offset > 1 ? offset : undefined
502+
}
503+
490504
/**
491505
* Generate a human-readable line snippet for approval messages.
492506
*/

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,13 @@ export const ChatRowContent = ({
649649
<ToolUseBlock>
650650
<ToolUseBlockHeader
651651
className="group"
652-
onClick={() => vscode.postMessage({ type: "openFile", text: tool.content })}>
652+
onClick={() =>
653+
vscode.postMessage({
654+
type: "openFile",
655+
text: tool.content,
656+
values: tool.startLine ? { line: tool.startLine } : undefined,
657+
})
658+
}>
653659
{tool.path?.startsWith(".") && <span>.</span>}
654660
<PathTooltip content={formatPathTooltip(tool.path, tool.reason)}>
655661
<span className="whitespace-nowrap overflow-hidden text-ellipsis text-left mr-2 rtl">

webview-ui/src/utils/formatPathTooltip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function formatPathTooltip(path?: string, additionalContent?: string): st
2121
const formattedPath = removeLeadingNonAlphanumeric(path) + "\u200E"
2222

2323
if (additionalContent) {
24-
return formattedPath + additionalContent
24+
return formattedPath + " " + additionalContent
2525
}
2626

2727
return formattedPath

0 commit comments

Comments
 (0)