fix(desktop): show complete repository trees (#5102)

## Summary

Large repositories were silently limited to the first 250
lexicographically sorted paths, which could leave the Files tab showing
only dot-directories. Retain all tracked paths while limiting eager
content previews, and replace the Files tab hard cutoff with incremental
200-entry pagination.

### Related issue

Fixes #4960. No duplicate PR found.

### Testing

- Targeted Rust regression: `cargo test --manifest-path
desktop/src-tauri/Cargo.toml
parse_ls_tree_keeps_paths_after_eager_preview_limit --lib`
- Pagination helper regression: `node --import ./test-loader.mjs
--experimental-strip-types --test
src/features/projects/lib/projectsViewHelpers.test.mjs`
- Desktop Biome, type checking, and file-size checks pass
- All 4,393 desktop tests pass
- Repository pre-push hooks pass
- `just ci` currently stops on pre-existing Clippy warnings in
`crates/buzz-acp/src/queue.rs` and `crates/buzz-agent/src/hints.rs`,
outside this PR diff

Generated with Codex

---------

Signed-off-by: Evan Chen <evanc@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Evan Chen
2026-08-19 15:53:14 -07:00
committed by GitHub
parent 9a1e861ab8
commit 9c2f05346f
18 changed files with 721 additions and 162 deletions

View File

@@ -26,7 +26,14 @@ import type {
ProjectRepoFile,
ProjectRepoSnapshot,
} from "@/features/projects/hooks";
import { relativeTime } from "@/features/projects/lib/projectsViewHelpers";
import {
formatFileSize,
formatLastChangedAt,
nextRepositoryEntryLimit,
pluralize,
relativeTime,
REPOSITORY_ENTRY_PAGE_SIZE,
} from "@/features/projects/lib/projectsViewHelpers";
import { useUserSearchQuery } from "@/features/profile/hooks";
import type { UserProfileLookup } from "@/features/profile/lib/identity";
import type { UserSearchResult } from "@/shared/api/types";
@@ -45,27 +52,10 @@ import {
RepoSyncActionButton,
RepositoryBranchDropdown,
} from "./ProjectRepositorySource";
function pluralize(count: number, singular: string) {
return `${count} ${singular}${count === 1 ? "" : "s"}`;
}
export function formatLastChangedAt(timestamp: number | null) {
if (!timestamp) return "—";
return new Date(timestamp * 1_000).toLocaleString(undefined, {
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
});
}
function formatFileSize(size: number | null) {
if (size === null) return "—";
if (size < 1024) return `${size} B`;
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
return `${(size / (1024 * 1024)).toFixed(1)} MB`;
}
import {
type RepositoryFileContentSource,
useRepositoryFileContent,
} from "./useRepositoryFileContent";
function normalizeAuthorLookupValue(value: string | null | undefined) {
return value?.trim().toLowerCase() ?? "";
@@ -545,11 +535,14 @@ function BreadcrumbButton({
function FileContentPanel({
file,
fileContentSource,
onOpenPath,
}: {
file: ProjectRepoFile;
fileContentSource?: RepositoryFileContentSource;
onOpenPath: (path: string) => void;
}) {
const fileContent = useRepositoryFileContent(file, fileContentSource);
const language = languageForPath(file.path);
const pathSegments = file.path.split("/").filter(Boolean);
const fileName = pathSegments[pathSegments.length - 1] ?? file.path;
@@ -588,24 +581,27 @@ function FileContentPanel({
<div className="border-border/50 border-b bg-muted/10 px-4 py-2 text-2xs text-muted-foreground sm:hidden">
Last changed {formatLastChangedAt(file.lastChangedAt)}
</div>
{file.previewContent ? (
{fileContent.isLoading ? (
<BuzzLoadingState label="Loading file" />
) : fileContent.content ? (
<pre className="overflow-x-auto bg-background/60 p-4">
{language ? (
<SyntaxHighlightedCode
className="whitespace-pre-wrap break-words text-xs leading-relaxed"
code={file.previewContent}
code={fileContent.content}
language={language}
/>
) : (
<code className="block min-w-full whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground">
{file.previewContent}
{fileContent.content}
</code>
)}
</pre>
) : (
<div className="p-6 text-sm text-muted-foreground">
Preview unavailable for this file. Large and binary files only show
metadata.
{fileContent.error
? "Could not load this file. Try again after refreshing the repository."
: "Preview unavailable for this file. Large and binary files only show metadata."}
</div>
)}
</div>
@@ -614,6 +610,7 @@ function FileContentPanel({
export function RepositoryFilesPanel({
files,
fileContentSource,
snapshot,
isLoading,
error,
@@ -624,6 +621,7 @@ export function RepositoryFilesPanel({
unavailableMessage,
}: {
files: ProjectRepoFile[];
fileContentSource?: RepositoryFileContentSource;
snapshot: ProjectRepoSnapshot | null | undefined;
isLoading: boolean;
error: unknown;
@@ -640,6 +638,13 @@ export function RepositoryFilesPanel({
const [currentPath, setCurrentPath] = React.useState("");
const [selectedFile, setSelectedFile] =
React.useState<ProjectRepoFile | null>(null);
const [visibleEntryCount, setVisibleEntryCount] = React.useState(
REPOSITORY_ENTRY_PAGE_SIZE,
);
const openPath = React.useCallback((path: string) => {
setCurrentPath(path);
setVisibleEntryCount(REPOSITORY_ENTRY_PAGE_SIZE);
}, []);
React.useEffect(() => {
onContextChange?.({
kind: selectedFile ? "file" : "folder",
@@ -650,7 +655,12 @@ export function RepositoryFilesPanel({
() => repositoryEntries(files, currentPath),
[currentPath, files],
);
const visibleEntries = entries.slice(0, 200);
const visibleEntries = entries.slice(0, visibleEntryCount);
const nextVisibleEntryCount = nextRepositoryEntryLimit(
visibleEntryCount,
entries.length,
);
const nextEntryCount = nextVisibleEntryCount - visibleEntries.length;
const latestCommit = snapshot?.latestCommit ?? null;
const knownLatestCommitProfile = React.useMemo(
() => profileForCommitAuthor(latestCommit, profiles),
@@ -692,6 +702,7 @@ export function RepositoryFilesPanel({
if (!filesKey) return;
setCurrentPath("");
setSelectedFile(null);
setVisibleEntryCount(REPOSITORY_ENTRY_PAGE_SIZE);
}, [filesKey]);
// Loading/error/empty states keep the header controls visible — the
@@ -775,9 +786,10 @@ export function RepositoryFilesPanel({
return (
<FileContentPanel
file={selectedFile}
fileContentSource={fileContentSource}
onOpenPath={(path) => {
setSelectedFile(null);
setCurrentPath(path);
openPath(path);
}}
/>
);
@@ -806,14 +818,14 @@ export function RepositoryFilesPanel({
/>
</>
) : (
<BreadcrumbButton onClick={() => setCurrentPath("")}>
<BreadcrumbButton onClick={() => openPath("")}>
Files
</BreadcrumbButton>
)}
{sourceControls && pathSegments.length > 0 ? (
<>
<ChevronRight className="h-3.5 w-3.5 shrink-0 text-muted-foreground/60" />
<BreadcrumbButton onClick={() => setCurrentPath("")}>
<BreadcrumbButton onClick={() => openPath("")}>
Files
</BreadcrumbButton>
</>
@@ -823,7 +835,7 @@ export function RepositoryFilesPanel({
return (
<React.Fragment key={nextPath}>
<ChevronRight className="h-3.5 w-3.5 shrink-0 text-muted-foreground/60" />
<BreadcrumbButton onClick={() => setCurrentPath(nextPath)}>
<BreadcrumbButton onClick={() => openPath(nextPath)}>
{segment}
</BreadcrumbButton>
</React.Fragment>
@@ -896,7 +908,7 @@ export function RepositoryFilesPanel({
const latestCommit = entry.latestCommit;
const rowIsLast = index === visibleEntries.length - 1;
const openEntry = () =>
openRepositoryEntry(entry, setCurrentPath, setSelectedFile);
openRepositoryEntry(entry, openPath, setSelectedFile);
return (
<tr
@@ -957,11 +969,24 @@ export function RepositoryFilesPanel({
</tbody>
</table>
</div>
{entries.length > 200 ? (
<p className="border-border/50 border-t px-4 py-3 text-2xs text-muted-foreground">
Showing the first 200 entries in this folder. Open a folder to narrow
the list.
</p>
{entries.length > visibleEntries.length ? (
<div className="flex items-center justify-between gap-3 border-border/50 border-t px-4 py-3 text-2xs text-muted-foreground">
<span aria-live="polite">
Showing {visibleEntries.length} of {entries.length} entries.
</span>
<button
aria-label={`Show next ${nextEntryCount} entries, ${nextVisibleEntryCount} of ${entries.length} total`}
className="shrink-0 font-medium text-foreground hover:underline"
onClick={() =>
setVisibleEntryCount((current) =>
nextRepositoryEntryLimit(current, entries.length),
)
}
type="button"
>
Show next {nextEntryCount}
</button>
</div>
) : null}
</div>
);