Code completion
Describes the features of the IDE editor that provide assistance when you enter OPL code.
Overview
Code completion can be invoked at any time in the IDE editor while creating or editing an OPL model. The code completion feature prompts you with a context-sensitive list, and enables you to select model elements from the list and insert them into your model.
Code completion is activated by pressing Ctrl + Space, or after typing a dot (.), in the .mod file (modeling or scripting part).
You can filter elements by typing the first character or characters, to display a restricted list of elements.
The list of elements proposed is context sensitive, in that code completion can detect whether you are writing a CPLEX® or CP Optimizer model, and prompt you only with the relevant code elements. It can detect whether you are entering OPL modeling code or scripting code, and display an appropriate list of code elements. It can also detect model elements defined by the user in the modeling part of the code.
The proposals that follow a dot (.), depend on what precedes the dot. For example,
after <tuplename>. the proposals, in a modeling
context, would contain field names defined by the tuple.
In a modeling context (not scripting), the dot syntax applies only to tuples and tuple sets.
Working with code completion
The proposals made by code completion depend on whether you are in the modeling part of the code, or in the scripting part.
Modeling
- In a new line, press Ctrl + Space. The window opens, displaying entries
that are appropriate for the context. In this example, the code completion was activated in the
modeling part of the code, and OPL keywords and functions are proposed.

- To filter the display, type one or more characters of the keyword or function you are searching
for, before or after pressing Ctrl + Space. For example, here the user types
the letter m.

- To insert the selection, double-click it or select it and press Enter. In
this example, the user has selected the
minimizekeyword, and it is inserted into the editor at the cursor position.
Note that the red X symbol appears in the left margin of the editor at this point, because
minimizehas required arguments that have not yet been supplied.
Example of dot completion on a tuple, in a modeling context (not scripting).
Tuple field completion is type aware, so it shows only valid fields for a given tuple.
The code
extract in the following screen capture shows a simple example of dot completion on a tuple. The
dropdown list is sorted by int since that is what is being declared (int
cost =). If you type a 'c' after the dot, the list will contain only "cost".

In this example, f you type 'c' after the dot, to filter elements beginning with 'c', the
line is completed as int cost = t.cost, because there are no other relevant
possibilities.
Scripting
In ILOG® Script, class methods and properties are presented, sorted alphabetically when you type a
dot after a scripting element, or when you press Ctrl + Space at the
beginning of a line. In the code extract in the following screen capture, the scripting keyword
thisOplModel is followed by a dot. The class methods and properties in ILOG Script are displayed.

The documentation for the selected ILOG Script method is also displayed.
You can filter on scripting keywords such as Opl
and thisOplModel. In the following screen capture, the user has filtered on 'g'
after the dot, displaying only the functions that begin with 'g'.
