Open 7twin opened 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.
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!
@hambos22 What IDE are you using that supports this natively?
@bmewburn In blade templates you can mix php, blade syntax and html too
@7twin PHPStorm
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.
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
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
...
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.
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.
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
it would be nice to have this feature :)
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.
This is the only thing keeping me on PHPStorm at the moment.
@bmewburn, Are there any particular issues in VS Code that are blocking implementation of this feature, or is it simply a matter of priority?
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(/*...*/) !!}
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.
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?
I would also love to see this feature!
bumping
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.
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
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
With Laravel Folio and Livewire Volt we can now have actual PHP in Blade files by design. Would love to see this as well.
I really hope this gets resolved too...
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!
Any updates?
+1
Seems like the author will not get that done any time soon... would need contributions!
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