Content assist in the ST-editor

A very instrumental function to quickly enter ST-code is Content Assist.

In this article:

Adding ST elements by adding keywords and using templates

How to add ST elements by adding keywords and using templates:

  1. Position within the ST-code where you need the appropriate ST-code.

  2. Start content assist: context menu within ST-editor, SourceContent Assist
    Keyboard shortcut: Press Ctrl+Space.
    Result: You see a list with all elements that are possible within the current context of the ST-code.

  3. Do one of the following:

    • Enter one or more letters. This displays a list with all elements fitting your input.
      Example 1: Enter the beginning of a →keyword; such as: PRO – A keyword is prefixed by icon  in the list.
      Example 2: Enter the beginning of a →template; such as: fun – A template is prefixed by icon  in the list.
      For details on a template: Click on a template or select it with the cursor movement keys ↑ (Up) or ↓ (Down) in order to see the code for the template to the left of the list. 

    • Click an element in the list or select it (by using the mouse or the cursor movement keys) and press the Enter-key.
      Result: The keyword or the code of the template is inserted at the current position. If the template contains one or more template variables, the first template variable is selected.

      What is a template variable?

      A template variable marks an editable location in the code of the template. They can be resolves to a concrete value when the code of the template is evaluated in its context. They can also provide a list of alternative proposals valid at the given location. For instance, a template variable within a declaration template stands in for the identifier that is needed within a declaration. 

    • Press the ESC-key to close the list and exit content assist.

  4.  If the inserted code contains template variables, overwrite these template variables as follows

    1. As the first template variable is already selected, just type the requested identifier. (If the same template variable is repeatedly used in the code, the identifier is automatically entered at all of these places.)

    2. Press the Tab-key to select the next template variable. Overwrite it as well.

    3. Press the Tab-key until there are no template variables left to overwrite. Then you leave the code of the template.

Neuron has provided many templates for you to use. You can view them in the preferences: menu WindowPreferences, group ST-ObjectTemplates
There, you may also create your own templates or edit the existing ones.

Declaring external variables based on global variables

If you declare an →external variable (VAR_EXTERNAL...END_VAR) as described under "Declaration of external variables in ST", it is imperative that you know the name and data type of the basic →global variable. If you declare an external variable and no global variable has been declared for it, the application cannot be built because the external variable cannot be resolved.

The best practice is to use the second list of the content assist of the ST editor so that an external variable is declared based on an already existing global variable and so that the external variable is added in the ST code where the content assist has been started:

  1. Position the mouse pointer at the position where you want to add the external variable. Usually, this is in the body of the language element.

  2. Start the content assist: From the context menu of the ST editor, select Content Assist. Alternative: Press Ctrl+Space.
    Result: A list is displayed with all →variables already declared in the POU and with all available →functions and →function blocks.

  3. Now press Ctrl+Space again.
    Result: The list changes to display the global variables (icon ) that have been declared in →programs or →resources (within a PLC-object). The entry for the global variable includes its data type. Example: portSetting (LocalConfiguration.local) : INT – Meaning: This is the global variable with name portSetting and →data type INT. The global variable is declared in the →configuration LocalConfiguration and the resource local.

  4. Enter one or more letters. This displays a list with all elements fitting your input.
    Example: Enter port. The list provides all global variables containing the text port.

  5. Click an element in the list or select it (by using the mouse or the cursor movement keys) and press the Enter-key.
    If you want to close the list without any action, click the primary mouse button outside the input field or press the ESC-key

Good to know

(grey lightbulb) The application navigator provides the possibility to declare external variables and to have the declarations based on the already existing global variables. This is done when you drag the global variables from a global-object onto a →POU. Details: See "Declaring external variables by dragging and dropping global variables into POUs".