MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / scanFileForMatch

Function scanFileForMatch

agent/utils/files/ai_content_search.go:131–160  ·  view source on GitHub ↗
(absPath string, match func(string) bool, maxPerFile, maxTextRunes int)

Source from the content-addressed store, hash-verified

129}
130
131func scanFileForMatch(absPath string, match func(string) bool, maxPerFile, maxTextRunes int) ([]FileAIContentHit, error) {
132 f, err := os.Open(absPath)
133 if err != nil {
134 return nil, err
135 }
136 defer f.Close()
137
138 scanner := bufio.NewScanner(f)
139 buf := make([]byte, 0, 64*1024)
140 scanner.Buffer(buf, 1024*1024)
141
142 var out []FileAIContentHit
143 lineNo := 0
144 for scanner.Scan() {
145 lineNo++
146 if len(out) >= maxPerFile {
147 break
148 }
149 line := scanner.Text()
150 if !match(line) {
151 continue
152 }
153 out = append(out, FileAIContentHit{
154 Path: absPath,
155 Line: lineNo,
156 Text: truncateHitLine(line, maxTextRunes),
157 })
158 }
159 return out, scanner.Err()
160}
161
162func truncateHitLine(s string, maxRunes int) string {
163 if maxRunes <= 0 {

Callers 1

SearchFileAIContentHitsFunction · 0.85

Calls 3

truncateHitLineFunction · 0.85
CloseMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected