Skip to content

feat(laravel): add Blade Template (.blade.php) semantic indexing#45

Open
doITmagic wants to merge 3 commits intodevfrom
feat/blade-template-indexing
Open

feat(laravel): add Blade Template (.blade.php) semantic indexing#45
doITmagic wants to merge 3 commits intodevfrom
feat/blade-template-indexing

Conversation

@doITmagic
Copy link
Owner

Description

Add semantic indexing for Laravel Blade templates (.blade.php), extracting structural directives as symbols with inheritance and dependency relations in the Code Graph.

Previously, .blade.php files were accepted by the PHP parser (CanHandle() returns true for anything ending in .php), but only PHP constructs (classes, functions) were extracted. All Blade-specific directives (@extends, @section, @yield, @include, @component, etc.) were completely ignored, making Blade templates invisible to semantic search.

What this adds:

  • BladeAnalyzer — regex-based parser for 8 Blade directives:
    • @extends → inheritance relations
    • @section / @yield → section symbols
    • @include / @component / @each → dependency relations
    • @push / @stack → stack tracking
    • @props → component property extraction
  • findBladeFiles() — recursive .blade.php file discovery with vendor/node_modules exclusion
  • convertBladeToChunks() — converts templates to CodeChunk with:
    • Type: blade_template
    • Structural relations (RelInheritance for @extends, RelDependency for @include/@component)
    • Rich metadata (framework, sections count, includes count, stacks, props)
    • Auto-generated docstrings from directive summaries
  • Integration into the existing Laravel Enrich() pipeline — follows the same FrameworkEnricher pattern as Routes/Eloquent/Migrations
  • bladeViewName() — converts file paths to Laravel dot notation (e.g., resources/views/layouts/app.blade.phplayouts.app)
  • 3 new types: BladeTemplate, BladeSection, BladeInclude in types.go
  • 9 comprehensive unit tests covering all directives, edge cases (empty files, nonexistent files), complex templates, and view name conversion

Architecture decision:

Implemented as a Laravel enricher extension (not a separate parser), because:

  1. .blade.php already passes PHP CanHandle() — no new parser registration needed
  2. Blade is strictly a Laravel feature — it fits naturally in pkg/parser/php/laravel/
  3. Directives are plain text patterns — regex is sufficient (no AST needed)
  4. Follows the established FrameworkEnricher pattern used by Routes/Eloquent/Migrations

Closes: Trello cards #104-#111

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/laravel/blade.go NEW — BladeAnalyzer with 8 regex extractors
pkg/parser/php/laravel/blade_test.go NEW — 9 unit tests
pkg/parser/php/laravel/types.go Added BladeTemplate, BladeSection, BladeInclude types + BladeTemplates field in LaravelInfo
pkg/parser/php/laravel/adapter.go Added findBladeFiles() + convertBladeToChunks()
pkg/parser/php/laravel/enricher.go Integrated Blade analysis into Enrich() pipeline

… 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
Copilot AI review requested due to automatic review settings March 16, 2026 19:36
@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

Adds Laravel Blade (.blade.php) semantic indexing to make Blade templates and directives discoverable in semantic search/code graph, integrated into the existing PHP→Laravel enricher pipeline.

Changes:

  • Introduces a regex-based BladeAnalyzer to extract key Blade directives and template metadata.
  • Discovers .blade.php files and converts parsed templates into php.CodeChunk entries with relations/metadata.
  • Integrates Blade analysis into the Laravel Enrich() pipeline and adds unit tests + new Laravel types.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/parser/php/laravel/blade.go New Blade directive analyzer + view-name/path helpers
pkg/parser/php/laravel/blade_test.go Unit tests for directive extraction and view-name conversion
pkg/parser/php/laravel/types.go Adds Blade-related types and BladeTemplates to LaravelInfo
pkg/parser/php/laravel/adapter.go Adds Blade file discovery + conversion to CodeChunk with relations/metadata
pkg/parser/php/laravel/enricher.go Runs Blade analysis during Laravel enrichment and appends Blade chunks

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

Comment on lines +300 to +307
chunk := php.CodeChunk{
Name: tpl.Name,
Type: "blade_template",
Language: "php",
FilePath: tpl.FilePath,
StartLine: 1,
Signature: sig,
Docstring: docstring,
- 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)
@doITmagic
Copy link
Owner Author

Review Comments Addressed

All 3 Copilot review comments have been fixed:

1. ✅ Regex patterns — capture only first quoted argument (blade.go)

Changed .+?[^'"]+ and removed trailing \s*\). The lazy (.+?) was expanding through commas in multi-argument forms like @section('title', 'Dashboard'), capturing title', 'Dashboard instead of just title. Tests strengthened with value assertions.

2. ✅ Log message clarified (enricher.go)

Renamed "Enrich DONE: returning N total chunks (before blade)""Enrich: N chunks before blade analysis". The "DONE" label was misleading since blade analysis hadn't run yet.

3. ✅ EndLine populated (adapter.go + types.go)

Added TotalLines int field to BladeTemplate, populated from line count in analyzeFile(). Used as EndLine in convertBladeToChunks(), with fallback to 1 for empty files.

All tests pass (go test ./pkg/parser/php/... — 5 packages OK).

- Fix regex patterns: changed (.+?) to ([^'"]+) to capture only the
  first quoted argument in multi-arg directives like @section('title', 'Dashboard')
- Add EndLine to blade CodeChunks via new BladeTemplate.TotalLines field
- Fix misleading 'Enrich DONE' log that appeared before blade analysis
- Strengthen tests with value assertions (section names, view names, TotalLines)
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