Code Assist

The Code Assist feature provides a context-sensitive list of pre-existing code elements that you can enter at the cursor point in order to complete code that you have partially entered.  Code Assist works with types both PHP and HTML.

code assist Available for the following:

You can use this function to help insert or finish a tag, function or line of code in the editor as well as to select and insert templates and all of the following:

    Note:  The cursor should be placed at the end of the inserted text.

    Note:  If the inserted code is a function that requires variables - place the cursor inside the parentheses.

Function Parameters

A Function Parameter Hint window opens by placing the cursor between the parentheses of a function call. You can open the window manually by pressing (Ctrl+Shift+Space). The Hint window lists function's available parameters (shown bolded). Close the window by pressing the "Esc" key.

HTML Code Assist

Activating Code Assist

  1. Open the file in the Editor and place the cursor at the location where you want to enter the code.

  2. Enter the first few characters of the code.

  3. Press Ctrl+Space.

  4. The Code Assist drop-down menu will open and display an alphabetical list of the available code, starting with the characters you have entered.

Figure:  -  Code Assist Drop Down Menu

  1. Each type of code element has a unique icon.

Figure:  -  Code Assist Icons

  1. Select the desired code from the list mouse (double-click or Enter).

Adding Code to the Code Assist Menu

You can add code elements to Code Assist for use within the scope of the current active function, file or project.

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

  1. Create a PHP file as shown below.

    1. <? 

    2.                 define('continent','africa');
                   $control = ''

    3.                  $mail = 'int@eclipse.org'

    4.                  function media()  {

    5.                       $music = '';

    6.                       $messenger = '';

    7.                       $                            --------- Location_1

    8.                                                }

    9.               $                                    ---------Location_2

    10.     ?>

  2. Place the cursor at the $, on line "7" marked by "Location_1". This is within  function "media".

  3. Type the letter "m" and click CTRL-SPACE to activate Code Assist. Code Assist will open with the options you have defined within the function.

  4. The variable $mail (not within the scope of "media()" ) is not available.

Figure:  -  Adding Code to Code Assist

  1. Next, place the cursor at the $, on line "9" marked  by "Location_2".

  2. Type the letter "m" and click CTRL-SPACE to activate Code Assist.

Figure:  -  Code Assist - Context Sensitive (within function)

Note: "Location_2" is not part of function "media", therefore $music and $messenger are not available here.

The variable "mail" is potentially available to the entire file and therefore appears in the Code Assist list when it is activated at "Location_2".

Because the cursor is not within the context of the function "media", Code Assist now opens without the "media's" variables ($music and $messenger ); they are available only when within the defining function.

Added Code - Available Within the Same Project

Code elements defined in one file are available for use by other files within the same project. The example shown above was carried out in the PHP file named PHPfile2.php. The file was created as part of the project named "New_PHP_Project".

The code element defined in line ii of the PHP file PHPfile2.php [ i.e., the define: define('continent','africa') ] is available to all files in the same project. When the element is highlighted - Code Assist displays the original location of the code element and all other information available.

Figure:  -  Code Assist; New Elements Available within Same Project

@var tag as Class Type Hint

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

In the example below, '$myVar->' opens the code assist with 'Test' class function as defined in the comment.

Figure: -  @var tag

Note: Without the comment, code assist will not be available for the function.

Code Assist Navigation

Use the following controls to navigate within the Code Assist drop-down menu.

Keyboard
Mouse

Setting PHP Preferences

  1. Select Preferences from the Window menu.

  2. Go to PHP | Editor | Code Assist.

  3. Select your configuration options.

  4. In addition, you can set a preference that causes code assist to pop up automatically when certain characters are typed, as in HTML and XML.

Figure:  -  Setting Code Assist Preferences

Setting HTML Preferences

  1. Select Preferences from the Window menu.

  2. Select Web and XML Files from the navigator, followed by HTML Files. Expand. Select HTML Source.

  3. In the Code Assist group box, select the Auto-Activation check box.

  4. Supply any additional characters that should trigger code assist .

  5. If your cursor location enables code assist, a pop-up list of all available choices is displayed. For each of these choices, a brief description of the code is provided.

  6. Complete the options for HTML Styles and HTML Source.