import { Link } from "@tanstack/react-router"; import { EmptyState } from "./ui/Primitives"; import { SNIPPET_CLOSE, SNIPPET_OPEN } from "~/lib/code-intel"; import type { CodeSearchHit } from "~/lib/code-intel"; type Segment = { offset: number; text: string; marked: boolean }; function segments(text: string): Segment[] { const out: Segment[] = []; let offset = 0; for (const [position, part] of text.split(SNIPPET_OPEN).entries()) { const [marked, rest] = position === 0 ? ["", part] : [part.split(SNIPPET_CLOSE)[0] ?? "", part.split(SNIPPET_CLOSE)[1] ?? ""]; if (marked) out.push({ offset, text: marked, marked: true }); offset += marked.length + 1; if (rest) out.push({ offset, text: rest, marked: false }); offset += rest.length + 1; } return out; } function Snippet({ text }: { text: string }) { return (
      {segments(text).map((segment) =>
        segment.marked ? (
          
            {segment.text}
          
        ) : (
          {segment.text}
        ),
      )}
    
); } export function CodeSearchResults({ hits, showRepo, empty, }: { hits: CodeSearchHit[]; showRepo: boolean; empty: string; }) { if (hits.length === 0) return ; return ( ); }