MCPcopy Create free account
hub / github.com/github/gh-aw / processIncludesWithVisited

Function processIncludesWithVisited

pkg/parser/include_processor.go:21–57  ·  view source on GitHub ↗

processIncludesWithVisited processes import directives with cycle detection

(content, baseDir string, extractTools bool, visited map[string]struct {
})

Source from the content-addressed store, hash-verified

19
20// processIncludesWithVisited processes import directives with cycle detection
21func processIncludesWithVisited(content, baseDir string, extractTools bool, visited map[string]struct {
22}) (string, error) {
23 if fastResult, fastPath := fastPathForNoIncludes(content, extractTools); fastPath {
24 return fastResult, nil
25 }
26
27 scanner := bufio.NewScanner(strings.NewReader(content))
28 var result bytes.Buffer
29
30 for scanner.Scan() {
31 line := scanner.Text()
32
33 // Parse import directive
34 directive := ParseImportDirective(line)
35 if directive != nil {
36 includedContent, shouldSkip, err := processIncludeDirectiveWithVisited(directive, baseDir, extractTools, visited)
37 if err != nil {
38 return "", err
39 }
40 if shouldSkip {
41 continue
42 }
43 if extractTools {
44 result.WriteString(includedContent + "\n")
45 } else {
46 result.WriteString(includedContent)
47 }
48 } else {
49 // Regular line, just pass through (unless extracting tools)
50 if !extractTools {
51 result.WriteString(line + "\n")
52 }
53 }
54 }
55
56 return result.String(), nil
57}
58
59func fastPathForNoIncludes(content string, extractTools bool) (string, bool) {
60 // Fast path: skip scanner allocation when no include/import directives are present.

Callers 2

Calls 4

fastPathForNoIncludesFunction · 0.85
ParseImportDirectiveFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected