Code Completion
Unit: SynEdit.CompletionProposal. Two components are available:
| Component | Description |
|---|---|
TSynCompletionProposal | A popup list of items (code completion) or of parameter hints, shown by a shortcut, by a timer or by trigger characters. |
TSynAutoComplete | Expands a token into a template when the shortcut is pressed (for example ife into an if ... then ... else block). |
TSynCompletionProposal
Connect the proposal to the editor with the Editor property (or AddEditor to serve more editors), fill ItemList with the text shown and InsertList with the text inserted, and set the ShortCut (default Ctrl+Space).
SynCompletionProposal1.Editor := SynEdit1;
SynCompletionProposal1.ItemList.Add('begin');
SynCompletionProposal1.InsertList.Add('begin' + sLineBreak + 'end;');Main properties
| Property | Description |
|---|---|
Editor | The TSynEdit the proposal works on. |
ShortCut | The key combination that shows the proposal. |
DefaultType | ctCode (completion list), ctHint or ctParams (parameter hints). |
ItemList | The text of the items shown in the list. |
InsertList | The text inserted when an item is selected (if empty ItemList is used). |
Options | Set of TSynCompletionOption, for example scoCaseSensitive, scoLimitToMatchedText, scoTitleIsCentered, scoEndCharCompletion, scoCompleteWithTab and scoCompleteWithEnter (the last four of these are in the default). |
NbLinesInWindow | Number of lines shown by the window (default 8). |
Width, ItemHeight, Margin | Size of the window and of the items. |
Title, TitleFont, ClTitleBackground | Title of the window. |
Font, ClBackground, ClSelect, ClSelectedText | Colors and font of the list. |
Columns | Columns for items with more fields (for example the type and the name). |
Images | Image list for the items. |
EndOfTokenChr | Characters that end the token under the caret. |
TriggerChars | Characters that show the proposal as soon as they are typed (for example .). |
Resizeable, ShowGripper | The window can be resized with the mouse. |
PaintFormShadow | Draws a shadow under the window. |
TimerInterval | Milliseconds to wait before showing the proposal in the automatic modes (default 1000). |
Events
| Event | Description |
|---|---|
OnExecute | The popup is about to be shown: fill or filter the items here for a dynamic list. |
OnCodeCompletion | An item has been chosen: change the text to insert. |
OnAfterCodeCompletion | The text has been inserted. |
OnCancelled | The popup was closed without choosing. |
OnValidate, OnKeyPress | Control of the keys typed while the popup is open. |
Methods
ActivateCompletion and CancelCompletion show and close the popup from your code, AddItem(ADisplayText, AInsertText) adds an item and ClearList removes all of them, AddEditor and RemoveEditor change the editors served.
TSynAutoComplete
AutoCompleteList contains the templates. Each template is a line with the token, an optional line starting with | (the description shown in the lookup list) and then one or more lines starting with = that contain the text to insert, where a | marks the final position of the caret.
ife
|if then else
=if | then
=else| Property | Description |
|---|---|
Editor | The editor served. |
ShortCut | The key that expands the token before the caret (default Shift+Space). |
AutoCompleteList | The templates. |
EndOfTokenChr | Characters that end the token. |
DoLookupWhenNotExact | When the token is not an exact template, shows a completion list of the templates that start with it. |
OnBeforeExecute, OnAfterExecute | Events fired around the expansion. |
Demo
See the Code Completion demo.
