11package main
22
3- // import (
4- // "fmt"
5- // "regexp"
6- // "strings"
7- // )
83import (
94 "bufio"
105 "fmt"
@@ -83,26 +78,20 @@ type DiffAnalyzer struct {
8378}
8479
8580
86-
87- // Supported file extensions for code analysis
8881var relevantExtensions = []string {".go" , ".c" , ".cpp" , ".py" , ".js" , ".ts" , ".tsx" , ".jsx" }
8982
90- // Regex patterns for code analysis
9183var (
9284 importRegex = regexp .MustCompile (`(?i)\b(import|include|from|require)\b.*` )
9385 functionRegex = regexp .MustCompile (`(?i)\b(func|def|function)\s+[a-zA-Z_][a-zA-Z0-9_]*\s*\(` )
9486 variableRegex = regexp .MustCompile (`(?i)\b(var|let|const|[a-zA-Z_][a-zA-Z0-9_]*\s*(:?=|:))` )
9587)
96-
97- // CodeEssence represents the essential elements extracted from a code file
9888type CodeEssence struct {
9989 FilePath string `json:"filePath"`
10090 Imports []string `json:"imports,omitempty"`
10191 Functions []string `json:"functions,omitempty"`
10292 Variables []string `json:"variables,omitempty"`
10393}
10494
105- // ExtractEssenceFromFile analyzes a single file and extracts its code essence
10695func ExtractEssenceFromFile (filePath string ) (* CodeEssence , error ) {
10796 file , err := os .Open (filePath )
10897 if err != nil {
@@ -122,12 +111,10 @@ func ExtractEssenceFromFile(filePath string) (*CodeEssence, error) {
122111 for scanner .Scan () {
123112 line := strings .TrimSpace (scanner .Text ())
124113
125- // Skip empty lines and comments
126114 if line == "" || strings .HasPrefix (line , "//" ) {
127115 continue
128116 }
129117
130- // Handle multiline comments
131118 if strings .HasPrefix (line , "/*" ) {
132119 multilineComment = true
133120 continue
@@ -138,8 +125,6 @@ func ExtractEssenceFromFile(filePath string) (*CodeEssence, error) {
138125 }
139126 continue
140127 }
141-
142- // Extract code elements
143128 switch {
144129 case importRegex .MatchString (line ):
145130 essence .Imports = append (essence .Imports , line )
@@ -157,7 +142,6 @@ func ExtractEssenceFromFile(filePath string) (*CodeEssence, error) {
157142 return essence , nil
158143}
159144
160- // SearchDirectory recursively searches a directory for relevant code files
161145func SearchDirectory (root string ) ([]* CodeEssence , error ) {
162146 var results []* CodeEssence
163147
0 commit comments