PDT auto completion tips (for agavi)

In PDT (php development tools for eclipse) you are able to do auto completion (e.g. ctrl+space) on most of the classes, as long as they are defined properly or you have a proper php-doc set up. Check that tutorial, if you want to set up PDT.

Graste posted a snippet, which tells eclipse for the project (in this example it's agavi) that the variables (which are common for templates), like $template (or $ro, $rd and so on) are defined with correct type.

Here is a slightly modified autocomplete.php:

$slots = array();
$template = array(); // agavi 0.11 default
$t = array(); // agavi 1.0 default
$tm = new AgaviTranslationManager();
$ro = new AgaviWebRouting();
$rq = new AgaviWebRequest();
$ct = new AgaviController();
$us = new AgaviSecurityUser();
$rd = new AgaviWebRequestDataHolder();

Just save that file to autocomplete.php in your project structure -> eclipse will use this classes as default, so you have neat auto completion even in agavi templates.

If you have return type for a function, and want the caller to be able to autocomplete: just use proper php-docs. For example, the following will give SomeClass-typed elements on a function test123:

 * [strong]@return SomeClass[/strong]
function test123() {
    /* ... */

If you just want autocomplete for a specific scope, you may use the following:

if (false) $instance = new [strong]SomeClass[/strong]();

or better

/* @var $instance [strong]SomeClass[/strong] */

and auto completion on $instance will work like if it was a SomeClass.

Got another tip? Feel free to add it in the comments!

In agavi, eclipse, open source, pdt for eclipse, php by
@ 23 Feb 2009, Comments at Reddit & Hackernews