bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.6k stars 93 forks source link

Support for "Laravel Blade" language mode #93

Open 7twin opened 6 years ago

7twin commented 6 years ago

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

bmewburn commented 6 years ago

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.

cpouldev commented 6 years ago

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!

7twin commented 6 years ago

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

7twin commented 6 years ago

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

cpouldev commented 6 years ago

@7twin PHPStorm

dev-nicolaos commented 5 years ago

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.

ghost commented 5 years ago

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

xiaohuilam commented 5 years ago

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

...

prpdl commented 4 years ago

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.

Deji69 commented 4 years ago

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.

str commented 4 years ago

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 <?php ?> tags to go to the class definition

image

mrcwebdesign commented 3 years ago

it would be nice to have this feature :)

NamesMT commented 3 years ago

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.

christianmagill commented 2 years ago

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

christianmagill commented 2 years ago

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

augusto-moura commented 2 years ago

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(/*...*/) !!}
georgeboot commented 2 years ago

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.

EmranMR commented 2 years ago

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?

willschwanke commented 1 year ago

I would also love to see this feature!

backtrackjack commented 1 year ago

bumping

garygreen commented 1 year ago

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

haringsrob commented 1 year ago

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.

garygreen commented 1 year ago

@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

mikebronner commented 11 months ago

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

ZayRTun commented 8 months ago

I really hope this gets resolved too...

WebCimes commented 8 months ago

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!

bdsoha commented 7 months ago

Any updates?

alexsoluweb commented 1 month ago

+1

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