Skip to content

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

Merged
doITmagic merged 2 commits intodevfrom
feat/blade-template-indexing
Mar 18, 2026
Merged

feat(laravel): add Blade Template (.blade.php) semantic indexing#45
doITmagic merged 2 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

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.

@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)
@doITmagic
Copy link
Owner Author

✅ All Review Threads Verified as Resolved

Verified all 3 Copilot review comments against current codebase on feat/blade-template-indexing:

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

  • TotalLines int field added to BladeTemplate (types.go:142)
  • Populated from line count in analyzeFile() (blade.go:131)
  • Used as EndLine in convertBladeToChunks() (adapter.go:300-304), with fallback to 1 for empty files
  • Thread still showing as unresolved on GitHub — needs manual resolve click

2. ✅ Regex patterns fixed (blade.go)

  • All patterns use ([^'"]+) instead of (.+?) (blade.go:15-22)
  • Thread already marked resolved ✅

3. ✅ Log message clarified (enricher.go)

  • Changed to "Enrich: %d chunks before blade analysis" (enricher.go:126)
  • Thread already marked resolved ✅

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

Note: The EndLine thread (#1 above) needs to be manually marked as "Resolve conversation" on GitHub — the fix is confirmed in code.

…dexing

# Conflicts:
#	pkg/parser/php/laravel/adapter.go
#	pkg/parser/php/laravel/blade.go
#	pkg/parser/php/laravel/enricher.go
#	pkg/parser/php/laravel/types.go
Copilot AI review requested due to automatic review settings March 18, 2026 14:12
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 the existing PHP→Laravel enrichment pipeline so Blade directives become searchable symbols/relations in the code graph.

Changes:

  • Introduces a regex-based BladeAnalyzer to extract key Blade directives into BladeTemplate structures.
  • Discovers .blade.php files and converts extracted directives into php.CodeChunk entries with relations/metadata.
  • Integrates Blade enrichment into Enrich() and adds unit tests + Laravel types for Blade templates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/parser/php/laravel/blade.go Blade directive regex extraction + template metadata (name, lines, directives).
pkg/parser/php/laravel/blade_test.go Tests for directive extraction correctness and edge cases.
pkg/parser/php/laravel/types.go Adds Blade-related types and includes them in LaravelInfo.
pkg/parser/php/laravel/adapter.go Discovers Blade files + converts templates into CodeChunk relations/metadata.
pkg/parser/php/laravel/enricher.go Hooks Blade analysis into the Laravel enrich pipeline.

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

Comment on lines +15 to +21
reExtends = regexp.MustCompile(`@extends\(\s*['"]([^'"]+)['"]`)
reSection = regexp.MustCompile(`@section\(\s*['"]([^'"]+)['"]`)
reYield = regexp.MustCompile(`@yield\(\s*['"]([^'"]+)['"]`)
reInclude = regexp.MustCompile(`@include\(\s*['"]([^'"]+)['"]`)
reComponent = regexp.MustCompile(`@component\(\s*['"]([^'"]+)['"]`)
reEach = regexp.MustCompile(`@each\(\s*['"]([^'"]+)['"]`)
rePushStack = regexp.MustCompile(`@(?:push|stack)\(\s*['"]([^'"]+)['"]`)
@doITmagic doITmagic merged commit 52571ac into dev Mar 18, 2026
9 checks passed
@doITmagic doITmagic deleted the feat/blade-template-indexing branch March 18, 2026 14:22
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