Monorepo for Tangled
tangled.org
1package models
2
3import (
4 "github.com/bluesky-social/indigo/atproto/syntax"
5 "github.com/sourcegraph/zoekt"
6)
7
8// Result is a single matched file. A zoekt FileMatch is either a filename
9// match or a set of content matches, never both: File is set for the former,
10// Chunks for the latter.
11type Result struct {
12 RepoDID syntax.DID
13 FilePath string
14 Branches []string // branch names
15 Commit string // commit id
16 Language string
17
18 File *Result_FileMatch // set for a filename match
19 Chunks []Result_ChunkMatch // set for content matches
20}
21
22type Result_FileMatch struct {
23 // Ranges are the matched span(s) within FilePath. LineNumber is always 1 for
24 // filename matches; Column is 1-based and in runes.
25 Ranges []zoekt.Range
26}
27
28type Result_ChunkMatch struct {
29 // Content is a contiguous run of complete lines that fully contains Ranges.
30 Content string
31 // ContentStartLine is the 1-based line number of Content's first line.
32 ContentStartLine int
33 // Ranges are the matched span(s) within the file. LineNumber/Column are
34 // 1-based, Column is in runes. A Range may span multiple lines.
35 Ranges []zoekt.Range
36}
37
38// IsFileMatch tells if search result is from file-name match
39func (r *Result) IsFileMatch() bool {
40 return r.File != nil
41}
42
43// IsChunkMatch tells if search result is from chunk match
44func (r *Result) IsChunkMatch() bool {
45 return len(r.Chunks) > 0
46}