Skip to content

ctf0/vscode-blade-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blade Parser

VS Code extension that brings language intelligence to Laravel Blade templates (.blade.php).

Features

All standard VS Code language features enabled for Blade files

  • Go to Definition — jump to class/method/function definitions from Blade
  • Find References — locate all references to a symbol across the project
  • Hover — type signatures and docblocks on hover
  • Document Symbols — outline and breadcrumb navigation for PHP symbols
  • Reference CodeLens — see reference counts above classes, functions, methods, properties, enums

Requirements

  • intelephense (bmewburn.vscode-intelephense-client)
  • PHP 8.x with the php binary available (or configured via bladeParser.phpCommand)

PHP rename support

PHP renames are delegated to Intelephense. Blade Parser adds matching edits to Blade files without duplicating the PHP edits already returned by Intelephense.

Blade files are searched with the intelephense.rename.exclude patterns, so paths such as vendor can be excluded from Blade rename updates.

Known conflicts

If you use TypeLens, exclude the Blade language to avoid duplicate codelens:

"typelens.skiplanguages": [
    // ...,
    "blade"
],

to have better support for variables in blade, you have 2 ways

1 : use @var comment

@foreach ($users as $user)
    {{-- @var \App\Models\User $user --}}
    @if ($user->isActive)
        // ..
    @endif
@endforeach

2 : use assertion

  • add global function

    use Webmozart\Assert\Assert;
    
    if (! \function_exists('_is')) {
        /**
         * @template T of object
         *
         * @param  class-string<T>  $type
         *
         * @return T
         */
        function _is(object $obj, string $type): object
        {
            return Assert::isInstanceOf($obj, $type);
        }
    }
  • now use it like so

    @foreach ($users as $user)
        @if (_is($user, \App\Models\User::class)->isActive)
            // ..
        @endif
    @endforeach

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages