Working with Code Assist

The purpose of this tutorial is to teach you how to use PDT's Code Assist function in order to write code quickly, easily, and accurately.

Contents

Purpose and Usage

 

Activating Code Assist

 

Making Code Assist Elements Available Within the Same Scope

 

Function Parameter Hints

 

Class Type Hints

 

Configuring Code Assist

 

 

Purpose and Usage

The Code Assist feature enables the selection and insertion of existing code elements to complete partially entered code.

A list of possible code elements appears in relevant locations within your files according to the context of your cursor, which you can then select to be automatically entered into your code.

 

Each type of code element will have a unique icon:

Reserved PHP Words

Functions

Templates

Classes

Interfaces

Constants

Variables

 

Code Assist works with the following elements: PHP Classes, Functions, Variables, Constants, Keywords, Interfaces, Attributes, Values, Nested Functions, Names and Syntax, as well as all user defined Classes, Functions, and Constants.

Note:

Code Assist works with both PHP and HTML.

Activating Code Assist

By default, the Code Assist options will be automatically displayed once the first few characters of the code have been entered.

 

 

Instructions on how to complete a procedure

The following procedure demonstrates using Code Assist:

  1. Create a new PHP File called 'File1'.

  1. On the line beneath the opening PHP tag, type "def".

  2. The Code Assist window will be displayed with a list of suitable code completion options:


 

  1. Double-click the first define function from the Code Completion window, or press Enter.

"define()" appears on the edit line.

Note:

If the Code Assist window does not open automatically, place your cursor at the required location and press Ctrl+Space.

Back to Top

Function Parameter Hints  

When entering a function call, a Function Parameter Hint box will be displayed detailing the types of parameters that should be entered within the parentheses of the function call.

 

 

Instructions on how to complete a procedure

The following procedure demonstrates using the Function Parameter Hint feature:

  1. Place your cursor between the parentheses of the above function call: "define()"

  2. Press Ctrl+Shift+Space.

A function parameter hint box will be displayed indicating the types of parameters that should be inserted between the parentheses.

 

Back to Top

Making Code Assist Elements Available Within the Same Scope

Added Code – Available within the same function and file

Elements within the same scope (e.g. within the same project, file or function) will be available for use with Code Assist.

Variables belonging to different scopes are not available to each other via Code Assist.

 

 

Instructions on how to complete a procedure

The following procedure demonstrates using Code Assist for inserting elements within the same function and file:

  1. Edit your PHP File ('File1') so that it contains the following code:

<?php

define('continent','africa');

$control = '';

$mail = 'int@eclipse.org';

function media() {

$music = '';

$messenger = '';

$                        /*--------- Location_1*/

}

$                                  /* ---------Location_2*/

?>

  1. Place the cursor at the "$" marked by "Location_1". This is within function "media".

  2. Type the letter "m". The Code Assist window will be displayed with the variables "$messenger" and "$media", which were defined within the function.
    Note that the variable $mail (not within the scope of "media()" ) is not available.

  3. Next, place the cursor at the "$" marked by "Location_2".

  4. Type the letter "m". The Code Assist window will be displayed with the variable $mail, which is within the same file.
    Note that media's variables -  $music and $messenger  - are not within the function 'media' and so are not displayed.

  5. Select 'mail' from the Code Assist window to insert it into the script.

 

Back to Top

Added Code - Available Within the Same Project

Code elements defined in one file are also available for use by other files within the same project.

 

 

Instructions on how to complete a procedure

The following steps demonstrate using Code Assist for inserting elements within the same project:

  1. Within the same project as "File1", create a new PHP file called "File2".

  2. On the line beneath the opening PHP tag, type "def" and press Ctrl+Space to activate Code Assist. Select one of the define options and double-click it.

  3. Between the parentheses, type "cont" and press Ctrl+Space to activate Code Assist. The element 'continent', defined in "File1", will be available.

  4. Double-click 'continent' to enter it into your code.

When the element is highlighted, Code Assist displays the original location of the code element, its value ('africa') and all other information available.

Back to Top

Class Type Hints

By using a comment you can assign a variable its exact class value. This assignment will affect the code assist of this variable accordingly.

 

 

Instructions on how to complete a procedure

To see and trial this feature:

  1. Create a new PHP file with the following code:

<?php

function getClass() {

return new Test();

}

class Test {

function printValues($a, $b) {

echo "Values: $a, $b";

}

}

$myVar = getClass();

/* @var $myVar Test */

$myVar->

?>

  1. Place your cursor after  '$myVar->' (on the line above the closing PHP tag) and press Ctrl+Space to activate Code Assist. Code Assist will open with the function defined in 'Test' class (printValues($a, $b)). Double click it to enter it into your code.

 

Note:    

Without the comment, Code Assist will not be available for the function.

Back to Top

Configuring Code Assist

Code Assist options can be configured through the  Code Assist Preferences page, accessible from Window | Preferences | PHP | Editor | Code Assist.

 

 

Related Links

Related Links

Using Code Assist

Code Assist Preferences

Basic Tutorials

Hover Support

Commenting PHP DocBlocks

Using Templates