Vscode: [php] Provide html intellisense

Created on 25 Nov 2015  Â·  234Comments  Â·  Source: microsoft/vscode

In PHP files there is no html tags auto completion, please add.


EDIT 9/13/2018 @egamma: VS Code provides only basic support for PHP, but there are powerful PHP extensions available in the market place:

This feature should be provided by these extensions (Intelephence actually already does support it). Please give these extensions a try and help to make them better by filing issues and pull requests.

This issue has lost focus and turned into a discussion whether VS Code should provide PHP support out of box. However, as with many other language like C#, C++, Go, Python, Rust we do not want to bundle PHP with VS Code but rather rely on our great extension ecosystem. I´m therefore closing this issue.

feature-request help wanted languages-basic php

Most helpful comment

I'm unable to help, but another +1000 from me. HTML/CSS/JS in PHP is common as a mixed file. I've tried full Visual Studio + VS.php - also not supported. I keep wondering why is this overlooked in every Microsoft development tool that supposedly supports PHP. Yes, PHP support is there, but is useless if we don't have IntelliSense (code completition & code suggestions) for HTML/CSS/JS as well.

Same goes for JS blocks & inline CSS in HTML.
If I define in settings.json:
"files.associations": {"*.php": "html"},
... than PHP IntelliSense (obviously) does not work, and HTML kicks in. But inline-CSS by using style=" ...something... "; does not offer any CSS properties when writing in between quotes of style attribute.
Likewise, if I start a <script> block, you won't get IntelliSense for JS, while opening .js file reacts normally.

I do support suggestion that (if it's easier):

  • <?php ... ?> should start the PHP IntelliSense
  • outside <?php ... ?> should start HTML IntelliSense
    but also
  • inside <style> ... </style> and style=" .... " should start CSS IntelliSense
  • inside <script ... > and <script> ... </script> should start JS IntelliSense

Also, if possible, a suggestion by @TheColorRed should be considered, meaning if you are inside
<?php ... ?> but are writing a string eg $string="..." than it should consider turning HTML IntelliSense as well. Thing is, PHP devs often use something like:
<?php
$something="test";
echo "<div><a href="http://sample.com">This is a ".$something."</a></div>";
$continue = "coding here ... etc";
?>
.. to avoid doing blocks with opening/closing php tags all the time, like:
<?php
$something="test"; ?>
<div>
<a href="http://sample.com">This is a <?php echo $something; ?></a>
</div>
<?php
$continue = "coding here ... etc";
?>

Also @egamma , while we don't mean to sound ungrateful or lazy, smug comments don't do much help either, if one of us was competent and knowledgeable enough to code it ourselves - I'm sure we'd do it. Unfortunately - I am not :-/ But if I can help in any other way I'd be glad to (not just by commenting with suggestions, but testing, or whatever).

I hope that there IS a consensus that this feature should exist, and that current PHP support without it is only a partial support for the most PHP devs.

P.S. And again, not to sound as a critic - I really like VS Code so far, and am most thankful to everyone that contributed and keep contributing to this wonderful project!

EDIT:
Would simply including/referencing one .ts file to another work?
E.g. in /languages/php/common/php.ts
include: /languages/html/common/html.ts
include: /languages/css/common/css.ts
include: ...

While there could be some overlap with the tag/attribute/function names nothing comes to my mind at the moment... And for IntelliSense it's non-issue I think as each would have different icon, only color coding could be messed in such cases... Am I missing something else?

All 234 comments

Sounds reasonable. The HTML tag intellisense providers are located here, it might just be a matter of hooking that module up to the PHP code. Also insuring they are only available when outside <?php tags, if I remember how PHP works correctly.

@Tyriar outside <?php tags means what? Are they availabe when outside <?php ?> tags in PHP files?

Outside <?php ?> is HTML, inside is PHP. So the HTML auto complete should only be available outside the <?php ?> tags.

@Tyriar But now they are not available outside the <?php ?> tags in .php files, maybe they are only available in .html files.

Please add this feature quickly, I think it's a basic feature, thank you guys.

@osjn thanks for helping us with the prioritization by commenting. An even better way to help us would be a Pull Request with an implementation.

Maybe it is just me, but I think it would be cool if intellisense was available inside of php strings as well.

An upvote from me too. This feature is needed, please.

Almost every PHP developer will need this feature in order to pick VSCode as their primary editor.

We need this issue to be fixed in order to target more developers.

Yesterday I tried bumping my head against this problem but unfortunately my lack of TypeScript skills are holding me back to help you on this issue.

I need this!

Same. Simply +1000

I'm unable to help, but another +1000 from me. HTML/CSS/JS in PHP is common as a mixed file. I've tried full Visual Studio + VS.php - also not supported. I keep wondering why is this overlooked in every Microsoft development tool that supposedly supports PHP. Yes, PHP support is there, but is useless if we don't have IntelliSense (code completition & code suggestions) for HTML/CSS/JS as well.

Same goes for JS blocks & inline CSS in HTML.
If I define in settings.json:
"files.associations": {"*.php": "html"},
... than PHP IntelliSense (obviously) does not work, and HTML kicks in. But inline-CSS by using style=" ...something... "; does not offer any CSS properties when writing in between quotes of style attribute.
Likewise, if I start a <script> block, you won't get IntelliSense for JS, while opening .js file reacts normally.

I do support suggestion that (if it's easier):

  • <?php ... ?> should start the PHP IntelliSense
  • outside <?php ... ?> should start HTML IntelliSense
    but also
  • inside <style> ... </style> and style=" .... " should start CSS IntelliSense
  • inside <script ... > and <script> ... </script> should start JS IntelliSense

Also, if possible, a suggestion by @TheColorRed should be considered, meaning if you are inside
<?php ... ?> but are writing a string eg $string="..." than it should consider turning HTML IntelliSense as well. Thing is, PHP devs often use something like:
<?php
$something="test";
echo "<div><a href="http://sample.com">This is a ".$something."</a></div>";
$continue = "coding here ... etc";
?>
.. to avoid doing blocks with opening/closing php tags all the time, like:
<?php
$something="test"; ?>
<div>
<a href="http://sample.com">This is a <?php echo $something; ?></a>
</div>
<?php
$continue = "coding here ... etc";
?>

Also @egamma , while we don't mean to sound ungrateful or lazy, smug comments don't do much help either, if one of us was competent and knowledgeable enough to code it ourselves - I'm sure we'd do it. Unfortunately - I am not :-/ But if I can help in any other way I'd be glad to (not just by commenting with suggestions, but testing, or whatever).

I hope that there IS a consensus that this feature should exist, and that current PHP support without it is only a partial support for the most PHP devs.

P.S. And again, not to sound as a critic - I really like VS Code so far, and am most thankful to everyone that contributed and keep contributing to this wonderful project!

EDIT:
Would simply including/referencing one .ts file to another work?
E.g. in /languages/php/common/php.ts
include: /languages/html/common/html.ts
include: /languages/css/common/css.ts
include: ...

While there could be some overlap with the tag/attribute/function names nothing comes to my mind at the moment... And for IntelliSense it's non-issue I think as each would have different icon, only color coding could be messed in such cases... Am I missing something else?

if this is not getting added, then i have to switch editor, right now i use 2 editors...

Please, how can I deactivate de HTML IntelliSense when I'm working with a PHP?

This option is a nightmare, because I can't tab in a variable because automatically create a XML/HTML tag.

I don't mix my PHP code with the HTML, and I will not make this error ever, please, at least add the option to deactivate it in PHP "mode".

@TheColorRed Crane Intellisense has the problem. It's by far the most popular VS Code PHP extension, so I guess this is what most people are reporting their problem with.

same here, we need auto-completion for CSS/JS in HTML. Otherwise, switching to Monaco is no real option :-)

I've just tried vscode but lacking of this feature just stop me using this IDE. Please provide this feature as it a must have feature for every IDE.
Thank you in advanced.

This is very needed. It's incredibly annoying not getting proper intellisense when putting either php code inside a html file, or putting html in a php file.

One big feature i'm missing and its preventing me and colleagues to use vsCode as out main editor.

This is a deal killer for me without this very common feature. Shame though...I REALLY, REALLY, REALLY love this IDE. If this is added, I will be so happy.

@egamma I'll get right on submitting a PR, after I spend an unnecessary amount of time trying to find the code to modify because you decided to be passive aggressive and sarcastic instead of offering the slightest bit of direction to those who might be able to help.

@TechnikEmpire please do not read too much into a comment I made in December 2015, while we were recovering from the big November VS Code release. Apologies if this comment came over as sarcastic.

There is some good progress with regard to Intellisense for PHP. If you want to contribute, then I suggest to look into contributing to the php-language-server project that @felixfbecker is working on. Felix is also the author of the php-debugger. These are the related repositories:

More information about the language server approach and the language server protocol can be found here.

@egamma But is there any way the PHP language server can "delegate" to VS Code's HTML language server? Seems like https://github.com/Microsoft/vscode/issues/1751 would cover this

@felixfbecker now that we have extracted the HTML language server, the first scenario we want to investigate is how to integrate it with CSS language server so that we can provide Intellisense in CSS sections. This corresponds to the first scenario you mention in #1751 and that was also requested in #8928.

This work didn't make it for September and it is now planned for October.

Thanks! CSS support inside HTML work is planned to October, what about JS aka <script> support?

@egamma are there any changes or improvements? Mid October passed, so just wanted to re-check. so far, after 5 months I'm still not using VS Code as my primary editor because of the issue, and i'm sure there are hundreds of silent souls out there. i'm glad that there's some work with HTML/CSS mixing, but we really do need a complete HTML+CSS+JS+PHP support...

@luxzg HTML+CSS progress according the October plan, HTML+CSS+JS is a stretch. Follow our progress here: https://github.com/Microsoft/vscode/projects/2

For me powershell inliners in some kind of devops files editing this feature also help a lot. May be someone have an extension that's particularly automatically changed syntax when a cursor located in some of code block?

FWIW the "HTML Snippets" plug-in allong side PHP Intellisense is working well for me.

@matthewringer the plugin not working for me

This is an issue for me too.. has there been no movement on this yet ?

Let's hope this will be added soon. Without this I doubt any php developer will use it.

Sublime is itching me bad to revert back(TM). VSCode if you Love me than save my soul and add the HTML CSS & JS support please.

Well over a year and STILL no support for this? Really? ...and here I thought MS finally made a product that wasn't garbage.

This is the one feature alone, that for me, makes PHPStorm, so much better then anything else I've tried. If they can finally implement proper intellisense/syntax highlighting support for PHP with HTML, CSS, Javascript, then we could finally have a really good lightweight PHP editor.

It's way to annoying right now to be typing in HTML or CSS or Javascript and getting PHP completions everywhere. You might as well be using another editor without autocomplete.

It can't be that hard to just classify .php files as HTML and then parse only what's inside of <?php ?> tags as PHP code, can it?

+1 from me, please mix them up :)

