Skip to content

feat(wordpress): integrate Oxygen and WooCommerce analyzers into WordPress pipeline#46

Open
doITmagic wants to merge 2 commits intodevfrom
feat/oxygen-woocommerce-integration
Open

feat(wordpress): integrate Oxygen and WooCommerce analyzers into WordPress pipeline#46
doITmagic wants to merge 2 commits intodevfrom
feat/oxygen-woocommerce-integration

Conversation

@doITmagic
Copy link
Owner

Description

Integrate the existing Oxygen Builder and WooCommerce analyzers into the main WordPress parsing pipeline, so that plugin-specific patterns are automatically detected and indexed as enriched CodeChunk objects.

Previously, wordpress/oxygen/analyzer.go and wordpress/woocommerce/analyzer.go existed with passing tests, but were never imported from the main wordpress/analyzer.go. This meant:

  • Oxygen OxyEl classes were parsed as generic PHP classes (no oxy_element metadata)
  • WooCommerce hooks like woocommerce_before_cart were detected as generic wp_hook (no area classification like cart, checkout, product)

What this adds:

  • Oxygen integration — calls oxygenAnalyzer.AnalyzeFromPackages() in analyzeWordPress():
    • oxy_element chunks for classes extending OxyEl / OxyElShadow / OxygenElement
    • oxy_template chunks for ct_template post type registrations
    • Rich metadata: framework=wordpress, wp_type=oxygen_element, namespace, methods, slug
  • WooCommerce integration — calls woocommerceAnalyzer.AnalyzeHooksFromWP():
    • wc_hook chunks with area classification (cart, checkout, product, order, payment, etc.)
    • wc_api_call chunks for WC API functions (wc_get_product, wc_get_order, etc.)
    • Rich metadata: wc_area, hook_type, callback, priority
  • Import cycle resolutionwoocommerce package previously imported wordpress (for WPHook type and ASTHelper), creating a cycle when wordpress imports woocommerce. Resolved by:
    • Defining WPHookInput struct locally in woocommerce package
    • Reimplementing AST helpers (extractHookFromFunctionCall, extractCallArgs, etc.) locally
    • Converting WPHook → WPHookInput at call site in analyzer.go
  • 3 new integration tests:
    • TestAnalyzer_OxygenElementDetection — end-to-end OxyEl detection via AnalyzePaths()
    • TestAnalyzer_WooCommerceHookClassification — end-to-end WC area classification
    • TestConvertToChunks_OxygenAndWooCommerce — nil safety for new fields

Architecture decision:

Implemented as direct integration (Oxygen/WooCommerce analyzers called from wordpress/analyzer.go), not as separate enrichers, because:

  1. Both are conceptual extensions of WordPress — they don't make sense outside WP context
  2. They reuse the same packages/AST already parsed by the WordPress analyzer
  3. Avoids duplicating file walking and PHP parsing

Closes: Trello cards #114-#119

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have formatted my code with go fmt ./...
  • I have run tests go test ./... and they pass
  • I have verified integration with Ollama/Qdrant (if applicable)
  • I have updated the documentation accordingly

Files Changed

File Change
pkg/parser/php/wordpress/types.go Added OxygenInfo any and WooCommerceInfo any fields to WordPressInfo
pkg/parser/php/wordpress/analyzer.go Imported oxygen + woocommerce, added analyzers to struct, integrated calls in analyzeWordPress() and convertToChunks()
pkg/parser/php/wordpress/analyzer_test.go +3 integration tests for Oxygen, WooCommerce, and nil safety
pkg/parser/php/wordpress/woocommerce/analyzer.go Broke import cycle: removed wordpress import, defined WPHookInput, reimplemented AST helpers locally
pkg/parser/php/wordpress/woocommerce/analyzer_test.go Updated TestAnalyzeHooksFromWP to use WPHookInput instead of wordpress.WPHook

razvan added 2 commits March 16, 2026 21:23
… BladeTemplate, BladeSection, BladeInclude types in types.go- Implement BladeAnalyzer with 8 regex extractors for Blade directives (@extends, @section, @yield, @include, @component, @each, @push/@stack, @props)- Add findBladeFiles() for recursive .blade.php discovery- Add convertBladeToChunks() with inheritance/dependency relations- Integrate BladeAnalyzer into Laravel Enrich() pipeline- Add 9 comprehensive unit tests (all passing)Closes: Trello cards #104-#111
- Add OxygenInfo and WooCommerceInfo fields to WordPressInfo struct
- Add oxygen.Analyzer and woocommerce.Analyzer to WordPress Analyzer
- Call Oxygen analyzer in analyzeWordPress() for OxyEl element detection
- Call WooCommerce analyzer for hook classification by area (cart, checkout, product, etc.)
- Convert Oxygen elements/templates and WC hooks/API calls to CodeChunks
- Break import cycle: woocommerce package no longer imports wordpress
  - Define WPHookInput in woocommerce as local mirror of WPHook
  - Reimplement AST helpers locally in woocommerce package
