vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Support for "Laravel Blade" language mode

Open 7twin opened this issue 7 years ago • 30 comments
trafficstars

It would be nice to be able to activate intelephense for other language modes than "php", especially for laravels .blade.php template files, with the "Laravel Blade" language mode selected: https://github.com/onecentlin/laravel-blade-snippets-vscode#blade-syntax-hightlight

7twin avatar Apr 27 '18 00:04 7twin

Can you mix php and blade syntax? If not then I dont think this extension would be useful. HTML/CSS/JS suggestions come from the HTML language server. This extension just forwards requests on in this scenario.

bmewburn avatar Jun 25 '18 07:06 bmewburn

The only thing that keeps me from using VSCode full time is intellisense in blade.php files. In blade you can do this

@php
  echo 'some_stuff and ' . $some_var;
@endphp

Also

{{ a_function_which_returns_something() ? 'this' : 'that' }}

So intellisense inside blade files is essential. (btw I'm using blade syntax with Wordpress and Woocommerce too and its a total nightmare, countless business logic inside the views and ends up in a mixed hell)

Thanks for your awesome work!

cpouldev avatar Jun 26 '18 14:06 cpouldev

@hambos22 What IDE are you using that supports this natively?

7twin avatar Jun 26 '18 14:06 7twin

@bmewburn In blade templates you can mix php, blade syntax and html too

7twin avatar Jun 26 '18 14:06 7twin

@7twin PHPStorm

cpouldev avatar Jun 26 '18 14:06 cpouldev

Just tried this plugin for the first time, and was able to leverage a lot of it in blade files by associating blade files with php in my settings.

"files.associations": {
  "*.blade.php": "php"
},

Unfortunately, this causes me to lose all the blade specific syntax highlighting I had with the laravel-blade, which actually configures a 'blade' language. If these two plugins could work together that'd be perfect.

dev-nicolaos avatar Feb 09 '19 00:02 dev-nicolaos

Happy to see this being added as an enhancement, it's a shame we can't currently use this in blade files because it's the best php lang sever, no other comes close.

Great work @bmewburn

ghost avatar Mar 09 '19 11:03 ghost

Embed var

<div>
{{$var}}
</div>
<div>
{{$var + $var2}}
</div>

Embed method call

<div>
{{$obj->method() + $obj->method("argument, could be var")}}
</div>

Condition

@if (true)
<div></div>
@endif
@if ($obj->method())
<div></div>
@endif

...

xiaohuilam avatar Aug 31 '19 07:08 xiaohuilam

Is this feature avilable now? I've tried to make them work with no luck. And there is not much about this topic in the internet as well.

prpdl avatar Apr 17 '20 01:04 prpdl

There's a similar issue with JavaScript in blade templates that I'm currently puzzling over the best approach to solving. VSCode probably needs to add support for multiple languages per file extension, but I'm not sure how feasible this is. The blade extension probably needs to support all those possibilities too, but given a blade template could be used on any language, that feels like something outside of its responsibility too.

Deji69 avatar Jun 14 '20 10:06 Deji69

Can you mix php and blade syntax? If

@bmewburn yes you can. I usually mix a lot of PHP in the blade file, however I cannot [F12] over the class even if it's inside the tags to go to the class definition

image

str avatar Jul 28 '20 14:07 str

it would be nice to have this feature :)

mrcwebdesign avatar Nov 14 '20 20:11 mrcwebdesign

Advertising alert
Well, I just created an extension as a temporary work-around for this: Blade Syntax for PHP
Now you can still use the amazing Intelephense and have Blade syntax 😁

Snippets is not integrated tho, blade snippets are somewhat simple and vscode have a built-in function to make snippets to match your favor, I recommend using that instead.

NamesMT avatar Mar 19 '21 20:03 NamesMT

This is the only thing keeping me on PHPStorm at the moment.

christianmagill avatar Oct 28 '21 00:10 christianmagill

@bmewburn, Are there any particular issues in VS Code that are blocking implementation of this feature, or is it simply a matter of priority?

christianmagill avatar Oct 31 '21 00:10 christianmagill

This would be awesome. Laravel is currently the most popular PHP framework, and almost everyone uses it together with Blade.

The features I miss the most are autocompletion and PHPDoc recognition.

@php
/**
 * @var bool $isActive
 */
@endphp

{{ $isActive }}
<br>
{!! \App\Helpers\FormHelper::createForm(/*...*/) !!}

augusto-moura avatar Nov 08 '21 15:11 augusto-moura

Practice example: enum's.

When I search for references/uses, the uses in blade files don't show up. Same for refactoring a class: it won't get changed in blade files.

georgeboot avatar Nov 26 '21 19:11 georgeboot

Full blade support would be great... even a bit of a support would enhance things dramatically. Unfortunately none of the methods and properties receives any suggestions. An example is the $loop object inside the blade @foreach directives. We have to basically use a documentation or try to remember the properties and methods.

Unless anyone here knows a workaround apart from snippets?

EmranMR avatar Dec 29 '21 14:12 EmranMR

I would also love to see this feature!

willschwanke avatar May 16 '23 20:05 willschwanke

bumping

backtrackjack avatar Jul 04 '23 06:07 backtrackjack

When using the extension Laravel Blade Snippets it seems to properly set the language context for each block of code. So in theory intelephense should be able to support Blade files - it just needs to also register itself for blade language and should auto detect the php code blocks? It works with php files, which can contain HTML/any text, blade is just slightly extended syntax with {{ }} echo, and @ blade directives, which basic PHP code expressions.

image

image

garygreen avatar Jul 16 '23 15:07 garygreen

Going to pinch in here real quick as I worked on this already for quite some hours/days.

It is not as easy as it seems. Basically you need to compile the blade template to it's php counterpart then perform the LSP related stuff such as autocomplete. With this, you also need to keep track of the cursor position and so on.

The next challenge is that you have to "inject" the variables/properties from the component, view call or livewire component into the blade file. This is quite a heavy operation, and keep in mind, this needs to happen for every keystroke.

Some of these can be cached based on the context to improve performance. But it's more then just enabling php.

haringsrob avatar Jul 16 '23 17:07 haringsrob

@haringsrob

Basically you need to compile the blade template to it's php counterpart then perform the LSP related stuff such as autocomplete. With this, you also need to keep track of the cursor position and so on.

Sounds like you worked on a new implementation built from the ground up? Most of the functionality your describing is already baked into intelephense - i.e. it knows cursor position, the language it's in (it works in PHP files with mixture of HTML/PHP and still auto completes), has a client for AST/language server. Plus a lot of the heavy lifting is already done in vscode api. But yeah, if you were implementing this from scratch then can imagine it being not easy.

It's unfortunate intelephense is closed source, as I'm sure there would be a fork to add Blade support quite easily if it were

garygreen avatar Jul 16 '23 18:07 garygreen

With Laravel Folio and Livewire Volt we can now have actual PHP in Blade files by design. Would love to see this as well.

mikebronner avatar Oct 10 '23 15:10 mikebronner

I really hope this gets resolved too...

ZayRTun avatar Jan 09 '24 16:01 ZayRTun

I also want this support for laravel blade, it will be very useful to have the intelephense working inside blade, please take a look to this topic!

WebCimes avatar Jan 12 '24 09:01 WebCimes

Any updates?

bdsoha avatar Feb 13 '24 08:02 bdsoha

+1

Seems like the author will not get that done any time soon... would need contributions!

alexsoluweb avatar Aug 14 '24 20:08 alexsoluweb