Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTypes = map[string][]string{
"go": {"*.go"},
"js": {"*.js", "*.mjs", "*.cjs"},
"ts": {"*.ts", "*.tsx", "*.mts", "*.cts"},
"py": {"*.py", "*.pyi", "*.pyw"},
"python": {"*.py", "*.pyi", "*.pyw"},
"rust": {"*.rs"},
"c": {"*.c", "*.h"},
"cpp": {"*.cc", "*.cpp", "*.cxx", "*.hh", "*.hpp", "*.hxx"},
"java": {"*.java"},
"kotlin": {"*.kt", "*.kts"},
"swift": {"*.swift"},
"cs": {"*.cs"},
"csharp": {"*.cs"},
"json": {"*.json"},
"yaml": {"*.yml", "*.yaml"},
"toml": {"*.toml"},
"xml": {"*.xml", "*.xsd", "*.xsl"},
"html": {"*.html", "*.htm"},
"css": {"*.css", "*.scss", "*.sass", "*.less"},
"sh": {"*.sh", "*.bash", "*.zsh", "*.fish"},
"bash": {"*.sh", "*.bash"},
"sql": {"*.sql"},
"proto": {"*.proto"},
"md": {"*.md", "*.markdown", "*.mkd"},
"markdown": {"*.md", "*.markdown"},
"rb": {"*.rb"},
"ruby": {"*.rb"},
"php": {"*.php"},
"lua": {"*.lua"},
"docker": {"*Dockerfile*", "*.dockerfile"},
"makefile": {"Makefile", "GNUmakefile", "*.mk"},
"cmake": {"CMakeLists.txt", "*.cmake"},
"tf": {"*.tf", "*.tfvars"},
"terraform": {"*.tf", "*.tfvars"},
"gradle": {"*.gradle", "*.gradle.kts"},
"nim": {"*.nim", "*.nims"},
"zig": {"*.zig"},
"dart": {"*.dart"},
"elixir": {"*.ex", "*.exs"},
"clojure": {"*.clj", "*.cljc", "*.cljs"},
"scala": {"*.scala", "*.sc"},
"haskell": {"*.hs", "*.lhs"},
"r": {"*.r", "*.R"},
}
DefaultTypes maps type names (as used in --type flag) to glob patterns. Ported from ripgrep's crates/ignore/src/default_types.rs
Functions ¶
func CountMatches ¶
CountMatches returns the number of matching lines in a file.
func TypeToGlobs ¶
TypeToGlobs returns the glob patterns for a given type name. Returns nil, false if the type is not found.
Types ¶
type FileMatch ¶
type FileMatch struct {
Path string
ModTime time.Time
Lines []LineMatch // empty for file-only searches
Count int // for OutputModeCount
}
FileMatch is a file that matched a search query.
func SearchFiles ¶
SearchFiles walks rootPath and returns matching files, sorted by modification time (newest first).
type IgnoreMatcher ¶
type IgnoreMatcher struct {
// contains filtered or unexported fields
}
IgnoreMatcher holds compiled ignore patterns from one or more ignore files. Patterns are applied in order; last match wins (like git).
func LoadIgnoreFiles ¶
func LoadIgnoreFiles(rootPath string) (*IgnoreMatcher, error)
LoadIgnoreFiles loads .gitignore and .pandoignore files starting from rootPath and walking up to the filesystem root. Returns an IgnoreMatcher with all patterns.
type LineMatch ¶
type LineMatch struct {
LineNum int
Text string
IsContext bool // true = context line, false = actual match
}
LineMatch is a single matched or context line from a search.
func SearchFile ¶
SearchFile searches a single file and returns matched lines. Returns nil, nil if the file is binary or has no matches.
type OutputMode ¶
type OutputMode string
OutputMode controls what the searcher returns.
const ( OutputModeContent OutputMode = "content" // matched lines + context OutputModeFiles OutputMode = "files_with_matches" // just file paths OutputModeCount OutputMode = "count" // count per file )
type SearchOptions ¶
type SearchOptions struct {
Pattern *regexp.Regexp
OutputMode OutputMode
BeforeCtx int // lines of before-context (-B)
AfterCtx int // lines of after-context (-A)
Multiline bool // match across lines (load whole file)
}
SearchOptions configures a content search operation.
type WalkOptions ¶
type WalkOptions struct {
RootPath string
Pattern *regexp.Regexp // nil = list files only (no content search)
IncludeGlob string // file name glob, e.g. "*.go"
TypeFilter string // type name, e.g. "go" (expands via DefaultTypes)
IgnoreMatcher *IgnoreMatcher // nil = no ignore filtering
SearchOpts SearchOptions
MaxResults int // 0 = unlimited
Concurrency int // 0 = runtime.NumCPU()
}
WalkOptions configures a file walk and optional content search.