I just started using VScode while learning programming and it's super great - loving the speed, polish and useability - magical stuff. Just today realised that it's not picking up HTML within PHP files (wither within or without PHP tags) which is making matching HTML tags quite difficult. I'm having to switch out to another editor which isn't ideal.

Sorry I'm not experienced enough to remotely attempt to add this/fix this myself but would really appreciate if someone at Microsoft could add it in. I routinely embed HTML, Javascript, CSS, and SQL code within my PHP files. Would be great if it could all be detected like in other editors, although I'm sure it's not trivial to add this functionality. Would really hate to have to leave VScode all together as it's making the learning experience enjoyable.

@egamma @aeschli this has been laying around for quite a while - you mentioned you wanted to solve this problem with the HTML and CSS language servers, is that finished? I think what this comes down to is the ability for a language server to define certain ranges in the document where all language features should be handled by a different language server. So a PHP LS can after parsing a document declare which ranges are HTML, an HTML LS can declare which parts are JS or CSS, a TS/JS LS can declare which parts are SQL or GraphQL.

@felixfbecker yes this support is available since a couple of milestones, pls see

image

The html language server can be found here https://github.com/Microsoft/vscode-html-languageservice.

The approach has been mimiked for the vue language support https://github.com/octref/vetur

// fyi @aeschli

@egamma So how does it hand off completion to a different language server? Is there any documentation on this? I assumed this would have taken an LSP extension

leaving this here

@felixfbecker We currently have no other documentation except the code, sorry. I suggest that you connect with @aeschli for a deep dive when you want to get started to add this support for php.

@felixfbecker

Seems there is no generalized way to do language injection yet, but html extension's implementation is pretty straightforward.

I think now it hits a good middle-ground: VSCode offers html/css LS packages to alleviate implementing embedded language support. Meanwhile it keeps flexibility so each LS can react differently based on its context.

By context I mean, html extension could download jquery.d.ts when a script tag with jquery is included (wouldn't apply to vue), or vue extension mark each .vue file as a component to do module resolution (wouldn't apply to html).

To quote @aeschli: https://github.com/Microsoft/vscode/issues/12354#issuecomment-257242426

There are some bugs that want us to come up with a general solution for embedded content, but I think that we won't succeed in that. There are subtle differences in every case where we think it's better to have specific implementation of every host language for the best user experience.

But I do agree doc for implementing embedded language support is lacking. Guess I'll do some writeup once I finish all major features for my vue extension.

This is very unfortunate. Can't we add this capability to LSP? The language server is what parses the documents into an AST, so only the language server has knowledge about what part of the document are written in a different language and should be handed off. So now the extension _also_ needs to parse the document? That is in most cases not even possible because the parser depends on a different runtime than Node (PHP, Java, ...).

I don't imagine adding this to LSP would be that hard, for example the server could just send a notification for a URI with an array of a range + a language mode. Than any editor (not just VS Code) could use a different language server for that range.

@egamma I couldn't find the code in the repository that hands off the language, could you give a more specific pointer? Sorry if I overlooked this.

@felixfbecker Erich meant: embedding of different language services is done inside _the server_.
You can e.g. see that in the dependencies of the html server.
That way the server is selfcontained and has full control configuring the context of the embedded language (the JavaScript libraries are available in the embedded content, version of the language (ES5, ES6..)).

That's where the solution you outline (communication between language servers) starts getting in trouble. It likely leads to language server specific APIs and dependencies between servers.
We'd like to keep the coupling low and language extensions replaceable.

That said, every language server is free to choose its approach. You can use custom LS messages to do this. That's how we implemented it the November release. The server sends the request back the client the client asks other extensions based on a virtual documents that just contain the embedded language content.

I'd suggest we continue the discussion is a separate issue. Maybe file a new issue with the suggestions you have on how to extend the LSP?

Chiming in here, too. Loving VS Code so far, however the absence of HTML tag competition inside of PHP is a real deal breaker. Temporarily I'm switching to the HTML language mode for PHP files, but don't know how this will work out in the end.

Fell in love with VSCode until I discovered it was lacking this rather basic feature. Gone back to sublime for now.

This one feature is keeping me from switching to VSCode.

This is a badly needed feature. +99999

Such a basic feature which exists in all other editors :|

Unfollow

Any updates on when we can expect this?

This in my mind would be directly related to #765.

