Code formatter breaks when escaping PHP inside JavaScript

PHP Tools [?] extends Visual Studio with set of advanced features to work more efficiently with PHP code.

Code formatter breaks when escaping PHP inside JavaScript

Postby jazz » February 19th, 2017, 11:59 pm

Hi guys,

I'm having a few problems with some of my PHTML view scripts. I use the PHP editor to edit them as they can contain PHP but are mostly HTML and JavaScript. From memory this used to work fine in VS2015.

However, VS2017 is giving me a nasty error when I try and do something like the following:

Code: Select all
<h1>Test Code</h1>

<script>
    var test = '<?=$testvalue;?>';
</script>


When I run the formatter I get the following error popup:

Object reference not set to an instance of an object.

This is the simplest form of the code required to get it to break. Also syntax coloring no longer works. If I remove the PHP escape section then both the HTML and JavaScript syntax coloring works and I no longer get the error dialog. So it's the "<?=$testvalue;?>" breakout to PHP that is causing a problem.

Side note: JavaScript intellisense doesn't work inside <script> tags? Not a big issue. Just wondering if it's supposed to.

As always, thanks for the efforts. Let me know if you need any more info.
Try Hazaar MVC - http://www.hazaarmvc.com
The MVC Framework that makes PHP not suck!

Image
User avatar
jazz
 
Posts: 41
Joined: August 25th, 2016, 1:59 am
Location: Canberra, Australia

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby Miloslav Beno » February 22nd, 2017, 10:03 am

Hello Jazz,

Thanks again for your feedback.

These are several issues with VS2017 (vs2015 is fine):

1.) Javascript language service is not enabled in php editor in VS2017 due to bug on Microsoft end. They are working on it, but currently it's not clear when it's going to be out.

2.) Syntax highlighting of JS works without php code in it. We have solution for this (smart template already has that), but to employ it in php we need to wait for solution for issue #1.

3.) Object reference not set to an instance of an object during formatting. I'm going to take a look at this one and get back to you.

Thank you very much for your continuous feedback!
Miloslav Beno │ DEVSENSE s.r.o. │ @miloslavbenomiloslav@devsense.com
User avatar
Miloslav Beno
 
Posts: 1252
Joined: January 7th, 2012, 8:36 pm

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby jazz » February 24th, 2017, 10:07 pm

Thanks for the update.

I'm actually using this extension every day to help me develop my PHP MVC framework, Hazaar MVC, and I find it an invaluable tool. Just let me know if I get too annoying. haha.

Thanks.
Try Hazaar MVC - http://www.hazaarmvc.com
The MVC Framework that makes PHP not suck!

Image
User avatar
jazz
 
Posts: 41
Joined: August 25th, 2016, 1:59 am
Location: Canberra, Australia

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby Miloslav Beno » February 27th, 2017, 10:53 am

Hi Jazz,

hehe, no wories. We love feedback, so please continue ;-)

So far we haven't been able to replicate issue #3, does this happen all the time or in some specific file?

Thanks!
Miloslav Beno │ DEVSENSE s.r.o. │ @miloslavbenomiloslav@devsense.com
User avatar
Miloslav Beno
 
Posts: 1252
Joined: January 7th, 2012, 8:36 pm

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby jazz » February 28th, 2017, 10:44 pm

To get that error to pop up, all I have to do is create a new file that is opened by the PHP editor. For me, this is my .phtml view files. But it also does this by creating a new PHP class and just putting this in the content:

Code: Select all
<script>
    var test = '<?=$thing;?>';
</script>


Then run the code formatter (CTRL-SHIFT-K for me, or Edit/Advanced/Format Document) and you should see the message error dialog. This happens consistently when ANY PHP code is added inside JavaScript code.

Thanks.
Try Hazaar MVC - http://www.hazaarmvc.com
The MVC Framework that makes PHP not suck!

Image
User avatar
jazz
 
Posts: 41
Joined: August 25th, 2016, 1:59 am
Location: Canberra, Australia

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby info@dotcompanion.de » September 17th, 2018, 6:44 pm

Any news on the javascript problem?
I have the same problem in many view files.
The way it is right now is almost unusable.
Not only that the javascript language sevice does not work but even simple formatting like manual tab indent isn't working.
This makes editing files a pain.
info@dotcompanion.de
 
Posts: 4
Joined: September 17th, 2018, 6:13 pm

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby Miloslav Beno » September 20th, 2018, 2:22 pm

Hi guys,

Thank you for noticing. We are currently investigating this. We suspect recent VS update caused this behaviour. I will notify you once I know more.

Thanks
Miloslav Beno │ DEVSENSE s.r.o. │ @miloslavbenomiloslav@devsense.com
User avatar
Miloslav Beno
 
Posts: 1252
Joined: January 7th, 2012, 8:36 pm

Re: Code formatter breaks when escaping PHP inside JavaScrip

Postby JefferyS » October 25th, 2018, 2:45 am

I'm having the same problem. I also noticed that the JavaScript code coloring goes away too. All the JavaScript is white.

Is there any update to this problem?

Thanks,

Jeffery
JefferyS
 
Posts: 4
Joined: March 15th, 2017, 1:45 am


Return to PHP Tools

Who is online

Users browsing this forum: No registered users and 32 guests

cron

User Control Panel

Login

Who is online

In total there are 32 users online :: 0 registered, 0 hidden and 32 guests (based on users active over the past 5 minutes)
Most users ever online was 256 on March 28th, 2024, 9:42 am

Users browsing this forum: No registered users and 32 guests