Page 1 of 1

IntelliSense not working in some files.

PostPosted: February 11th, 2013, 6:28 am
by codeowl
Hi there,

I am working on a CakePHP project and there seems to be no IntelliSense in some files. For example I have the following file:
index.ctp (I have mapped the .ctp file extension to PHP Editor in the VS options)

Code: Select all
<h1>Blog posts</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Created</th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $post): ?>
        <tr>
            <td><?php echo $post['Post']['id']; ?></td>
            <td>
                <?php echo $this->Html->link(
                    $post['Post']['title'],
                    array(
                        'controller' => 'posts',
                        'action' => 'view',
                        $post['Post']['id']
                    )
                ); ?>
            </td>
            <td><?php echo $post['Post']['created']; ?></td>
        </tr>
    <?php endforeach; ?>
    <?php unset($post); ?>
</table>


I can't goto definition on the link method. How can I get this to work?
Do I have to add a reference to the file that has the class with this method to the index.ctp somehow?

Some info regarding CakePHP:
You might have noticed the use of an object called $this->Html. This is an instance of the CakePHP HtmlHelper class. CakePHP comes with a set of view helpers that make things like linking, form output, JavaScript and Ajax a snap. You can learn more about how to use them in Helpers.
http://book.cakephp.org/2.0/en/views/helpers.html

I am using VS2012, on Windows 7 and all the above code is rendering correctly in the browser.

Regards,

Scott

Re: IntelliSense not working in some files.

PostPosted: February 11th, 2013, 9:08 am
by CFI
I am also working with CakePHP, but as this is nothing "generic" I did not complain about this...
In the controller I got my helpers/components via PHPDoc tags, which works fine.

Maybee something "generic" could be implemented to support "generic template engines", like a "/* @baseclass BaseController */" at the top of a PHP file, to tell IntelliSense, that the file is in the "class context of BaseController".

Re: IntelliSense not working in some files.

PostPosted: February 11th, 2013, 1:42 pm
by Jakub Misek
Hi,

Please check whether the script file with non-.php extension has highlighted PHP syntax (close it and reopen is probably needed).

Once scripts are highlighted, they should be visible for IntelliSense too.

Thanks,

Re: IntelliSense not working in some files.

PostPosted: February 11th, 2013, 1:56 pm
by CFI
IntelliSense in general works.
It just does not know "what $this is" - and this is the problem, as there is no "generic way" to find out.
For example in CakePHP in the file "ROOT/View/Home/index.ctp" $this would be an instance of HomeController from "ROOT/Controller/HomeController.php".
As this is something "framework dependant" I suggested the somehow generic approach of e.g. adding a comment at the top of "index.ctp" like "/* @baseclass HomeController */" to tell IntelliSense what to use for $this.

Re: IntelliSense not working in some files.

PostPosted: February 11th, 2013, 2:10 pm
by Jakub Misek
Yes, $this is known issue ... it is very special variable name, and in case of global code, it is very difficult to find out what type it is ... we are ignoring $this for now, but we are open to any suggestions, eventually we can make it working for certain frameworks.

Thanks!

Re: IntelliSense not working in some files.

PostPosted: February 11th, 2013, 9:50 pm
by codeowl
Jakub,

Thanks for quick the response again. Yes mate the highlighted PHP syntax is working, as I have set-up the .ctp extension in the File Extension options, and IntelliSense for standard PHP functions is working.

The issue is described well by CFI (thanks for your input mate ;-), and his suggestion is a good one:

"As this is something "framework dependant" I suggested the somehow generic approach of e.g. adding a comment at the top of "index.ctp" like "/* @baseclass HomeController */" to tell IntelliSense what to use for $this."

Is there anything like this in PHP Tools?

BTW: Great to see an active forum here, and good support. Thanks to all participating ;-)

Regards,

Scott

Re: IntelliSense not working in some files.

PostPosted: February 12th, 2013, 11:02 am
by Jakub Misek
Thank you!

We are planning new release soon, following PHPDoc syntax can be supported for this case?
Code: Select all
/**
 * @global TypeName $this
 */

Re: IntelliSense not working in some files.

PostPosted: February 12th, 2013, 11:40 am
by CFI
The PHPDoc syntax is also great and would fullfill all needs.