:+1: So good editor and it lacks such a simple function :(

I imagine if this hasn't been closed outright it will potentially be fixed one day. I sure hope so - the sooner the better.

The ONLY thing keeping me from transitioning to VSCode from Atom is the lack of this crucial feature :(

So can anyone then suggest any alternative editors for full-stack web PHP/HTML/JS? Really love VSCode, but this lack of feature is just a blocker for me. Is PHPStorm or WebStorm good?

As the maintainer of PHP IntelliSense, this thread is a nightmare to subscribe to. If you wanna +1 the issue, give it a thumbs up. All these +1 comments just clutter the thread and spam maintainers with notifications without adding any value to the discussion. And to everyone saying "this is such a simple feature": it's actually not. But if you think so, feel free to do a PR.

@felixfbecker i do think it highlights how frustrated people are with this issue. It's not so much a simple feature; I agree its complex to implement, but its more that people have come to expect this kind of feature with a text editor, and like me after falling in love with VScode, are quite shocked that its missing.

It about the lack of a roadmap of such an important issue. Simple or not this is a feature required for a dev environment in 2017. Super simple fix would be let us tag sections with comments or another keyword to specify which intelligence we want. Thing of GitHub code blocks, wrap a section of text in tags.

While it is a bit annoying hearing all the whining, and I have been one to
chime in on this issue, it is important to hear it.

It doesn't matter if something is open source, you're still engaged in
delivering a product to consumers and when it sucks, people are going to
complain. When my car dealer throws in a free wash with my annual service
and the minimum wage car washer leaves streaks all over my car, I'm going
to complain.

Free or not, there's an investment on the user's part to modify their
workflow with a new editor. People are doing this only to find out that
they wasted time and might as well stick to using notepad. People can
unsubscribe if they don't want to hear the negative feedback, but it's
important that Microsoft hears these complaints. After all, they've
invested significantly into producing this product and what are they
getting back for their money? People with one more reason to curse their
company and not use the product that they've paid into.

As far as pull requests, people are already annoyed that their time
investment just to switch workflow and tools has been wasted. There's
little to no insight into where to even start to make an additional time
investment even if they felt like potentially throwing away more time. This
isn't a complex feature on paper, so if it is in practise then perhaps
there's severe deficiencies in the application design. I can only
speculate, as can everyone else, because we are not getting paid by someone
to learn this code base.

On Wed, Mar 29, 2017 at 9:37 AM Stephen Eckels notifications@github.com
wrote:

It about the lack of a roadmap of such an important issue. Simple or not
this is a feature required for a dev environment in 2017. Super simple fix
would be let us tag sections with comments or another keyword to specify
which intelligence we want. Thing of GitHub code blocks, wrap a section of
text in tags.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-290091896,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKtty5-1B6H5kqCCq9mb8rva78_dR53Uks5rql6ZgaJpZM4Gpk-J
.

>

Jesse Nicholson

THE ANSWER FOR ALL THIS PROBLEM FOR ME WAS NETBEANS FOR PHP

A GREAT IDE THAT I WONT CHANGE FOR A LONG LONG TIME.

@madruga88 Netbeans isn't even the best thing out. PHPStorm I believe is currently the best PHP editor out there. I believe Jetbrains took the whole Intelligent Coding Assistance from Microsoft, and made it a whole lot better.

When I first started using VSCode, the only IDE it reminded me of was ones from IntelliJ Products because of how lightning fast the completions showed up. Infact, both VSCode and PHPStorm have a very similar feeling out of the box in terms of general editing features. The only place thing that VSCode Fails hard (And I mean really hard) is on PHP with embedded HTML (which should have worked from the start).

If VSCode finally got embedded HTML to work with PHP, it would easily become the best text editor (non IDE) for PHP.

Currently I'm sticking to using Sublime Text because it at least knows if I'm in HTML, CSS, Javascript, or PHP all within the same file and gives proper completions at least.

Funny thing is Sublime text when you have a PHP file processes it as a plain HTML file. Can VSCode not add the PHP support to the HTML syntax also? No need to have 2 separate syntaxes for it?

@drone540 the bad load and use (even code typing is slow) performance of phpstorm made me choose netbeans... that have all the linting and hinting tools, formating and debugging perfect out of box.

i've used visual studio for a decade.. and i can say that netbeans is the visual studio of PHP because of complete features and nice performance.

i agree with you that the only thing missing in vscode is the html + php syntax formatting.

but even if PHPSTORM was free.. i would pick netbeans... because of its performance.

Seriously this is not fixed since 2015? Back to sublime

I keep checking back to see if this issue is fixed but no movement. Won't switch to VSCode till it is regardless of how many other great features it has. It's needed badly.

I keep checking back to see if this issue is fixed but no movement. Won't switch to VSCode till it is regardless of how many other great features it has. It's needed badly.

What IDE are you using right now?

@icenold I have a pretty nifty workflow with Brackets atm. Inclined to stick with that.

Unfortunetely, although I love Visual Studio Code , I have to switch to Sublime because of this issue.

still open? everyone wants this feature!

Please Implement this feature. I have heard great things about VS from developer friends. I was about to make the switch from sublime this morning but I really can't get passed not having this feature.

Guys, let's be patient.

@markpanado Original ticket date: "Nov 25, 2015"

Whilst we wait is there a way I can set the HTML syntax to be the default for PHP files as i'm typically writing far more HTML in PHP than PHP. There's nothing obvious in the user settings panel.

Thanks!

@matt3224 click on the language indicator in the bottom left corner of the status bar and in the quick pick select 'Configure File Association'

image

@egamma Excellent! Thanks

Actually, php is designed to work with HTML and use html tag to cover itself, just like javascript/css in HTML. Other languages do not work like that. So HTML support in .php files should be a built-in feature.

Whilst I love the extensions for VS Code, the issue mentioned here (given how long this thread dates back) is a deal breaker. Of course you can get the work done without it, but it feels slow, slow enough you can just go back to Notepad and go without any language tooling at all.

It shouldn't be like this.

Hello vscode php enthusiasts. You might be interested in the 0.7.0 release of Intelephense.

optimised

There's a few quirks in that you must be in HTML language mode and syntax colouring is not available for php. Formatting (it got cut from the gif) is a 3 step process: format html -> switch to php -> format php.

Hopefully you're all separating your views and models nicely and these shortcomings are not too much of an issue.

@bmewburn amazing! When will that available?

@popcorner it's now available

I personally solved this by going to File->Exit and downloading Netbeans
w/web dev addon. Superior. Vs code is a decent typescript ide and not much
else. When you stop expecting more from it you stop being disappointed.

On Sat, Jun 24, 2017 at 5:02 PM Ben Mewburn notifications@github.com
wrote:

@popcorner https://github.com/popcorner it's now available

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-310865635,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKtty5j9FjPOsarF3tjW9qq2JugqnYjZks5sHXlggaJpZM4Gpk-J
.

>

Jesse Nicholson

@bmewburn I tried out Intellephense but it still has the some glaring issues. PHP typed inside of HTML tag attributes eg( id="") lose auto-completion. The loss of PHP theme formatting.

It requires the same back and forth between HTML and PHP and that just wastes too much time.

On a separate note, I am beginning to wonder if this whole thread is just one big troll. How can this still be an issue after 2 years? Everyone that even opens a similar issue, has it closed and referred to this one. Yet no headway has been made in all that time.

I too moved on to Netbeans, found out PHPStorm is capable of handling php html js in one file perfectly. Remote DB Integration via SSH is also neat.

So, I did some testing with both Netbeans and PHPStorm.

It looks like Netbeans is pretty decent at this.

Netbeans
It supports:

  • HTML/CSS/JS in a PHP file outside of tags
  • CSS in HTML tags with style attributes.
  • Spelling completions (dunno if useful of not but it's there)

It fails with:

  • The completions don't seem to be aware of the content you're typing, so the first completion might not be what you want.
  • No support for HTML in PHP Strings. In fact the completions here are as bad as VScode.

PHPStorm

  • Well it works pretty much in any context, and works really good and all the completions are pin point accurate and what you actually want.

Minor Fails:

  • minor issue that seems to close autocomplete upon - key with with style attributes. Can be reopened with ctrl + space or continued typing of css attribute
  • only activates in PHP strings if a HTML tag is present (which really is good enough support anyway)

PHPStorm definately feels a lot closer to VSCode (when it works), then Netbeans does. If you wanna test how autocomplete should really work. I'd recommend testing it out in PHPStorm. Also PHPStorm and VSCode share quite a lot of similar editing features out the box. Performance wise, I'm thinking PHPStorm is faster. Didn't experience any delays even with autocomplete. Netbeans noticed some lag with autocomplete.

Dunno how long it will be before VSCode actually fixes this issue, but I believe when it does finally work. It will work a lot closer to how PHPStorm works, and become at least the 2nd best editor for PHP autocomplete ever.

I just recently switched to VSCode from SublimeText, only to run into this issue. It is a pretty annoying issue, and a pretty basic one too. I have to go back to SublimeText because of it. Tried associating PHP with HTML, but that makes all PHP code white, no syntax highlighting at all. Terrible!

I thought that after 10 years I will finally have a single Microsoft software that will installed on my computer permanently, but if they can't solve a simple issue for 2 years, it is going to the trash again.

Writing HTML inside a PHP document causes

screen shot 2017-07-28 at 1 32 51 pm

@ingageco No, it's not. It's suggested by the PHP Intellisense extension by @felixfbecker. But there's nothing he can do, because extensions are not able to specify special activation characters, so it can avoid suggesting that, yet.

I just want to know one thing. Is it in progress (little by little, baby ant steps) or just have been put aside completely?

@bsienn About what? The php intellisense extension is in progress, while the Code team don't want this to be provided natively.

@jens1o Thanks for reply. So, php intellisense extension are you talking about Fleix Baker extension?
So this thread is redundant? I'm confused now. Should I follow His plugin repository for progress?

Yep, I'm talking about Felix's extension, and yes, you should follow his repository to be up2date.

...so 2 years later, there is still no solution for having html autocompletion in a php file? I really like VS Code, I don't want to have to go back to Sublime over this :-(

Right now we just have to really deal with it

Or not you know because there are other options out there. Git and debugging alone isn't going to make me step backwards in my workflow. Never not when there are options that may not be as well implemented but are otherwise adequate. This issue should have been solved from the beginning.

The main problem is that we don't know who would provide that. Ideally the PHP extension (@felixfbecker ?). I'm also open to adding support to the HTML language server.
All HTML smartness is also available as a node module.

@aeschli As outlined above and in some other threads, I don't think requiring every language server to embed language servers for every possible embedded language is the right and sustainable approach. PHP commonly embeds HTML and SQL. HTML commonly embeds CSS and JS. JS again commonly embeds HTML. Language server authors would go down a rabbit hole supporting every nested combination and the user would end up with language servers installed multiple times for the same language, but cannot control what language server to use for these embedded languages anymore, nor their version. Like you said yourself in https://github.com/Microsoft/vscode/issues/670#issuecomment-282702369 (emphasis mine):

It likely leads to language server specific APIs and dependencies between servers.
We'd like to keep the coupling low and language extensions replaceable.

I strongly agree with that, and from my point of view the embedding approach leads to exactly that, not my outlined solution:

  • Give language servers the capability to announce to the _client_ what ranges contain embedded languages. E.g. the PHP language server reports to VS Code the ranges of inline HTML as embedded HTML, the HTML language server reports to VS Code the ranges of <style> tags as embedded CSS, ranges of <script> tags as embedded JS.
  • The client (VS Code) activates the language servers needed for embedded languages and sends them didOpen notifications with a virtual URI and contents of the embedded range.
  • Whenever the user requests autocompletion inside the range of an embedded language, send that request to the language server for the embedded language (positions relative to the start of the embedded range)
  • Show the results, resolving positions relative to the start of the embedded range as needed.

With this approach, the user has full control over what language servers to use (they are replacable) and the individual servers don't need to bother with embedding other language servers as dependencies. This means a consistent experience across embedded languages vs top-level languages and maintains SoC for every language server to only care about one language.

The notification could look roughly like this:

/** Parameters for textDocument/publishEmbeddedScripts, a notification sent from server to the client */
interface PublishEmbeddedScriptsParams extends TextDocumentIdentifier {
  /** All the embedded scripts for this text document */
  embeddedScripts: EmbeddedScript[]
}
interface EmbeddedScript {
  /** Ranges in the text document that form this continuous embedded script */
  ranges: Range[]
  /** The language ID for that script (as also used in MarkedString) */
  languageId: string
}

Example:

Given a PHP document like this:

<h1>Foo</h1>
<?php echo 'Hello' ?>
<p>Bar</p>

the PHP langserver would send to VS Code

{
  embeddedScripts: [{
    languageId: 'html',
    ranges: [
      { start: { line: 0, column: 0 }, end: { line: 0, column: 11 }}
      { start: { line: 2, column: 0 }, end: { line: 2, column: 9 }}
    ]
  }]
}

which would result in the HTML langserver receiving textDocument/didOpen from VS Code with a URI like file:///foo.php#embedded1 and this content:

<h1>Foo</h1>
<p>Bar</p>

Happy to discuss this in a separate issue if you want.

@aeschli I think the fact that that this keeps getting bounced around as a language server issue even though this issue is still open is telling me that it will possibly never get fixed.

@felixfbecker No one is saying to have every single bit of formatting be detectable. That would be insane but a bare minimum in of PHP/ HTML being detectable inside each other would be nice. VSCode it makes working with PHP/HTML needlessly difficult compare to other IDE's

@felixfbecker

What files specifically need to be edited in the language server for this to take effect? I looked at the language server for HTML and can't see exactly what it does with style and script.

It looks like what it does it skip tokenizing anything that's not HTML according to these file: https://github.com/Microsoft/vscode-html-languageservice/blob/master/src/parser/htmlScanner.ts
https://github.com/Microsoft/vscode-html-languageservice/blob/master/src/htmlLanguageService.ts

But how does CSS and Javascript know what to do? I don't see how they work at all according to this file.

@aeschli a php and html language server can already work reasonably well together given that many of the vscode features allow for multiple providers to be registered. In many cases the first non falsey provider result is used or in some cases multiple results used. So as long as each server ignores what it doesnt understand -- outside of <?php ?> for php, inside for html -- it works.You can see this in action here https://github.com/Microsoft/vscode/issues/670#issuecomment-310822851

To have this working more smoothly.

  1. Allow multiple language id file associations so each lang server runs.
   "files.associations": {
        "*.myphp": ["php", "html"]
    }  
  1. Use a combined php/html/css/js grammar file for syntax highlighting

Are there more complete solutions for language embedding? Probably. And I agree it should not be the responsibility of any particular server to embed multiple languages. I don't think it should even be the servers responsibility to identify what particular language is being used, the user should identify the document range. But that aside, to get PHP and HTML working together I don't think it's that hard.

@bmewburn If it's not that hard why are we waiting 2 years later for a fix?
@felixfbecker says it's not so easy to do. But this issue is still open so obviously one would think it might be a priority but every release sees it overlooked. So until someone makes a change i'll keep being ornery and hope that it eventually gets fixed. Until then i'll keep on using what works.

@felixfbecker As I mentioned in my comment, no requirements here, each language server is free to pick the approach on how to deal with embedded content: Forward requests to other servers, or handle it itself. e.g. using a linked library/service. It all depends on how tightly coupled the embedded content and the main language are and the user experience the server wants to provide. Often embedded content needs context from the main language and has to adhere to escaping rules. That can't be easily communicated to a language server that only sees a virtual document. That was the reason why we moved away from that approach in the HTML server.
But if this is a feasible approach for PHP, and the PHP language server wants HTML server to handle requests for given ranges, let's do that, the APIs for it are all there, it can all be done in the client and with custom LS protocol.
If there's anything I can help in the html-server or service, let me know.

@aeschli escaping rules is a good point, so instead of ranges, the language server would have to send the unescaped content back. Would that solve it? Or any other problems you see with the proposal?

But if this is a feasible approach for PHP, and the PHP language server wants HTML server to handle requests for given ranges, let's do that, the APIs for it are all there, it can all be done in the client and with custom LS protocol.

The PHP language server is used by a lot of other clients than VS Code, sublime, neovim, atom-ide-php, Eclipse Che, etc. How can we build a solution that can be expected to (eventually) work in all of these clients (as that's the point of LSP), while at the same time avoiding to bundle specific HTML (and CSS, JS...) langservers with specific runtime requirements (e.g. a neovim PHP developer has PHP installed, but not necessarily NodeJS) so the user can decide what language server to use for the embedded languages? I would be very excited if we could pull that off in a universal-for-all-languages way as that would be a super strong argument for LSP.

@aeschli @felixfbecker So does this mean you both are going to attempt to sort this issue out? That would be amazing.

This is a feature that almost every PHP coder really needs it. So please, do not ignore it simply because we can't make it in a _correct_ way.
Even if there is a illogical or ugly solution, it can still be used temporarily, rather than we put it off and do nothing.

If we're handcuffed because we want to be as compatible as possible for extensions originally written for another older editor, then maybe we should consider writing a new cross-editor standard that goes above what we have available today. It's not like Microsoft hasn't stepped out of it's boundaries before and worked with other groups to build a standard language server model used in both this and other editors. We just need to do the same thing over again regarding how mixed language scenarios are handled.

It's obvious that mixed-language extensions like @felixfbecker 's php-intellisense extension or my vscode-jinja extension is getting blocked by this issue. It's great if you're able to do it in the core languages, but if the community can't expand on it easily, it's just going to give a poor experience to the whole editor in general. At this point, this issue has gone on long enough that the community itself is actually telling others to go elsewhere, and I'm doing the same.

@wholroyd agreed, I was telling people about this IDE like it was the best thing since sliced bread and now I'm actively steering people away from it. I regret that I've integrated it one of my projects.

@aeschli would you consider the following in the html language server?

  1. An additional languageId to listen to phtml. This would provide a shared id that php and html extensions could listen to and a combined textmate grammar.
  2. If necessary modifications to the html language server scanner to consume all within <\?(php|=)?>, \?> as a single self closing tag.

The following providers from separate php and html extensions would work well together without any embedding in the server or hacking away in the client.

  • code lens
  • code action
  • completion
  • definition
  • highlight
  • link
  • doc symbol
  • hover
  • implementation
  • reference
  • signature
  • workspace symbol

Some hacks would be needed to get formatting and rename working and users would need to name view files with a different extension and associate with phtml rather than php. But I think this would be a pretty good start with minimal effort and risk.

@bmewburn Yes, sounds good, I can do that. What's the idea with the 'phtml' language? Will you use it to programmatically forward the requests?

@aeschli no forwarding of requests, the idea is just to let the html server register providers for phtml and have a php server register providers for phtml too and let vscode handle the separate responses.

The above providers all either have responses merged or the first non falsey response used. So as long as separate html and php servers don't try and return a result for a range they dont understand then it should all work. The phtml id is just something common for both language servers, it might be better to just have multiple language file associations but that might be much more involved? Plus I suppose keeping php and phtml separate avoids sending requests to the html server for php only files.

"files.associations": {
        "*.php": ["php", "html"]
    }

At the moment I register my php extension with html and php doc selectors but Im wary of overriding the html language config in this setup.

A file association can only be assigned to a single language id. But language servers are free to serve documents of any language they want.
Possibility 1: HTML also registers for php, participates on all requests, but will only return results when outside of <?php .../?>
Possibility 2: Only the PHP language server registers for php, and will forward all requests <?php .../?> to all language server registered to the phtml language.

So forwarding can be achieved just via commands.executeCommand ?

@bmewburn I created #36396. Lets take our discussion to that item.
Yes, with `commands.executeCommand' as done here

Any update concerning html intellisense for php

Hey Guys, is there any way to mixed php and html coding? Html highlighting doesn't work correct in php document :-(

835b4a9809

Looks like almost after 2 years there is still no proper solution?

is this issue solve till? i still facing

Nope, still not possible. Unfortunately I've been forced back to ST3 because of this issue. I hope one day they fix this and I can come back.

@bmewburn Fantastic work. This has been needed for so long. Thanks a lot. Now there is no reason not to switch to VSCode

@kilevvri1 please share your setting. For me not work..

@expo87 I used the default PHP Intelephense requested settings setup
"php.suggest.basic": false
I don't use any other settings, yet.

Bummer. I had just set up my VSCode environment and got all my plugins ready. Then I ran into this and still no fix.
It's a shame because I was starting to really like VSCode but now I have to return to Sublime Text.

@DannyMexen Try PHP Intelephense extension

@kilevvri1 this extension required install PHP. For me install in system PHP dont needed! Why I shold do this? Just for see normal mixed syntaxis php and other language? Why this option dont work out of box?! Sublime Text install file 8,5 Mb - mixed highlighting work fine. CodeLite install file 50 Mb - mixed highlighting work fine. And the don't needed install PHP!

I agree with @expo87 that this functionality should come out of the box in VS Code. PHP Intelliphense is already a step forward and makes auto completion possible, however I can't get any html syntax highlighting at all.

@kilevvri1, hey, how's it going? I did, it did not work.

However, I still cannot format HTML in a .php file. I also agree that such a functionality should be out of the box.

Everything else is fine but just this one thing that is ruining my experience. It is very important for my code to be well formatted due to company policies. Here's to hoping in the future.

It's cumbersome but for large files, I am renaming the files to .html, formatting and then renaming back to .php (believe me, I have tried every trick there is with no success).

I like VSCode and I will give it a week. If my work slows down significantly, I will return to ST 3.

For those of you who are complaining about installing PHP for the extension to work, do you seriously not have PHP installed on your local machine? Are you seriously wasting time putting the code on your server before testing it, and doing this over and over again?

PHP should be installed locally, that just seems like a given. If your app doesn't run locally, then you have some development issues to work out.

@TheColorRed for me no needed view result of my code on locally and after then upload file on server. Using WinSCP and ST - light and fast speed of my work. And of course I know what I doing :-)

@TheColorRed you found someone on the internet that was wrong and passive aggressively ranted about the value of time.

image

While we would all love for this to be straight out of the box functionality, the fact is that it isn't. The VSCode team either sees this as a non-issue or very low priority. @bmewburn has made the PHP Intelephense extension which I am happy with versus the alternative.

@expo87 No need to explain your workflow. We all do things a bit differently.

because of this
i use smarty, so i can move all HTML to tpl file, not inside php code -_-
and make my code more cleaner

@DannyMexen I have no problem formatting HTML inside of PHP files. I do turn off the PHP Intelephense formatting "intelephense.formatProvider.enable": false in settings.json

All I really want is for > to not trigger an autocomplete suggestion (and make me stop what I'm doing to dismiss it). It's annoying when you close an HTML element and want to go to the next line, but if you "accidentally" hit enter, you end up with garbage you have to then delete instead of a new line. None of the suggestions above seem to fix this particular issue.

All that's needed for that is https://github.com/Microsoft/language-server-protocol/issues/138.
@jrieken could you give a comment on whether the intermediate solution you proposed is in scope anytime soon?

We might be able to implement multi-character triggers but it is not as trivial as it sound. Until then, an extension should use the last character in a potential sequence of trigger characters.

@kilevvri1 no dice. I have followed your posts but to no avail. Can I see all your settings, please? Perhaps a list of the extensions you have installed if that's not a problem.

The closest I got was changing the file association and tinkering with beautify but even that did not help.
Anyway, thanks everyone. It does not seem like there is a straight-forward answer to this.

After hours of trying, I can't get this thing to work. Not even "PHP Intelephense" plugin working for me as @bmewburn suggested. Type 'php' and press tab, it expands into this: http://s.zeshanahmed.com/a_1FC81B2B.png

This is the most basic feature when you're using HTML with PHP. At least as a WordPress theme developer.

I may come back and check VS Code again, but for now, switching back to Sublime. I loved how powerful VS Code looked to me at first, but these small issues (or lack of features) will keep many PHP/WP developers to stay away from it.

aaand I'm with @zeshanshani and @DannyMexen - if I can't write html inside my PHP files, then this editor is right out.

Dang. I liked it so much but this one (seemingly simple) thing has made it useless for me.

Maybe I was a bit wrong here, this issue isn't really what I was referring to. Anyway, like I mentioned I loved how powerful VS Code looked to me, so I checked in further and found a pretty easy solution to the problem.

The problem I faced was that when you are outside of <?php ?> blocks and try to open PHP blocks with a shortcut, it doesn't work.

So I created custom HTML snippets for expanding PHP blocks. I created these 3 snippets for now:

  • php - to expand into <?php ?>
  • if - to open IF conditional.
  • foreach - to open FOREACH loop.

Here's the snippets code if anyone is looking for it:

https://gist.github.com/zeshanshani/ccbfe8c0177a2513f0a92d0747349f50

And this is the result:

PHP Expand in HTML

The only problem here is that it also expands snippets in .html files unlike Sublime Text where you can define the scope so a particular snippet only expands if it's PHP: http://s.zeshanahmed.com/a_1FCD4A29.png

Btw, did anyone try enabling emmet.triggerExpansionOnTab setting? It enables emmet HTML expansion on tab support inside PHP strings.

To make this setting, go to the User Settings and add this line:

"emmet.triggerExpansionOnTab": true

Screenshot: http://s.zeshanahmed.com/a_1FD14980.png

Here's the result:

HTML Expand in PHP Strings

I found a workable solution for me (and possibly other people.)

I installed the "_Auto Close Tag_" extension by Jun Han. Then in my settings I added this:

"php.suggest.basic": false,
"auto-close-tag.SublimeText3Mode": true,

Now while in a .php file and outside the <?php ?>tags I don't get $_cookie after I finish typing a html tag, and when I type </ it auto completes the appropriate closing tag.

hopefully, this helps someone else that was having the same problem as me.

@Chenzo does your workaround format code? If you press Ctrl + Shift + I, does the PHP as well as the HTML code get formatted/indented accordingly?

@DannyMexen hmmm... no. Altho, is that a native thing to VScode? Even my beautify plugin doesn't seem to know what to do with HTML while in a .PHP file.

@Chenzo I see. Yeah, same here. This is the only feature I need to work in order to use VSC as my exclusive text editor.

@zeshanshani @DannyMexen
if PHP Intelliphense can't work
try to reinstall vscode and PHP Intelliphense
or
try use everedit,that's a good editor,but not IDE,and only windows

Thanks for the suggestion @iscraft but I am running Linux and I am using ST 3 for all my PHP projects.

So, if I'm following this correctly, the blocking issues are solved in the LSP (yay!), and also solved in Felix's Language Server (yay!), but it's not yet solved in VS Code Insiders.

The smaller related issue with the ever-present <?php autocomplete is present in VS Code Insiders, with Felix's Intellesense plugin active, so I guess that is also waiting on something in VS Code?

https://github.com/felixfbecker/vscode-php-intellisense/issues/205#issuecomment-347794655

I guess it'll skip Insiders Edition and make it into 1.19?

In settings.json, adding the following property works fine.

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

Well, I guess it wasn't true after all. Back to Sublime Text?

files.association was one of the things I tried. Never worked for me.
Official Twitter account just told me to raising the issue and hopefully
one day, the team will implement it. It is such a bizarre thing to not have
this out of the box. Literally the only thing keeping me from using VScode
as my exclusive editor.
@Ken Newman that is my solution for all PHP projects.

On Thu, Dec 14, 2017 at 10:31 PM, Ken Newman notifications@github.com
wrote:

Well, I guess it wasn't true after all. Back to Sublime Text?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-351827207,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APewuYFpWR6_mZbUO-XVNMwH0LpYb_Cqks5tAYWugaJpZM4Gpk-J
.

--
Regards,

Danny Mexen.

Is it possible that HTML is now working within PHP language/files in 1.19? Just tested and i see ait working, even without any extension...

@jsieler in 1.19 and 1.20 it's still not working.

VSCode 1.19 cannot autocomplete html, attribute in .php file :( !!!!
Issue 2 year...

HTML has been working well in PHP files with this extension. This issue can probably be closed.

phphtml

@bmewburn I think so too

No, personally, I'm waiting for support without the need of external extensions.

The key problem also applies to other languages.

Let's be clear about the issue some of us are reporting here.

For now, I'll speak for myself.

The issue is NOT failure of HTML autocomplete in PHP files, it's FORMATTING HTML code in PHP files in the context of VSCode's 'Format Document' feature. Is this clear?

If your default keyboard shortcut is Ctrl + Shift + I you might find that only PHP code will be formatted in a PHP file that also contains HTML code. The HTML code is not formatted at all.

This feature comes out of the box in ST 3, for instance.

Things like autocomplete, auto closing tags etc work just fine. Tab a PHP line, and then tab an HTML line, try to format the document and only the PHP code will be indented correctly.

I hope this clears things up for some here.

Who here is experiencing this issue alongside me?

@bmewburn it works only if you choose HTML language mode for php files, but then you have bad styling for php part of the code :(

@Perumal93

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

It doesn't work at all! It simply uses whichever language you used last (php in this case). Others are completely ignored.

@SharakPL what version of VSCode r u using?

@kilevvri1 I've just upgraded from 1.19.1 to 1.19.2. No change :(
If I choose PHP as file language then html suggestions don't work.
If I choose HTML as file language then php part is styled as plain text and Output shows many errors.

@SharakPL Do you have your phone path linked in your VSCode user settings? I'm not home right now but when I get back I will help because intellephense is not perfect but it does wonders when it works well so I'll try to help.

@SharakPL I meant your PHP path. Typing on my phone, sorry.

@kilevvri1 yes, I have

"php.suggest.basic": true,
"php.validate.enable": true,
"php.validate.executablePath": "c:\\wamp64\\bin\php\php5.6.25\php.exe",
"php.validate.run": "onType",

It should be like in Sublime Text 3, where html code is always suggested accordingly while in PHP language mode

@SharakPL
Per the extension recommendations:
"php.suggest.basic": false

Try that and let me know

@kilevvri1 no change :(

Oh I get it now! There is some kind of HTML intellisense in PHP formated files but it's managed through EMMET suggestions: https://docs.emmet.io/cheat-sheet/
I kept getting annoyed with not being able to add simple link by typing <a because there isn't any snippet suggested. I figured typing only a shows what I need but even though I had my link, all attributes I had to add manually letter by letter. With EMMET I can simply type a#mylink.btn.btn-success to get <a href="" id="mylink" class="btn btn-success"></a>. That's cool, but to get more accurate html I should use a#mylink.btn.btn-success[title="click me" target="_blank"] and that new part again has to be typed letter by letter. It would be much better SublimeText's style:
html_is

Is there any way that we can manually add .php to the list of file extensions in which the HTML intellisense works? This can be done in Eclipse.

@graddev someone suggested
"files.associations": {"*.php": "html, php"}
in user settings, but this doesn't work for me

when they add this opportunity, who knows ?
was 2020, they still did not do this ....

HTML and CSS autocomplete in PHP file... How?

Need this feature added. Attribute autocomplete for HTML tags doesn't work at all.

Guys, I'm using an extremely disgusting solution, but it (kinda) works. I have a keyboard with macro keys, so I built macros to change the language mode. I press M1 if I want HTML intellisense and M2 if I want PHP.

Please try the intelephense extension.

@aeschli This DOES NOT resolve the key problem. The same problem also occurs in an extension I maintain, in the Smarty extension. It's really disappointing that the featured PHP extension doesn't get any further support and you're trying to distract by recommending to use another extension that's using a shitty workaround. Still, the problems lays deeper. In fact, this issue should be resolved in the next sprint, and you should not consider it laying on the backlog and downplay the problem. Where are your feeling for the community interests?

Sorry, but I'm a little bit pissed off.

(Actually, I said the same thing 3 months ago.)

There are only so many areas the VSCode team can work on and have expert knowledge. Unfortunately, we are not PHP developers. That's why we came up with an open extensions API and a marketplace. Please support us by trying the extensions and help the authors with good feedback.
I understand it would be great if all extensions are built-in and shipped together with VSCode, but we also want to keep the download small.

We worked with Ben, the author of the intelephense extension to improve HTML completion in PHP. I think the approach taken is the correct approach. Only PHP as the 'main' language fully understands the embedded HTML content (e.g. how it is encoded, how PHP variables resolve) in order to provide a good user experience. From my experience, other, generic solutions, solve only part of the problem and we end up with hundreds of open issues for the cases that they can't solve.

@jens1o I'm sorry that you are frustrated, and that there's nothing planned in this area in the near future. Please help us by supporting our extension ecosystem or give intelephense (and also other PHP extensions) a chance.

Alright, I take a good breath and I calmed down. So, let's move the focus to my extension: Am I supposed to keep a fork of the HTML language server so my users have HTML completion? That's the key problem I'm referring too. I think other languages are hit even harder. The problem is, that Smarty is that flexible that it could be used for close to any language(such as csv, json), whatever. Because it is a template system that is not bound to any language restrictions. So I need to keep a fork of a csv language server(that's not existant), an XML one, the JSON one... I wonder how many languages the technical resources allow?

give intelephense (and also other PHP extensions) a chance.

I'm going to stick to php-intellisense by @felixfbecker, because I love the codebase, even though I do not have HTML intellisense(which is why I'm burning for this issue), and that's the official featured extension(while I was using it long before that). I love the concept of language servers, and I think multiple language servers responsible for different parts of a file is the next step to improve the concept.

@aeschli Do you think that an extension can make the html part in php get the same behavior as the standalone html file? including let all the plugin for html work fine in that part?
Extension system is really important as we all know, but not all the features are suitable for plugins. What we actually need is parse one file to multiple language and treat them separately. This should be a built-in ability for a code editor.

And, all the PHP files are actually HTML, with a special HTML tag. Only the content in this tag should not be regarded as HTML. It is just a language embedded in HTML and can't work without it (except CLI). So the question is not about HTML in PHP, HTML is the main container. And also lots of language can be embedded in HTML, such as css javascript vbscript svg perl java, I don't think any extension can do this without official support.

Thanks @popcorner. I actually wanted to say the same, but you wrote it a lot better. :)

Does anyone know how ST does this? Even a high level explanation will be appreciated.

Let's keep this issue about HTML intellisense in PHP. I will improve our docs with techniques on how to enable language features for embedded languages. I created #47288 as a starting point for this.

@jens1o I listed some approaches in the description of that issue
@paldepind I also added a reply to your comment.

I'm still uncomfortable with this. So afaik, this issue can be closed because you do not plan it to bring it out for PHP but instead live with that workaround?

problem still without solution?

I'm using Laravel Blade .. So there are no PHP tags here.. Wonder how they will implement the feature..

Solved, But I dont know why... Maybe update the php inteliphense or use vscode insiders...
test

@victormongi what php inteliphense you use?

@jfnadev I don't know how this works but this is my vscode version and intelephense version:
image

@victormongi we have the same configuration

@jfnadev these are my installed extensions:
extensions.json:

[
  {
    "metadata": {
      "id": "2cbad5ee-b4ab-4de8-a1c7-77fede846155",
      "publisherId": "patbenatar.advanced-new-file",
      "publisherDisplayName": "patbenatar"
    },
    "name": "advanced-new-file",
    "publisher": "patbenatar",
    "version": "1.1.0"
  },
  {
    "metadata": {
      "id": "697255a9-3f36-44c8-b084-d3b91edfb23a",
      "publisherId": "HookyQR.beautify",
      "publisherDisplayName": "HookyQR"
    },
    "name": "beautify",
    "publisher": "HookyQR",
    "version": "1.3.0"
  },
  {
    "metadata": {
      "id": "9d674f86-f8d2-4fe1-8fa6-a17b40caf4ac",
      "publisherId": "pawelgrzybek.bimbo-theme",
      "publisherDisplayName": "pawelgrzybek"
    },
    "name": "bimbo-theme",
    "publisher": "pawelgrzybek",
    "version": "0.4.5"
  },
  {
    "metadata": {
      "id": "f583eafd-aa0d-4ccb-8f44-d1e610389660",
      "publisherId": "CoenraadS.bracket-pair-colorizer",
      "publisherDisplayName": "CoenraadS"
    },
    "name": "bracket-pair-colorizer",
    "publisher": "CoenraadS",
    "version": "1.0.27"
  },
  {
    "metadata": {
      "id": "e337c67b-55c2-4fef-8949-eb260e7fb7fd",
      "publisherId": "Shan.code-settings-sync",
      "publisherDisplayName": "Shan"
    },
    "name": "code-settings-sync",
    "publisher": "Shan",
    "version": "2.9.0"
  },
  {
    "metadata": {
      "id": "532533c9-a894-4a58-9eee-bbfbe7c06f71",
      "publisherId": "mikestead.dotenv",
      "publisherDisplayName": "mikestead"
    },
    "name": "dotenv",
    "publisher": "mikestead",
    "version": "1.0.1"
  },
  {
    "metadata": {
      "id": "1946e66b-9eea-45a9-816b-316bf9d7d1ab",
      "publisherId": "Zyst.Egoist-One",
      "publisherDisplayName": "Zyst"
    },
    "name": "Egoist-One",
    "publisher": "Zyst",
    "version": "1.18.0"
  },
  {
    "metadata": {
      "id": "7b71fc1b-190d-4f7d-95d1-93e422649b0a",
      "publisherId": "Zignd.html-css-class-completion",
      "publisherDisplayName": "Zignd"
    },
    "name": "html-css-class-completion",
    "publisher": "Zignd",
    "version": "1.17.1"
  },
  {
    "metadata": {
      "id": "8d5687fe-08f5-4a8e-917a-23aef71db6b3",
      "publisherId": "zhengxiaoyao0716.intelligence-change-case",
      "publisherDisplayName": "zhengxiaoyao0716"
    },
    "name": "intelligence-change-case",
    "publisher": "zhengxiaoyao0716",
    "version": "1.1.0"
  },
  {
    "metadata": {
      "id": "6f35c257-7fd5-4bc2-9cd1-01976589c17a",
      "publisherId": "arcticicestudio.nord-visual-studio-code",
      "publisherDisplayName": "arcticicestudio"
    },
    "name": "nord-visual-studio-code",
    "publisher": "arcticicestudio",
    "version": "0.6.0"
  },
  {
    "metadata": {
      "id": "a41c1549-4053-44d4-bf30-60fc809b4a86",
      "publisherId": "christian-kohler.path-intellisense",
      "publisherDisplayName": "christian-kohler"
    },
    "name": "path-intellisense",
    "publisher": "christian-kohler",
    "version": "1.4.2"
  },
  {
    "metadata": {
      "id": "a439d61f-cd9c-453f-b8c7-186f73d44915",
      "publisherId": "MehediDracula.php-constructor",
      "publisherDisplayName": "MehediDracula"
    },
    "name": "php-constructor",
    "publisher": "MehediDracula",
    "version": "0.0.8"
  },
  {
    "metadata": {
      "id": "044b4b31-2969-4af3-895d-855433b8b46d",
      "publisherId": "felixfbecker.php-debug",
      "publisherDisplayName": "felixfbecker"
    },
    "name": "php-debug",
    "publisher": "felixfbecker",
    "version": "1.12.2"
  },
  {
    "metadata": {
      "id": "5e69f001-f945-4c97-baf0-320d82a153b3",
      "publisherId": "felixfbecker.php-intellisense",
      "publisherDisplayName": "felixfbecker"
    },
    "name": "php-intellisense",
    "publisher": "felixfbecker",
    "version": "2.3.1"
  },
  {
    "metadata": {
      "id": "96fa4707-6983-4489-b7c5-d5ffdfdcce90",
      "publisherId": "esbenp.prettier-vscode",
      "publisherDisplayName": "esbenp"
    },
    "name": "prettier-vscode",
    "publisher": "esbenp",
    "version": "1.2.2"
  },
  {
    "metadata": {
      "id": "e52bce95-a629-455f-8626-e7301b9e372a",
      "publisherId": "robinbentley.sass-indented",
      "publisherDisplayName": "robinbentley"
    },
    "name": "sass-indented",
    "publisher": "robinbentley",
    "version": "1.4.8"
  },
  {
    "metadata": {
      "id": "735af542-944f-4b07-b336-9df27d7b8d84",
      "publisherId": "smlombardi.slime",
      "publisherDisplayName": "smlombardi"
    },
    "name": "slime",
    "publisher": "smlombardi",
    "version": "2.31.2"
  },
  {
    "metadata": {
      "id": "d6ba4b7b-539f-456a-b0f6-0348df44cdf3",
      "publisherId": "nikitaKunevich.snippet-creator",
      "publisherDisplayName": "nikitaKunevich"
    },
    "name": "snippet-creator",
    "publisher": "nikitaKunevich",
    "version": "0.0.4"
  },
  {
    "metadata": {
      "id": "529697b9-b343-4b1c-ba2f-f5ef692132d4",
      "publisherId": "ms-vscode.sublime-keybindings",
      "publisherDisplayName": "ms-vscode"
    },
    "name": "sublime-keybindings",
    "publisher": "ms-vscode",
    "version": "3.0.3"
  },
  {
    "metadata": {
      "id": "a150991b-031b-457a-b823-ef4c45425a1b",
      "publisherId": "karyfoundation.theme-karyfoundation-themes",
      "publisherDisplayName": "karyfoundation"
    },
    "name": "theme-karyfoundation-themes",
    "publisher": "karyfoundation",
    "version": "17.0.0"
  },
  {
    "metadata": {
      "id": "2f5dd8cb-d251-4d70-abfe-ddebcb077483",
      "publisherId": "octref.vetur",
      "publisherDisplayName": "octref"
    },
    "name": "vetur",
    "publisher": "octref",
    "version": "0.11.7"
  },
  {
    "metadata": {
      "id": "d96e79c6-8b25-4be3-8545-0e0ecefcae03",
      "publisherId": "vscodevim.vim",
      "publisherDisplayName": "vscodevim"
    },
    "name": "vim",
    "publisher": "vscodevim",
    "version": "0.11.3"
  },
  {
    "metadata": {
      "id": "d637104e-1fd7-4063-98fc-8afe46012c9b",
      "publisherId": "sleistner.vscode-fileutils",
      "publisherDisplayName": "sleistner"
    },
    "name": "vscode-fileutils",
    "publisher": "sleistner",
    "version": "2.8.1"
  },
  {
    "metadata": {
      "id": "aaee577c-f062-495a-9816-0cbd442f1d25",
      "publisherId": "ecmel.vscode-html-css",
      "publisherDisplayName": "ecmel"
    },
    "name": "vscode-html-css",
    "publisher": "ecmel",
    "version": "0.2.0"
  },
  {
    "metadata": {
      "id": "c46b0018-f317-4b6c-a785-d2039b27338f",
      "publisherId": "wix.vscode-import-cost",
      "publisherDisplayName": "wix"
    },
    "name": "vscode-import-cost",
    "publisher": "wix",
    "version": "2.6.2"
  },
  {
    "metadata": {
      "id": "ffda6552-0ad5-431b-a4fa-0905a7e4f3f0",
      "publisherId": "bmewburn.vscode-intelephense-client",
      "publisherDisplayName": "bmewburn"
    },
    "name": "vscode-intelephense-client",
    "publisher": "bmewburn",
    "version": "0.8.8"
  },
  {
    "metadata": {
      "id": "80e9cc3c-eb09-48ed-afda-f1cfd9c9ca3f",
      "publisherId": "phproberto.vscode-php-getters-setters",
      "publisherDisplayName": "phproberto"
    },
    "name": "vscode-php-getters-setters",
    "publisher": "phproberto",
    "version": "1.1.0"
  },
  {
    "metadata": {
      "id": "9b2c953d-6ad4-46d1-b18e-7e5992d1d8a6",
      "publisherId": "akamud.vscode-theme-onedark",
      "publisherDisplayName": "akamud"
    },
    "name": "vscode-theme-onedark",
    "publisher": "akamud",
    "version": "2.1.0"
  },
  {
    "metadata": {
      "id": "ee33fd31-7bb4-4252-8368-fdd5bcd94cf8",
      "publisherId": "akamud.vscode-theme-onelight",
      "publisherDisplayName": "akamud"
    },
    "name": "vscode-theme-onelight",
    "publisher": "akamud",
    "version": "2.1.0"
  }
]

Something change? I have this same issue..

+1 from me too.

I can't believe that this problem of more than 3 years ago has still not been solved, it's better to keep using SublimeText3

I think this is an essential feature. I'm just waiting for that to migrate to VS Code 😞

I am not sure we are all referring to the same thing at this point TBH.

On Mon, May 14, 2018 at 1:53 PM, Miqueias Penha notifications@github.com
wrote:

PHP Intelephense
highlight-matching-tag

Work! s2

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-388790414,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APewudsZw-Cu5mpgLrBJ8vUPagFUxB5Rks5tyXApgaJpZM4Gpk-J
.

--
Regards,

Danny Mexen.

vscode doesnt give a f about php. add this please.

I have installed PHP Intelephense. The issue solved for me.

https://github.com/bmewburn/vscode-intelephense

Just so we are clear here.

HTML code cannot be formatted (Ctrl + Shift + I) in PHP files.

@venoel Are you saying that installing PHP Intelephense allows you to do
that?

On Wed, May 30, 2018 at 8:17 PM, venoel notifications@github.com wrote:

I have installed PHP Intelephense. The issue solved for me.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-393264440,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APewuX-9NlZ3_tgvbVnOADg57CLN0yBlks5t3uItgaJpZM4Gpk-J
.

--
Regards,

Danny Mexen.

@DannyMexen.
I mean I get suggestion for tags correctly and indents are applied well.

Microsoft is acquiring GitHub!
but this issue still!
lol!

@venoel
Well noted. Glad it works for you.

No matter what I try, I just cannot format HTML code in PHP files.

On Mon, Jun 4, 2018 at 11:00 AM, venoel notifications@github.com wrote:

@DannyMexen https://github.com/DannyMexen.
I mean I get suggestion for tags correctly and indents are applied well.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-394283911,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APewuVJC1tDUt9qWZ2Hjn76-NEQjSC15ks5t5PdBgaJpZM4Gpk-J
.

--
Regards,

Danny Mexen.

VSCode definitely should have option to set 2 or more language modes for specific file types to have syntax highlighting and intellisense for all of them at the same time. You have that even now with 1 instance of VSCode, just in different files with different language modes. Honeslty I don't know why is it so hard to implement. Someone even used it earlier as a working solution although it doesn't work and never did, but it definitely should:

"files.associations": {
    "*.phtml": ["html", "php"]
}

Yeah, completely agree @SharakPL. I never understood the response given but
some more smarter folks than I am here have said that it is not an easy
thing to implement. I am not savvy enough to do it myself but because this
feature comes out of the box with ST3 for instance, I expect it to be a
default feature everywhere else.

On Wed, Jun 6, 2018 at 9:33 PM, SharakPL notifications@github.com wrote:

VSCode definitely should have option to set 2 or more language modes for
specific file types to have syntax highlighting and intellisense for all of
them at the same time. You have that even now with 1 instance of VSCode,
just in different files with different language modes. Honeslty I don't
know why is it so hard to implement. Someone even used it earlier as a
working solution although it doesn't work and never did, but it definitely
should:

"files.associations": {
"*.phtml": ["html", "php"]
}

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-395187031,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APewuQ4MZdnzRvFyDZC2LSkhfPLVHt7Wks5t6C6XgaJpZM4Gpk-J
.

--
Regards,

Danny Mexen.

agree @DannyMexen even notepad ++ have it. it's 2018 and vscode still doesnt have this feature. It's crazy.

_Close this issue, It never gonna happen._

@bsienn care to explain? Why something common in simple text editors is impossible in VSCode?

@SharakPL explain? Read the 3 year old DEAD thread, It will explain to you it ain't gonna happen.

@bsienn It's there with emnet, html on php is using emnet, try to learn it.. https://docs.emmet.io/ please... it's working anyway...

@bsienn explain me this then: why you giving up should be a reason to close this issue?

@benyaminl emmet is fine, but it only works when I create new tags. It's useless when I need to edit tags i.e. add some attributes to a link, because there's still no intellisense for html in php files

Ah that's the think I tried to ignore hahaha.. it's true anyways. Still
when I think someone tried to implement it, it's not quite easy

Sent from My Asus Pegasus X005

Pada tanggal Kam, 14 Jun 2018 19.26, SharakPL notifications@github.com
menulis:

@bsienn https://github.com/bsienn explain me this then: why you giving
up should be a reason to close this thread?

@benyaminl https://github.com/benyaminl emmet is fine, but it only
works when I create new tags. It's useless when I need to edit tags i.e. add
some attributes to a link <#m_4226514043244462616_issuecomment-359139115>,
because there's still no intellisense for html in php files

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/670#issuecomment-397275321,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACr9NMadCpzlgPV4BjF9uM2kTA4DlOz-ks5t8lZdgaJpZM4Gpk-J
.

I am trying to convert from using Brackets.io to VS Code since I've read so many great things about Intellisense. This basic feature is preventing me. It scares me that it goes back for 3 years and nothing has been done.

Does anyone know if there is a plug-in or a way to register .php files to use .html auto-complete?

thanks for your help.

Any news on this issue?
I believe that just doing the same implementation made for mixed editing in html files, where html + css + js works fine.

Another alternative is to implement in the Extension API a way to watch the file excerpt and change the selected language.

I made this because I was annoyed at nested HTML in PHP, this should format based on whatever native settings you have for html.format and editor format on save/type Format HTML in PHP.

Also I get full auto-complete, intellisense doing it this way.

@RiFi2k Hi! I try install your extension, but for me is nothing changes. In description is set the nothing to do for this extension to by work.

@BxDev Hey! So you would need to have
html.format.enable = true
editor.formatOnSave = true
and any other settings in vscode related to html formatting or editor formatting you might want, set up.

Then it wants to format nested HTML in .php files, so you also need to make sure you have a .php file with some code like this:

<?php
$hi = true;

?>
<div class="correct-formatting">
                                     <div class="wrong-formatting">
</div>
</div>

When you save it should fix the HTML div's

If your still having issues, let me know I'll help you get it rolling.

@RiFi2k thanks for the replies!
I write this in user setting:
"html.format.enable": true, "editor.formatOnSave": true
After, I create a php file whit your example, but it don't work :-(
l213wgru87dzrr

@BxDev Actually it looks as though it did it's job perfectly

<?php
$hi = true;

?>
<div class="correct-formatting">
                                     <div class="wrong-formatting">
</div>
</div>

to

<?php
$hi = true;

?>
<div class="correct-formatting">
        <div class="wrong-formatting">
        </div>
</div>

That is all it does, hopefully you weren't confused about functionality

@RiFi2k ohh yeea :) I got it :) Sorry about that. But for me, very important, is highlight pair tag in mixed php/html/js/css documents. Thanks for your work!

This is a 3 year old issue and it will never get resolved is my feeling.
This is such a basic thing to have in an editor and it's making my day-to-day work incredibly annoying.

I'll probably have to switch back to ST3, because I feel like VScode, especially lately, has been moving backwards by adding all kinds of fancy features but ignoring their core problems.

@TheDutchCoder It's because nobody wants to code PHP these days, which is the right thing to do. :D

@steebcheen please keep on the topic. Thanks

@Tyriar Anyway does anyone have been assigned for this? Or it's not?
EDIT: Oh It's assigned.. Okay

@RiFi2k Hello and thanks for trying to help! I tried your extension but it doesn't work. I tried the settings that you provided, but still no dice. Maybe it depends on the php formatter in use? What extension do you suggest to use to enable php formatting in the first place?

OK, quick update: It works on save, which is great! It doesn't work with the right click context menu. I guess it's a fair compromise :)

I thought the issue is only in my preference. When I mixed the HTML code to php the format is really messy like when I hit tab it will tab size to 4 and then add a new one now tab size is 2. I'd like to switch from ST3 to VSC but this stops me from switching to VSC. I guess I have to stay on ST3 for now.

@thanasisHS Sorry just saw this.

My extension will only run if format on save is configured, and it doesn't run as an actual PHP formatter, runs onBeforeSave.

I pretty much published my whole config as a few gists, feel free it took me months of work to get it perfect. For formatting I use PHPCBF but use this one, I know it only has 300 installs but he updated and merged the code from all the dead phpcbf extensions, it's money.
https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpcbf

Here are my gists, if anyone else is interested too in my config. It does php, js, scss, css, vue - auto formatting and linting with eslint, stylelint, phpcbf, phpcs, prettier. It's a beat once you get it all set up.

Global
https://gist.github.com/RiFi2k/d43e84788b1798252f30cac28b6f6eda

Project
https://gist.github.com/RiFi2k/42e294f3785bdbbc2641c4b18955e16f

All the dotfiles, composer.json, package.json, php ruleset
https://gist.github.com/RiFi2k/8b753d1f12a36760f3ee6e1322daf708

Closing this issue. I´ve explained the reason in the description of the issue above.

thanks. Code is getting more ruined each day. I thought you at Microsoft were cool with all this FOSS-initative, but it is still not independent, but focused to make money by advertising Github and Azure.

@jens1o I´m confused, this decision is all about fostering the OSS ecosystem. The referenced extensions are OSS projects, please help to make them better. The resources of the VS Code team are not unlimited.

Also, please do not forget our Code of Conduct and let´s communicate in a respectful way.

I just don't understand why you prioritize tasks over other, although the community definitely wants those. I only hear "issue reduction" and "out of scope", and, oh yeah, "limited resources"(that's why the community is here, lol). Nobody complains about things not coming soon, but a little bit more focus on the needs of the community would definitely help. Why do we need to keep the issue number low, even though they don't pollute anything? In my eyes, the Code roadmap passed the sweet spot 2 iterations ago. Now, it is all about earning money(with the big community earned throughout the years; I'm using it since the first demo of Build(); everyday) by integrating paid and third-party products(like GitHub, owned by Microsoft).

I'm saying that I'm not feeling welcome in this community anymore(and I'm honestly disappointed), I don't attack you personal in any way, so there is no reason to reference the COC here. It is part of FOSS-software to have open discussions.

But speaking of COC, I'd quote this:

Understand disagreements

I don't get why you want to shut me down, only because I disagree with the politics you do.

I'm trying to understand why you changed your politics, so could you please elaborate?

@egamma I don't think that your reason for closing this issue is reasonable. I understand that visual studio code can't and shouldn't provide all the features out of the box, but HTML support for PHP language should be one of the most basic feature for a PHP editor. Maybe most of the features for PHP should be provided by extensions, but this one shouldn't. Lots of editors have this feature, even the simple text editor, Notepad++, have this feature. This is part of the basic PHP grammar, and you can't write PHP without it. An editor shouldn't say that it supports PHP without this feature, for it can't read PHP in the right way.

And why does Javascript in HTML file works well and CSS in HTML works well without any extension in vscode? It seems that vscode have this feature but don't want to make a similar one for PHP, That's unfair.

This feature is really important for PHP users, and most user won't try to search these issues and they know nothing about the extensions which can help them get these basic and necessary features. These users may simply download this editor, install it and find this "bug", then uninstall it immediately and get a very bad impression about vscode. They won't say anything here. All the users who want to share their opinions here are the people who really want vscode to be better. The feeling for writing PHP code without this funtion is really too painful, you can't tell the blocks apart, you have to count the html tags manually, or convert the file format from php to html, and from html to php many times. All the other languages I have ever tried on the vscode won't have such bad feelings without any extension installed. Users won't know the reason, they just care about the user experience. Please consider about this and do something, even adding a little bit highlight is good too:

  • provide some basic support for HTML, or
  • provide an official extension with this feature and install automatically when using PHP
  • or even a simple recommedation for all the PHP user and install the recommended extension with one click, then get this feature and make vscode be able to really support PHP

Agreed, @popcorner is correct this is essential for PHP devs and considering WordPress powers ~30% of the internet or more and pretty much every theme or plugin has PHP nested with HTML in every template file. So basically a ridiculous amount of users right there in need of this.

Now I actually think the core of this whole issue lies with the fact you can not register multiple formatting extensions at the same time. There is basically kind of a race on that hook and only one can win, plus you can't see as a user what is trying to run when, and which one actually ran. So for a PHP file, odiously your going to go with a formatting extension that does PHP code over HTML. But if you could chain formatting extensions and there was a hook order or something that was changeable then you could register a PHP and an HTML and then set the priority / order for one to run first / last. For example this whole issue is fixed if you can...

Step One run PHPCBF or similar PHP formatting extension.
Step Two run js-beautify html formatting which just skips over all the PHP anyways and does the HTML only, which is the exact same thing I do in my extension, Format HTML in PHP, to fix the problem. But I have to run it onBeforeSave instead of using the default formatting registration, but this shouldn't have to be the solution.

So to sum it up, it's very needed, but instead of fixing / not fixing the issue, why not explore my idea above and then you end up having a way better experience with every language and formatting, for users and extension developers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sirius1024 picture sirius1024  Â·  3Comments

VitorLuizC picture VitorLuizC  Â·  3Comments

philipgiuliani picture philipgiuliani  Â·  3Comments

borekb picture borekb  Â·  3Comments

curtw picture curtw  Â·  3Comments