spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / views / detail / placeholder-of / placeholder-of.ts
45 lines · 1.1 KBRaw
1import type { DetailModel } from '../detail-model'
2import { SAFE_PATHSPEC_PATTERN } from './safe-pathspec-pattern'
3
4/**
5 * The dim italic lines drawn instead of hunks (DiffDetailView's wording),
6 * or null when the hunks draw.
7 *
8 * Untracked (the backend's note, its pasteable command only for a name of
9 * letters, digits and `._/@+-`), binary, loading, unreadable, large, or
10 * empty.
11 *
12 * @param detail the file
13 * @returns the lines, or null
14 */
15export function placeholderOf(detail: DetailModel): readonly string[] | null {
16 if (detail.isUntracked) {
17 return detail.words.untrackedNoteOf(
18 detail.path,
19 SAFE_PATHSPEC_PATTERN.test(detail.path),
20 )
21 }
22
23 if (detail.isBinary) {
24 return ['Binary file - cannot display diff']
25 }
26
27 if (detail.body === undefined) {
28 return ['Loading diff…']
29 }
30
31 if (detail.body === null) {
32 return ['Diff unavailable']
33 }
34
35 const { isLarge, hunks } = detail.body
36 const isEmpty = hunks.length === 0
37
38 const note = isLarge
39 ? 'Large file - diff exceeds 1 MB limit'
40 : isEmpty
41 ? 'No diff content'
42 : null
43
44 return note ? [note] : null
45}