Page 1 of 1

Code formatter breaks when escaping PHP inside JavaScript

PostPosted: February 19th, 2017, 11:59 pm
by jazz
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.

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: February 22nd, 2017, 10:03 am
by Miloslav Beno
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!

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: February 24th, 2017, 10:07 pm
by jazz
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.

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: February 27th, 2017, 10:53 am
by Miloslav Beno
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!

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: February 28th, 2017, 10:44 pm
by jazz
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.

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: September 17th, 2018, 6:44 pm
by info@dotcompanion.de
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.

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: September 20th, 2018, 2:22 pm
by Miloslav Beno
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

Re: Code formatter breaks when escaping PHP inside JavaScrip

PostPosted: October 25th, 2018, 2:45 am
by JefferyS
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