Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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
  • Reference Rename — update reference on rename

Requirements

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

Docker if you are going to use docker make sure to include -i in your command, ex.docker exec -i <app-image-name> php

Known conflicts

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

    "typelens.skiplanguages": [
        // ...,
        "blade"
    ],
  2. ext will set intelephense.codeLens.references.enable to false to avoid duplicate code lens in php as we override it to show references in blade files aswell.

Better support for variables (use any/both)

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

why u might use both ?

so you dont have to rewrite

@php
    // from
    $serverErrors = collect($errors->getBags())
        ->flatMap(fn($bag) => $bag->messages())
        ->toArray();

    // to
    $serverErrors = collect($errors->getBags())
        ->flatMap(function($bag) {
            /** @var \Illuminate\Support\MessageBag $bag */
            return $bag->messages();
        })
        ->toArray();

    // instead
    $serverErrors = collect($errors->getBags())
        ->flatMap(fn($bag) => _is($bag, \Illuminate\Support\MessageBag::class)->messages())
        ->toArray();
@endphp

for complex variables, use @see

use @see the same way you use it in php files to jump a class/method

{{-- @see \App\Models\User::isVerified() --}}
// or
{{-- @see \App\View\Composers\UserComposer::compose() --}}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages