Skip to content

Code Completion ​

Unit: SynEdit.CompletionProposal. Two components are available:

ComponentDescription
TSynCompletionProposalA popup list of items (code completion) or of parameter hints, shown by a shortcut, by a timer or by trigger characters.
TSynAutoCompleteExpands 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).

pascal
SynCompletionProposal1.Editor := SynEdit1;
SynCompletionProposal1.ItemList.Add('begin');
SynCompletionProposal1.InsertList.Add('begin' + sLineBreak + 'end;');

Main properties ​

PropertyDescription
EditorThe TSynEdit the proposal works on.
ShortCutThe key combination that shows the proposal.
DefaultTypectCode (completion list), ctHint or ctParams (parameter hints).
ItemListThe text of the items shown in the list.
InsertListThe text inserted when an item is selected (if empty ItemList is used).
OptionsSet of TSynCompletionOption, for example scoCaseSensitive, scoLimitToMatchedText, scoTitleIsCentered, scoEndCharCompletion, scoCompleteWithTab and scoCompleteWithEnter (the last four of these are in the default).
NbLinesInWindowNumber of lines shown by the window (default 8).
Width, ItemHeight, MarginSize of the window and of the items.
Title, TitleFont, ClTitleBackgroundTitle of the window.
Font, ClBackground, ClSelect, ClSelectedTextColors and font of the list.
ColumnsColumns for items with more fields (for example the type and the name).
ImagesImage list for the items.
EndOfTokenChrCharacters that end the token under the caret.
TriggerCharsCharacters that show the proposal as soon as they are typed (for example .).
Resizeable, ShowGripperThe window can be resized with the mouse.
PaintFormShadowDraws a shadow under the window.
TimerIntervalMilliseconds to wait before showing the proposal in the automatic modes (default 1000).

Events ​

EventDescription
OnExecuteThe popup is about to be shown: fill or filter the items here for a dynamic list.
OnCodeCompletionAn item has been chosen: change the text to insert.
OnAfterCodeCompletionThe text has been inserted.
OnCancelledThe popup was closed without choosing.
OnValidate, OnKeyPressControl 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.

text
ife
|if then else
=if | then
=else
PropertyDescription
EditorThe editor served.
ShortCutThe key that expands the token before the caret (default Shift+Space).
AutoCompleteListThe templates.
EndOfTokenChrCharacters that end the token.
DoLookupWhenNotExactWhen the token is not an exact template, shows a completion list of the templates that start with it.
OnBeforeExecute, OnAfterExecuteEvents fired around the expansion.

Demo ​

See the Code Completion demo.

Released under the MPL 1.1 / GPL 2 dual license.