Skip to content

Commit

Permalink
fix: Skip region included context lines (+-4 lines)
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed Dec 5, 2024
1 parent 19edddd commit 9930826
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/fleccs/fleccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Query struct {
Filename string
StartL, EndL int

enlargedContext int
contextStartLine int
contextEndLine int
contextLineLengths []int
Expand Down Expand Up @@ -64,6 +65,7 @@ func (q *Query) calculateContextLines(c *config, queryTree domain.Searcher) erro
queryFileStrLines := files.Lines(queryFileContent)
queryFileLines := ds.Map(queryFileStrLines, func(l string) []byte { return []byte(l) })

q.enlargedContext = c.contextLines
q.contextStartLine = max(1, q.StartL-c.contextLines) // inclusive, 1-indexed
q.contextEndLine = min(len(queryFileLines), q.EndL+c.contextLines) // inclusive, 1-indexed

Expand Down Expand Up @@ -128,6 +130,7 @@ func findCandidates(
) []*Candidate {
var candidates []*Candidate
windowSize := len(q.contextBigrams)
orgWindowSize := windowSize - q.enlargedContext

if len(searchFileBigrams) < windowSize {
// If the search target file is shorter than the query lines (including context)
Expand All @@ -138,9 +141,9 @@ func findCandidates(
startLine := i // 0-indexed, inclusive
endLine := i + windowSize // 0-indexed, exclusive

// Check if this region is skipped
if canSkip, skipUntil := ignoreRule.CanSkip(i, windowSize); canSkip {
i = skipUntil
// Check if this (original) region can be skipped
if canSkip, skipUntil := ignoreRule.CanSkip(i+q.enlargedContext, orgWindowSize); canSkip {
i = skipUntil - q.enlargedContext
continue
}

Expand Down

0 comments on commit 9930826

Please sign in to comment.