Unverified 提交 08b2cfa0 authored 作者: wwwillchen-bot's avatar wwwillchen-bot 提交者: GitHub

feat: display line numbers in DyadRead component (#2615)

## Summary - Add support for showing line number ranges (e.g., ":L3-L5") in the Read file display - Pass `start_line` and `end_line` attributes from the markdown parser to the DyadRead component - Display line number suffix in the file path to provide better context when viewing partial file reads ## Test plan - [x] Verify line numbers appear correctly when a file read includes start/end lines - [x] Verify files read without line numbers display normally - [x] All tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2615" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Show line numbers in the Read file path for partial file reads. Start and end lines are parsed from markdown and rendered as a :L suffix (e.g., :L3-L5) for clearer context. - **New Features** - Parse start_line and end_line in DyadMarkdownParser and pass to DyadRead. - DyadRead builds and displays line suffix (:L3, :L3-L5, or :L1-L5) next to the filename; tooltip shows full path with suffix. - Files without line numbers render unchanged. <sup>Written for commit 301bd200f245d934974c8d09ab0edf6ae42d7e9c. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> Co-authored-by: 's avatarWill Chen <willchen90@gmail.com> Co-authored-by: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
上级 4ff2633d
......@@ -352,6 +352,8 @@ function renderCustomTag(
node={{
properties: {
path: attributes.path || "",
startLine: attributes.start_line || "",
endLine: attributes.end_line || "",
},
}}
>
......
......@@ -6,30 +6,57 @@ interface DyadReadProps {
children?: ReactNode;
node?: any;
path?: string;
startLine?: string;
endLine?: string;
}
export const DyadRead: React.FC<DyadReadProps> = ({
children,
node,
path: pathProp,
startLine: startLineProp,
endLine: endLineProp,
}) => {
const path = pathProp || node?.properties?.path || "";
const startLine = startLineProp || node?.properties?.startLine || "";
const endLine = endLineProp || node?.properties?.endLine || "";
const fileName = path ? path.split("/").pop() : "";
const dirPath = path
? path.slice(0, path.length - (fileName?.length || 0))
: "";
// Build the line number suffix (e.g., ":L3-L5" or ":L3")
const getLineNumberSuffix = () => {
if (startLine && endLine) {
return `:L${startLine}-L${endLine}`;
} else if (startLine) {
return `:L${startLine}`;
} else if (endLine) {
return `:L1-L${endLine}`;
}
return "";
};
const lineNumberSuffix = getLineNumberSuffix();
return (
<div className="my-1">
<div className="flex items-center gap-1 py-1">
<FileText size={14} className="shrink-0 text-muted-foreground/50" />
<span className="text-[13px] font-medium text-foreground/70">Read</span>
{path && (
<span className="text-[13px] truncate min-w-0" title={path}>
<span
className="text-[13px] truncate min-w-0"
title={path + lineNumberSuffix}
>
{dirPath && (
<span className="text-muted-foreground/85">{dirPath}</span>
)}
<span className="font-medium text-foreground/70">{fileName}</span>
{lineNumberSuffix && (
<span className="text-muted-foreground/85">
{lineNumberSuffix}
</span>
)}
</span>
)}
</div>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论