-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ignoring files via .cpeignore
Introduced the ability to ignore files during code map generation, type resolution, and system message building by loading patterns from a .cpeignore file. Integrated the glob library for pattern matching and updated the related functions to consider these ignore rules.
- Loading branch information
1 parent
2e35e57
commit 43d91e0
Showing
6 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ignore | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/gobwas/glob" | ||
) | ||
|
||
type IgnoreRules struct { | ||
patterns []glob.Glob | ||
} | ||
|
||
func NewIgnoreRules() *IgnoreRules { | ||
return &IgnoreRules{ | ||
patterns: []glob.Glob{}, | ||
} | ||
} | ||
|
||
func (ir *IgnoreRules) LoadIgnoreFile(startDir string) error { | ||
ignoreFile := findIgnoreFile(startDir) | ||
if ignoreFile == "" { | ||
return nil // No .cpeignore file found, which is okay | ||
} | ||
|
||
file, err := os.Open(ignoreFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
pattern := strings.TrimSpace(scanner.Text()) | ||
if pattern != "" && !strings.HasPrefix(pattern, "#") { | ||
g, err := glob.Compile(pattern) | ||
if err != nil { | ||
return err | ||
} | ||
ir.patterns = append(ir.patterns, g) | ||
} | ||
} | ||
|
||
return scanner.Err() | ||
} | ||
|
||
func (ir *IgnoreRules) ShouldIgnore(path string) bool { | ||
for _, pattern := range ir.patterns { | ||
if pattern.Match(path) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func findIgnoreFile(startDir string) string { | ||
dir := startDir | ||
for { | ||
ignoreFile := filepath.Join(dir, ".cpeignore") | ||
if _, err := os.Stat(ignoreFile); err == nil { | ||
return ignoreFile | ||
} | ||
parent := filepath.Dir(dir) | ||
if parent == dir { | ||
break | ||
} | ||
dir = parent | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters