-
Notifications
You must be signed in to change notification settings - Fork 4
feat(wordpress): integrate Oxygen and WooCommerce analyzers into WordPress pipeline #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1cf637b
feat(laravel): add Blade Template (.blade.php) semantic indexing- Add…
059ffee
feat: integrate Oxygen and WooCommerce analyzers into WordPress pipeline
4cbac50
fix: address PR #46 review comments (6 fixes)
9c34e57
ci: update Go version from 1.22 to 1.24 to match go.mod
cea9f98
fix: address PR #46 review round 2 (5 fixes)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ Thumbs.db | |
| # Temporary files | ||
| tmp/ | ||
| temp/ | ||
| docs/plans/*.md | ||
|
|
||
| # Scripts | ||
| scripts/ | ||
|
|
||
This file contains hidden or 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 hidden or 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,181 @@ | ||
| package laravel | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "os" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "github.com/doITmagic/rag-code-mcp/internal/logger" | ||
| ) | ||
|
|
||
| // Compiled regex patterns for Blade directives | ||
| var ( | ||
| reExtends = regexp.MustCompile(`@extends\(\s*['"](.+?)['"]\s*\)`) | ||
| reSection = regexp.MustCompile(`@section\(\s*['"](.+?)['"]\s*(?:,.*?)?\)`) | ||
| reYield = regexp.MustCompile(`@yield\(\s*['"](.+?)['"]\s*\)`) | ||
| reInclude = regexp.MustCompile(`@include\(\s*['"](.+?)['"]\s*\)`) | ||
| reComponent = regexp.MustCompile(`@component\(\s*['"](.+?)['"]\s*\)`) | ||
| reEach = regexp.MustCompile(`@each\(\s*['"](.+?)['"]\s*\)`) | ||
| rePushStack = regexp.MustCompile(`@(?:push|stack)\(\s*['"](.+?)['"]\s*\)`) | ||
| reProps = regexp.MustCompile(`@props\(\s*\[(.*?)\]\s*\)`) | ||
| ) | ||
|
|
||
| // BladeAnalyzer parses Blade template files and extracts directives. | ||
| type BladeAnalyzer struct{} | ||
|
|
||
| // NewBladeAnalyzer creates a new BladeAnalyzer. | ||
| func NewBladeAnalyzer() *BladeAnalyzer { | ||
| return &BladeAnalyzer{} | ||
| } | ||
|
|
||
| // Analyze parses the given Blade template files, extracting directives. | ||
| // Files that cannot be read are logged and skipped (no error returned). | ||
| func (ba *BladeAnalyzer) Analyze(filePaths []string) []BladeTemplate { | ||
| var templates []BladeTemplate | ||
|
|
||
| for _, fp := range filePaths { | ||
| tpl, err := ba.analyzeFile(fp) | ||
| if err != nil { | ||
| logger.Instance.Debug("[BLADE] skip %s: %v", filepath.Base(fp), err) | ||
| continue | ||
| } | ||
| templates = append(templates, tpl) | ||
| } | ||
|
|
||
| return templates | ||
| } | ||
|
|
||
| // analyzeFile parses a single Blade file. | ||
| func (ba *BladeAnalyzer) analyzeFile(filePath string) (BladeTemplate, error) { | ||
| f, err := os.Open(filePath) | ||
| if err != nil { | ||
| return BladeTemplate{}, err | ||
| } | ||
| defer f.Close() | ||
|
|
||
| tpl := BladeTemplate{ | ||
| Name: bladeViewName(filePath), | ||
| FilePath: filePath, | ||
| } | ||
|
|
||
| scanner := bufio.NewScanner(f) | ||
| scanner.Buffer(make([]byte, 64*1024), 1024*1024) // Allow lines up to 1MB | ||
| lineNum := 0 | ||
| for scanner.Scan() { | ||
| lineNum++ | ||
| line := scanner.Text() | ||
doITmagic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // @extends | ||
| if m := reExtends.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Extends = m[1] | ||
| } | ||
|
|
||
| // @section | ||
| if m := reSection.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Sections = append(tpl.Sections, BladeSection{ | ||
| Name: m[1], | ||
| Type: "section", | ||
| StartLine: lineNum, | ||
| }) | ||
| } | ||
|
|
||
| // @yield | ||
| if m := reYield.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Sections = append(tpl.Sections, BladeSection{ | ||
| Name: m[1], | ||
| Type: "yield", | ||
| StartLine: lineNum, | ||
| }) | ||
| } | ||
|
|
||
| // @include | ||
| if m := reInclude.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Includes = append(tpl.Includes, BladeInclude{ | ||
| ViewName: m[1], | ||
| Type: "include", | ||
| Line: lineNum, | ||
| }) | ||
| } | ||
|
|
||
| // @component | ||
| if m := reComponent.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Includes = append(tpl.Includes, BladeInclude{ | ||
| ViewName: m[1], | ||
| Type: "component", | ||
| Line: lineNum, | ||
| }) | ||
| } | ||
|
|
||
| // @each | ||
| if m := reEach.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Includes = append(tpl.Includes, BladeInclude{ | ||
| ViewName: m[1], | ||
| Type: "each", | ||
| Line: lineNum, | ||
| }) | ||
| } | ||
|
|
||
| // @push / @stack | ||
| if m := rePushStack.FindStringSubmatch(line); len(m) > 1 { | ||
| tpl.Stacks = appendUnique(tpl.Stacks, m[1]) | ||
| } | ||
|
|
||
| // @props | ||
| if m := reProps.FindStringSubmatch(line); len(m) > 1 { | ||
| props := parsePropsArray(m[1]) | ||
| tpl.Props = append(tpl.Props, props...) | ||
| } | ||
| } | ||
|
|
||
| tpl.TotalLines = lineNum | ||
|
|
||
| return tpl, scanner.Err() | ||
| } | ||
|
|
||
| // bladeViewName converts a file path to Laravel dot notation. | ||
| // Example: /project/resources/views/layouts/app.blade.php → layouts.app | ||
| func bladeViewName(filePath string) string { | ||
| // Normalize to forward slashes | ||
| fp := filepath.ToSlash(filePath) | ||
|
|
||
| // Try to find resources/views/ in the path | ||
| marker := "resources/views/" | ||
| idx := strings.LastIndex(fp, marker) | ||
| if idx >= 0 { | ||
| relative := fp[idx+len(marker):] | ||
| // Remove .blade.php extension | ||
| relative = strings.TrimSuffix(relative, ".blade.php") | ||
| return strings.ReplaceAll(relative, "/", ".") | ||
| } | ||
|
|
||
| // Fallback: use basename without extension | ||
| base := filepath.Base(filePath) | ||
| return strings.TrimSuffix(base, ".blade.php") | ||
| } | ||
|
|
||
| // parsePropsArray extracts prop names from a @props([...]) content string. | ||
| // Input: "'title', 'color'" → Output: ["title", "color"] | ||
| func parsePropsArray(raw string) []string { | ||
| var props []string | ||
| parts := strings.Split(raw, ",") | ||
| for _, p := range parts { | ||
| p = strings.TrimSpace(p) | ||
| p = strings.Trim(p, "'\"") | ||
| if p != "" { | ||
| props = append(props, p) | ||
| } | ||
| } | ||
| return props | ||
| } | ||
|
|
||
| // appendUnique appends s to slice only if not already present. | ||
| func appendUnique(slice []string, s string) []string { | ||
| for _, existing := range slice { | ||
| if existing == s { | ||
| return slice | ||
| } | ||
| } | ||
| return append(slice, s) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.