- Add integration tests:
  - TestAnalyzer_OxygenElementDetection (end-to-end OxyEl detection)
  - TestAnalyzer_WooCommerceHookClassification (end-to-end WC area classification)
  - TestConvertToChunks_OxygenAndWooCommerce (nil safety)
Copilot AI review requested due to automatic review settings March 16, 2026 20:12
@doITmagic doITmagic self-assigned this Mar 16, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates existing Oxygen Builder and WooCommerce analyzers into the WordPress parsing pipeline to emit enriched framework-specific CodeChunks; additionally introduces Laravel Blade template parsing/chunking.

Changes:

  • WordPress: call Oxygen/WooCommerce analyzers during analyzeWordPress() and emit oxy_* / wc_* chunks in convertToChunks().
  • WooCommerce: break wordpress import cycle by introducing local WPHookInput and local AST helpers.
  • Laravel: add Blade template analyzer + adapter conversions + tests; update .gitignore.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pkg/parser/php/wordpress/woocommerce/analyzer_test.go Updates WooCommerce hook classification test to use local WPHookInput.
pkg/parser/php/wordpress/woocommerce/analyzer.go Removes wordpress dependency; adds WPHookInput + local AST helpers.
pkg/parser/php/wordpress/types.go Extends WordPressInfo with OxygenInfo / WooCommerceInfo (as any) to avoid cycles.
pkg/parser/php/wordpress/analyzer_test.go Adds WordPress integration tests for Oxygen/WooCommerce + nil-safety check.
pkg/parser/php/wordpress/analyzer.go Wires Oxygen/WooCommerce analyzers into WP pipeline and chunk conversion.
pkg/parser/php/laravel/types.go Adds BladeTemplate types to LaravelInfo.
pkg/parser/php/laravel/enricher.go Runs Blade discovery + Blade analyzer and appends resulting chunks.
pkg/parser/php/laravel/blade_test.go Adds unit tests for Blade directive extraction and view-name formatting.
pkg/parser/php/laravel/blade.go Implements line-oriented Blade directive parser via regexes.
pkg/parser/php/laravel/adapter.go Adds Blade file discovery and template→chunk conversion with relations.
.gitignore Ignores docs/plans/*.md.

You can also share your feedback on Copilot code review. Take the survey.

}
}

logger.Instance.Debug("[LARAVEL] Enrich DONE: returning %d total chunks (before blade)", len(chunks))
Comment on lines +128 to +139
// Analyze Blade Templates
bladeFiles := e.adapter.findBladeFiles(paths)
logger.Instance.Debug("[LARAVEL] Enrich: found %d blade files from paths=%v", len(bladeFiles), paths)
if len(bladeFiles) > 0 {
bladeAnalyzer := NewBladeAnalyzer()
bladeTemplates := bladeAnalyzer.Analyze(bladeFiles)
if len(bladeTemplates) > 0 {
bladeChunks := e.adapter.convertBladeToChunks(bladeTemplates)
logger.Instance.Debug("[LARAVEL] Enrich: %d blade templates → %d chunks", len(bladeTemplates), len(bladeChunks))
chunks = append(chunks, bladeChunks...)
}
}
FilePath: wcHook.FilePath,
StartLine: wcHook.StartLine,
EndLine: wcHook.EndLine,
Signature: fmt.Sprintf("%s('%s', '%s')", wcHook.HookType, wcHook.HookName, wcHook.Callback),
Comment on lines +175 to +179
wcHooks := a.woocommerceAnalyzer.AnalyzeHooksFromWP(wcInputHooks)
if len(wcHooks) > 0 {
wcInfo := &woocommerce.WooCommerceInfo{Hooks: wcHooks}
info.WooCommerceInfo = wcInfo
}
Comment on lines +322 to +345
// extractExprValue extracts a string representation from an expression
func extractExprValue(expr ast.Vertex) string {
if expr == nil {
return ""
}
switch n := expr.(type) {
case *ast.ScalarString:
val := string(n.Value)
if len(val) >= 2 {
val = val[1 : len(val)-1] // Remove quotes
}
return val
case *ast.ScalarLnumber:
return string(n.Value)
case *ast.Name:
var parts []string
for _, part := range n.Parts {
if namePart, ok := part.(*ast.NamePart); ok {
parts = append(parts, string(namePart.Value))
}
}
return strings.Join(parts, "\\")
case *ast.ExprVariable:
if nameNode, ok := n.Name.(*ast.Identifier); ok {
// Compiled regex patterns for Blade directives
var (
reExtends = regexp.MustCompile(`@extends\(\s*['"](.+?)['"]\s*\)`)
reSection = regexp.MustCompile(`@section\(\s*['"](.+?)['"]\s*\)`)
Comment on lines +300 to +316
chunk := php.CodeChunk{
Name: tpl.Name,
Type: "blade_template",
Language: "php",
FilePath: tpl.FilePath,
StartLine: 1,
Signature: sig,
Docstring: docstring,
Metadata: map[string]any{
"framework": "laravel",
"blade": true,
"sections_count": len(tpl.Sections),
"includes_count": len(tpl.Includes),
},
Relations: relations,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants