Code Insight (IDE Tutorial)

From RAD Studio
Jump to: navigation, search

Go Up to The Code Editor Index (IDE Tutorial)


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.

Code Completion C.png

Note: For the Clang-enhanced compiler, this feature uses a Language Server Protocol server. It is asynchronous and non-blocking.
  • 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.

Code Completion D.png

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.
Note:
  • 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++

Parameter Completion C.png

Note: For the Clang-enhanced compiler, this feature uses a Language Server Protocol server. It is asynchronous and non-blocking.
  • Delphi

Parameter Completion D.png

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.

Note: Code Hints only work for 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:

Code Hints D.png

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++

Tooltip Expresion Evaluation C.png

  • Delphi

Tooltip Expresion Evaluation D.png

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++

Tooltip Symbol Insight C.png

  • Delphi

Tooltip Symbol Insight D.png

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

Tooltip Help Insight D.png

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:

  1. The project Search Path (Delphi) or Include Path (C++)
  2. The project Source Path, defined as the directory in which the project was saved
  3. The global Browsing Path
  4. The global Library Path
  5. 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:

Examples:

  • C++

Find Declaration C.png

  • Delphi

Find Declaration D.png

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++

Error Insight C.png

  • Delphi

Error Insight D.png

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.

Note: This setting applies only for C++ and Clang-enhanced compilers. For the Clang-enhanced compiler, this feature uses a Language Server Protocol (LSP) server. It is asynchronous and non-blocking.

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.

Tip: Keep in mind, if this option is unchecked, both the Tooltip Insight and Find Declaration features are non-functional. However, Code Completion and Parameter Completion are still functional whether or not Indexing is turned ON.

Next

Refactoring