Working with Content Assist

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

Contents:

Purpose and Usage

 

Activating Content Assist

 

Making Content Assist Elements Available Within the Same Scope

 

Function Parameter Hints

 

Class Type Hints

 

Configuring Content Assist

 

 

Purpose and Usage

The Content 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:

code_assist_triangle.png

Reserved PHP Words

code_assist_circle.png

Functions

template_icon.png

Templates

classes_icon.png

Classes

interfaces_icon.png

Interfaces

constants_icon.png

Constants

variables_icon.png

Variables (public)

 

Content 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:

Content Assist works with both PHP and HTML.

Activating Content Assist

By default, the Content 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 Content Assist:

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

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

pri Code Asisst Box

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

"define()" appears on the edit line.

Note:

If the Content Assist window does not open automatically, place your cursor at the required location and press Ctrl+Space.
To enable the Content Assist window to open automatically, go to the Content Assist Preferences page, accessed from Window | Preferences | PHP | Editor | Content Assist and mark the 'Enable auto-activation' checkbox.

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.

Parameter Hint

Back to Top

Making Content 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 Content Assist.

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

 

 

Instructions on how to complete a procedure

The following procedure demonstrates using Content 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 Content Assist window will be displayed with the variables "$messenger" and "$music", 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 Content 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 Content 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 Content 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 Content Assist. Double-click one of the define options.

  3. Between the parentheses, type "cont" and press Ctrl+Space to activate Content 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, Content Assist displays the original location of the code element, its value ('africa') and all other information available.

Element Information

Back to Top

Class Type Hints

By using a comment you can assign a variable its exact class value. This assignment will affect the content 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";

  }

}

 

/* @var $myVar Test */

$myVar = getClass();

 

$myVar->

?>

  1. Place your cursor after  '$myVar->' (on the line above the closing PHP tag) and press Ctrl+Space to activate Content Assist. Content 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, Content Assist will not be available for the function.

Back to Top

Configuring Content Assist

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

 

 

link_icon.png

Related Links

Content Assist

Using Content Assist

Content Assist Preferences

Basic Tutorials

Hover Support

Commenting PHP DocBlocks