Code Insight (IDE Tutorial)
Go Up to The Code Editor Index (IDE Tutorial)
Contents
Code Insight refers to a subset of features embedded in the Code Editor (such as Code Completion, Parameter Completion, Code Hints, Tooltip Expression, Tooltip Insight, Go To Definition, Block Completion, Class Completion, and Error Insight) that aid in the code writing process. These features help identify common statements you want to insert into your code, and assist you in the selection of properties and methods. Some of these features are described in more detail in the following subsections.
To enable and configure Code Insight features, choose Tools > Options > User Interface > Editor and click on Code Insight option.
Code Completion — Ctrl+Space
The Code Completion feature displays a drop-down list of all items that contain the typed string anywhere in an identifier.
To invoke Code Completion, press Ctrl+Space
while using the Code Editor. Select the character and press Enter
to insert the text in the code at the cursor location.
Code Completion is also automatically invoked at some code locations, such as when you type a period "." in Delphi
, or a period ".", arrow "->", scope "::" or header "#include <" statement in C++
.
You invoke Code Completion for your specific language in the following ways:
C++
- Press
Ctrl+Space
(always invokes Code Completion). - Enter
.
or->
(only works when Auto Invoke is enabled on the Code Insight page). - To cancel a Code Completion request, press the
Esc
key.
- Press
Delphi
- Press
Ctrl+Space
(always invokes Code Completion). - Enter
.
(only works when Auto Invoke is enabled on the Code Insight page). - To cancel a Code Completion request, press the
Esc
key.
- Press
When you type characters, the selection/match behavior as you type considers the following situations:
- When there is an exact match between what is typed and an identifier, it is selected.
- Otherwise, the first identifier that starts with what was typed is selected.
- Otherwise, the first identifier that contains what was typed is selected.
For example, when you type MyControl in the Editor, invoke Code Completion, and then when you type Rect, not only the properties or methods beginning with Rect are shown, but also ClientRect, BoundsRect, etc. Anything containing Rect inside the identifier string are shown.
Code Completion works correctly, including correct results, in situations including:
- A new file that does not yet exist on disk.
- A new project where neither the project nor any units exist on disk.
- A modified unit, not yet saved, where the current in-IDE code has changes that affect completion results.
- Results are correct (and changed correctly) when changing target platforms or other project options.
- Matching is case-insensitive.
- Code Completion does not work inside anonymous methods.
Parameter Completion — Ctrl+Shift+Space
The Parameter Completion is auto-invoked after opening a left bracket of a function call, or pressing Ctrl+Shift+Space
while using the Code Editor. A popup window displays a hint containing argument names and types for method calls. You can type characters to match those in the selection and press Return
to insert the text in
the code at the cursor location.
Examples:
C++
Delphi
Code Hints
The Code Hints displays a hint containing information about the symbol such as type, file, and line number, where declared. You can display Code Hints by hovering the mouse over an identifier in your code, while working in the Code Editor.
Delphi
when you have disabled the Help Insight feature. To disable the Help Insight feature, uncheck Tooltip Help Insight on the Tools > Options > Editor Options > Code Insight dialog box.Example:
Tooltip Expression Evaluation
The Tooltip Expression Evaluation displays the current value of a variable when you position the cursor over it. This feature is available when the program execution is paused during a debugging session.
Examples:
C++
Delphi
Tooltip Insight
The Tooltip Insight displays information in a popup window when the mouse hovers above a symbol.
Tooltip Symbol Insight
The Tooltip Symbol Insight displays declaration information in a tooltip window for any identifier by passing the cursor over a symbol in the Code Editor.
Examples:
C++
Delphi
Tooltip Help Insight — Ctrl+Shift+H
The Tooltip Help Insight displays a hint containing information about the symbol such as type, file, line number where declared, and any XML documentation associated with the symbol (if available).
Invoke the Tooltip Help Insight by hovering the mouse over an identifier in your code, while working in the Code Editor. You can also invoke it by pressing Ctrl+Shift+H
.
Examples:
Delphi
Find Declaration — Ctrl+Click
Find Declaration navigates to the location where a type or variable is defined.
While using the Code Editor you can use Ctrl+Click
to automatically "jump to" the code that defines an identifier. To browse code, hold down the Ctrl
key while hovering the mouse over the name of any class, variable, property, method, or other identifier.
The mouse pointer turns into a hand, and the identifier appears highlighted and underlined. Click the highlighted identifier, and the Code Editor jumps to the declaration of the identifier, opening the source file, if necessary. You can do the same thing by right-clicking an identifier and choosing Find Declaration. Pressing Alt+Left Arrow
returns you to where you browsed from.
Find Declaration can find and open only units in the project Search Path or Source Path, or in the product Browsing Path or Library Path. Directories are searched in the following order:
- The project Search Path (Delphi) or Include Path (C++)
- The project Source Path, defined as the directory in which the project was saved
- The global Browsing Path
- The global Library Path
- The Library Path, which is searched only if there is no project open in the IDE
These paths can be modified by editing the corresponding values:
- Either the project-specific Search Path for Delphi (Project > Options > Delphi Compiler) or the Include Path for C++ (Project > Options > C++ (Shared Options)).
- The global Browsing Path and the Library Path:
- For Delphi: Tools > Options > Environment Options > Delphi Options > Library
- For C++: Tools > Options > Environment Options > C++ Options > Paths and Directories
- The global library path is set on the Add Runtime Package dialog box.
Examples:
C++
Delphi
Block Completion — Enter key
Block Completion happens when you are missing code in the following situations:
- In C++, the block considered for completion is the code that is inside curly braces {}.
- In Delphi, the block considered for completion is the code that is inside a begin-end.
When you press Enter
while working in the Code Editor and there is a code that is incorrectly closed, the Code Editor enters the closing token at the next available empty line after the current cursor position.
The drop-down menu sets the behavior of completion when you surround existing statements with symbols, as follows:
- Without new line - Positions the cursor after the code you just typed.
- With new line - Positions the cursor inside the code you just typed.
- New blocks only - Invokes completion only if you start a new block.
Class Completion — Ctrl+Shift+C
Class Completion simplifies the process of defining and implementing new classes by generating skeleton code for the class members that you declare.
Position the cursor within a class declaration in the interface section of a unit and press Ctrl+Shift+C
.
Any unfinished property declarations are completed.
For any methods that require an implementation, empty methods are added to the implementation section.
Class Completion can also be achieved by choosing the option Complete class at cursor from the Code Editor context menu.
Error Insight
The Error Insight feature underlines invalid code in red. Positioning the cursor over invalid text displays a tooltip window containing the probable cause of the error.
Also, the list of errors generated by the expression appears in the Errors pane of the Structure View.
Examples:
C++
Delphi
Index for C++ Insights
The Index for C++ Insights provides index for the Tooltip Insight and Find Declaration features.
It is the Language Server Protocol (LSP) server (cquery) that runs through the project and builds a database. It uses CPU, so it can be turned off through the Index for C++ Insights checkbox.
When working with Clang-enhanced compilers and the Index for C++ Insights feature is enabled, the project that you open is opened indexed. It also creates a database that is used for the Tooltip Insight and Find Declaration features. It uses CPU and it can be turned off by unchecking the Index for C++ Insights checkbox.