[Lazarus] Automatic identifier completion

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
Hi,

I know about code completion in the IDE and it works perfectly! However, to invoke it I need to press CRTL-space every time which is somewhat cumbersome. Is there a setting in the IDE that would invoke completion automatically on keypress?


TIA!

Regards, Darius

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
> Hi,
>
> I know about code completion in the IDE and it works perfectly!
> However, to invoke it I need to press CRTL-space every time which is
> somewhat cumbersome. Is there a setting in the IDE that would invoke
> completion automatically on keypress?
>
It can auto invoke after you enter a dot "form1."
But otherwise not.

See https://bugs.freepascal.org/view.php?id=33054
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
This patch seems to realize exactly the behavior I described. However, I tried applying it and about one third to half of it failed as it is fairly old. There are really not many visual leads for me in the current code to position the changes, so I guess that I won't be able to create a new updated patch, based on the existing patch.

There must be good reasons why this feature is not yet implemented, but for me (IŠłŅ sure others as well, as all major IDE's support it by default) this will boost productivity when working with Lazarus.

On Fri, Aug 16, 2019 at 10:55 PM Martin Frb via lazarus <[hidden email]> wrote:
On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
> Hi,
>
> I know about code completion in the IDE and it works perfectly!
> However, to invoke it I need to press CRTL-space every time which is
> somewhat cumbersome. Is there a setting in the IDE that would invoke
> completion automatically on keypress?
>
It can auto invoke after you enter a dot "form1."
But otherwise not.

See https://bugs.freepascal.org/view.php?id=33054
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Fri, 16 Aug 2019 22:55:45 +0200, Martin Frb via lazarus
<[hidden email]> wrote:

>On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
>> Hi,
>>
>> I know about code completion in the IDE and it works perfectly!
>> However, to invoke it I need to press CRTL-space every time which is
>> somewhat cumbersome. Is there a setting in the IDE that would invoke
>> completion automatically on keypress?
>>
>It can auto invoke after you enter a dot "form1."
>But otherwise not.

I have found that in order to get a list of available methods and
properties of an identifier to select from you have to stop for a
second or two after typing in its name until the IDE sort of "selects"
the identifier (it will get a grayish background).
Then when you hit the period the list appears.

But if you type the period immediately after the object name nothing
happens....


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Hi!

Attached a (still) naive patch that implements automatic completion upon keypress. It's already giving me a big boost in productivity so I thought I might share it here. It would be good to make the identifier invocation a bit smarter. For instance I would like to prevent invocation in case the word is part of a string or comment. Also it should auto hide after the first character gets deleted by backspace. Any tips or hints how to use the codetools to get the required information is appreciated!

Rgds, Darius Blaszyk 

On Fri, Aug 16, 2019 at 10:55 PM Martin Frb via lazarus <[hidden email]> wrote:
On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
> Hi,
>
> I know about code completion in the IDE and it works perfectly!
> However, to invoke it I need to press CRTL-space every time which is
> somewhat cumbersome. Is there a setting in the IDE that would invoke
> completion automatically on keypress?
>
It can auto invoke after you enter a dot "form1."
But otherwise not.

See https://bugs.freepascal.org/view.php?id=33054
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
Now with attachment! ūüėÄ

On Tue, Aug 20, 2019 at 6:48 PM Darius Blaszyk <[hidden email]> wrote:
Hi!

Attached a (still) naive patch that implements automatic completion upon keypress. It's already giving me a big boost in productivity so I thought I might share it here. It would be good to make the identifier invocation a bit smarter. For instance I would like to prevent invocation in case the word is part of a string or comment. Also it should auto hide after the first character gets deleted by backspace. Any tips or hints how to use the codetools to get the required information is appreciated!

Rgds, Darius Blaszyk 

On Fri, Aug 16, 2019 at 10:55 PM Martin Frb via lazarus <[hidden email]> wrote:
On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
> Hi,
>
> I know about code completion in the IDE and it works perfectly!
> However, to invoke it I need to press CRTL-space every time which is
> somewhat cumbersome. Is there a setting in the IDE that would invoke
> completion automatically on keypress?
>
It can auto invoke after you enter a dot "form1."
But otherwise not.

See https://bugs.freepascal.org/view.php?id=33054
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

autocompletion.patch (14K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
Index: ide/editoroptions.pp
===================================================================
--- ide/editoroptions.pp (revision 61726)
+++ ide/editoroptions.pp (working copy)
@@ -1406,6 +1406,7 @@
   TEditorOptions = class(TIDEEditorOptions)
   private
     FBlockTabIndent: Integer;
+    fAutoShowCompletion: Boolean;
     FCompletionLongLineHintInMSec: Integer;
     FCompletionLongLineHintType: TSynCompletionLongHintType;
     FMiddleTabClickClosesOthersModifier: TShiftState;
@@ -1702,6 +1703,8 @@
       write FAutoRemoveEmptyMethods default False;
     property CompletionLongLineHintInMSec: Integer
              read FCompletionLongLineHintInMSec write FCompletionLongLineHintInMSec;
+    property AutoShowCompletion: Boolean
+             read fAutoShowCompletion write fAutoShowCompletion;
   published
     property CompletionLongLineHintType: TSynCompletionLongHintType
              read FCompletionLongLineHintType write FCompletionLongLineHintType
@@ -5006,6 +5009,11 @@
       XMLConfig.GetValue('EditorOptions/CodeTools/AutoRemoveEmptyMethods', False);
     FCompletionLongLineHintInMSec :=
       XMLConfig.GetValue('EditorOptions/CodeTools/CompletionLongLineHintInMSec', 0);
+
+    fAutoShowCompletion :=
+      XMLConfig.GetValue('EditorOptions/CodeTools/AutoShowCompletion', False);
+    DebugLn('TEditorOptions: Load Editor option AutoShowCompletion %s', [BoolToStr(fAutoShowCompletion, True)]);
+
     FCompletionLongLineHintType := DefaultCompletionLongLineHintType;
     XMLConfig.ReadObject('EditorOptions/CodeTools/CompletionLongLineHintType',
                          Self, Self, 'CompletionLongLineHintType');
@@ -5207,6 +5215,13 @@
     XMLConfig.SetDeleteValue(
       'EditorOptions/CodeTools/CompletionLongLineHintInMSec',
       FCompletionLongLineHintInMSec, 0);
+
+    DebugLn('TEditorOptions: Write Editor option AutoShowCompletion %s', [BoolToStr(fAutoShowCompletion, True)]);
+    XMLConfig.SetDeleteValue(
+      'EditorOptions/CodeTools/AutoShowCompletion',
+      fAutoShowCompletion, False);
+
+
     XMLConfig.WriteObject('EditorOptions/CodeTools/CompletionLongLineHintType',
                          Self, nil, 'CompletionLongLineHintType');
 
Index: ide/frames/editor_codetools_options.lfm
===================================================================
--- ide/frames/editor_codetools_options.lfm (revision 61726)
+++ ide/frames/editor_codetools_options.lfm (working copy)
@@ -16,10 +16,10 @@
     AnchorSideLeft.Control = AutoCompletionDelayLabel
     AnchorSideLeft.Side = asrBottom
     AnchorSideTop.Control = AutoCompletionDelayLabel
-    Left = 172
-    Height = 15
-    Top = 156
-    Width = 83
+    Left = 212
+    Height = 17
+    Top = 168
+    Width = 107
     BorderSpacing.Left = 20
     Caption = 'AutoDelayLabel'
     ParentColor = False
@@ -32,7 +32,7 @@
     AnchorSideRight.Side = asrBottom
     Left = 0
     Height = 3
-    Top = 56
+    Top = 60
     Width = 634
     Anchors = [akTop, akLeft, akRight]
     BorderSpacing.Top = 6
@@ -42,9 +42,9 @@
     AnchorSideLeft.Control = Owner
     AnchorSideTop.Control = Owner
     Left = 6
-    Height = 19
+    Height = 21
     Top = 6
-    Width = 210
+    Width = 263
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoRemoveEmptyMethodsOnSave'
@@ -55,9 +55,9 @@
     AnchorSideTop.Control = AutoDisplayFuncProtoCheckBox
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 19
-    Top = 87
-    Width = 198
+    Height = 21
+    Top = 93
+    Width = 245
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoToolTipSymbToolsCheckBox'
@@ -68,9 +68,9 @@
     AnchorSideTop.Control = AutoRemoveEmptyMethodsOnSave
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 19
-    Top = 31
-    Width = 179
+    Height = 21
+    Top = 33
+    Width = 225
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoCompleteBlockCheckBox'
@@ -81,9 +81,9 @@
     AnchorSideTop.Control = AutoToolTipSymbToolsCheckBox
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 19
-    Top = 112
-    Width = 182
+    Height = 21
+    Top = 120
+    Width = 230
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoToolTipExprEvalCheckBox'
@@ -96,8 +96,8 @@
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 30
-    Top = 172
+    Height = 39
+    Top = 186
     Width = 622
     Frequency = 250
     Max = 4000
@@ -116,9 +116,9 @@
     AnchorSideTop.Control = DbgToolTipAutoCastClass
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 15
-    Top = 156
-    Width = 146
+    Height = 17
+    Top = 168
+    Width = 186
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoCompletionDelayLabel'
@@ -131,8 +131,8 @@
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 30
-    Top = 276
+    Height = 39
+    Top = 312
     Width = 622
     Frequency = 250
     Max = 4000
@@ -150,9 +150,9 @@
     AnchorSideTop.Control = AutoHintDelayTrackBar
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 15
-    Top = 260
-    Width = 148
+    Height = 17
+    Top = 294
+    Width = 188
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'CompletionDropDownLabel'
@@ -162,10 +162,10 @@
     AnchorSideLeft.Control = CompletionDropDownLabel
     AnchorSideLeft.Side = asrBottom
     AnchorSideTop.Control = CompletionDropDownLabel
-    Left = 174
-    Height = 15
-    Top = 260
-    Width = 177
+    Left = 214
+    Height = 17
+    Top = 294
+    Width = 225
     BorderSpacing.Left = 20
     Caption = 'CompletionDropDownDelayLabel'
     ParentColor = False
@@ -177,12 +177,12 @@
     AnchorSideBottom.Control = Owner
     AnchorSideBottom.Side = asrBottom
     Left = 6
-    Height = 23
-    Top = 308
+    Height = 29
+    Top = 353
     Width = 220
     BorderSpacing.Left = 6
     BorderSpacing.Top = 2
-    ItemHeight = 15
+    ItemHeight = 0
     Style = csDropDownList
     TabOrder = 7
   end
@@ -192,9 +192,9 @@
     AnchorSideTop.Control = CompletionDropDownHint
     AnchorSideTop.Side = asrCenter
     Left = 232
-    Height = 15
-    Top = 312
-    Width = 171
+    Height = 17
+    Top = 359
+    Width = 216
     BorderSpacing.Around = 6
     Caption = 'CompletionDropDownHintLabel'
     ParentColor = False
@@ -204,9 +204,9 @@
     AnchorSideTop.Control = AutoToolTipExprEvalCheckBox
     AnchorSideTop.Side = asrBottom
     Left = 26
-    Height = 19
-    Top = 131
-    Width = 159
+    Height = 21
+    Top = 141
+    Width = 198
     BorderSpacing.Left = 20
     Caption = 'DbgToolTipAutoCastClass'
     TabOrder = 8
@@ -215,9 +215,9 @@
     AnchorSideLeft.Control = Owner
     AnchorSideTop.Control = ToolTipBevel
     Left = 6
-    Height = 19
-    Top = 62
-    Width = 191
+    Height = 21
+    Top = 66
+    Width = 241
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoDisplayFuncProtoCheckBox'
@@ -228,9 +228,9 @@
     AnchorSideTop.Control = AutoCompletionDelayTrackBar
     AnchorSideTop.Side = asrBottom
     Left = 6
-    Height = 15
-    Top = 208
-    Width = 106
+    Height = 17
+    Top = 231
+    Width = 135
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
     Caption = 'AutoHintDelayLabel'
@@ -243,8 +243,8 @@
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 30
-    Top = 224
+    Height = 39
+    Top = 249
     Width = 622
     Frequency = 250
     Max = 4000
@@ -262,12 +262,25 @@
     AnchorSideLeft.Control = AutoHintDelayLabel
     AnchorSideLeft.Side = asrBottom
     AnchorSideTop.Control = AutoHintDelayLabel
-    Left = 132
-    Height = 15
-    Top = 208
-    Width = 92
+    Left = 161
+    Height = 17
+    Top = 231
+    Width = 117
     BorderSpacing.Left = 20
     Caption = 'AutoHDelayLabel'
     ParentColor = False
   end
+  object AutoShowCompletionDropDown: TCheckBox
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = CompletionDropDownHint
+    AnchorSideTop.Side = asrBottom
+    Left = 6
+    Height = 21
+    Top = 388
+    Width = 243
+    BorderSpacing.Left = 6
+    BorderSpacing.Top = 6
+    Caption = 'AutoShowCompletionDropDown'
+    TabOrder = 10
+  end
 end
Index: ide/frames/editor_codetools_options.pas
===================================================================
--- ide/frames/editor_codetools_options.pas (revision 61726)
+++ ide/frames/editor_codetools_options.pas (working copy)
@@ -45,6 +45,8 @@
     AutoHintDelayTrackBar: TTrackBar;
     AutoDisplayFuncProtoCheckBox: TCheckBox;
     AutoHintDelayLabel: TLabel;
+    AutoRemoveEmptyMethodsOnSave1: TCheckBox;
+    AutoShowCompletionDropDown: TCheckBox;
     DbgToolTipAutoCastClass: TCheckBox;
     CompletionDropDownHintLabel: TLabel;
     CompletionDropDownHint: TComboBox;
@@ -105,6 +107,8 @@
   CompletionDropDownHint.Items.Add(lisCompletionLongLineHintTypeRightOnly);
   CompletionDropDownHint.Items.Add(lisCompletionLongLineHintTypeLittleLeft);
   CompletionDropDownHint.Items.Add(lisCompletionLongLineHintTypeFullLeft);
+
+  AutoShowCompletionDropDown.Caption := lisAutoShowCompletion;
 end;
 
 procedure TEditorCodetoolsOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
@@ -123,6 +127,7 @@
     CompletionDropDownHintTrackBar.Position := CompletionLongLineHintInMSec;
     CompletionDropDownHint.ItemIndex := ord(CompletionLongLineHintType);
 
+    AutoShowCompletionDropDown.Checked := AutoShowCompletion;
   end;
   AutoCompletionDelayTrackBarChange(nil);
 end;
@@ -142,7 +147,7 @@
 
     CompletionLongLineHintInMSec := CompletionDropDownHintTrackBar.Position;
     CompletionLongLineHintType := TSynCompletionLongHintType(CompletionDropDownHint.ItemIndex);
-
+    AutoShowCompletion := AutoShowCompletionDropDown.Checked;
   end;
 end;
 
Index: ide/lazarusidestrconsts.pas
===================================================================
--- ide/lazarusidestrconsts.pas (revision 61726)
+++ ide/lazarusidestrconsts.pas (working copy)
@@ -2040,6 +2040,7 @@
   lisDelayForCompletionBox = 'Delay for completion box';
   lisDelayForHints = 'Delay for hints';
   lisDelayForCompletionLongLineHint = 'Delay for long line hints in completion box';
+  lisAutoShowCompletion = 'Automatic code completion';
   lisCompletionLongLineHintType = 'Show long line hints';
   lisCompletionLongLineHintTypeNone = 'Never';
   lisCompletionLongLineHintTypeRightOnly = 'Extend right only';
Index: ide/sourceeditor.pp
===================================================================
--- ide/sourceeditor.pp (revision 61726)
+++ ide/sourceeditor.pp (working copy)
@@ -5743,6 +5743,11 @@
     OnKeyDown(Sender, Key, Shift);
 
   IDECommandList.PostponeUpdateEvents;
+
+  // very crude invokaion of identifier completion
+  if EditorOpts.AutoShowCompletion then
+    if (chr(Key) in ['a'..'z', 'A'..'Z']) and (Shift <> [ssCtrl]) and (Shift <> [ssAlt]) and (Shift <> [ssAltGr]) then
+      StartIdentCompletionBox(false,false);
 end;
 
 procedure TSourceEditor.EditorKeyUp(Sender: TObject; var Key: Word;

On Tue, Aug 20, 2019 at 6:54 PM Darius Blaszyk <[hidden email]> wrote:
Now with attachment! ūüėÄ

On Tue, Aug 20, 2019 at 6:48 PM Darius Blaszyk <[hidden email]> wrote:
Hi!

Attached a (still) naive patch that implements automatic completion upon keypress. It's already giving me a big boost in productivity so I thought I might share it here. It would be good to make the identifier invocation a bit smarter. For instance I would like to prevent invocation in case the word is part of a string or comment. Also it should auto hide after the first character gets deleted by backspace. Any tips or hints how to use the codetools to get the required information is appreciated!

Rgds, Darius Blaszyk 

On Fri, Aug 16, 2019 at 10:55 PM Martin Frb via lazarus <[hidden email]> wrote:
On 16/08/2019 19:07, Darius Blaszyk via lazarus wrote:
> Hi,
>
> I know about code completion in the IDE and it works perfectly!
> However, to invoke it I need to press CRTL-space every time which is
> somewhat cumbersome. Is there a setting in the IDE that would invoke
> completion automatically on keypress?
>
It can auto invoke after you enter a dot "form1."
But otherwise not.

See https://bugs.freepascal.org/view.php?id=33054
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Automatic identifier completion

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
Not 100% sure, have to go through the code again. (Also you can add to https://bugs.freepascal.org/view.php?id=33054 )
Just throwing in a few quick notes.

For string and comments

procedure TSourceEditorManager.OnSourceCompletionTimer(Sender: TObject);
  function CheckStartIdentCompletion: boolean;
...
    if SrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(LogCaret,Token,Attri)
    and (Attri<>nil) and (Attri.StoredName=SYNS_XML_AttrComment) then

auto hide after the first character gets deleted by backspace.
You mean the word becomes empty.
Or the first char typed after the completion did open? (i.e. if the I type Sou and completion only opens then, the hide when I attempt to del part of the Sou?)

In either case, there are various ways I can think of for investigation, and we need to established which one is good.

SourceEditor sees the typed chars in UserCommands (or the other callback). SO it could interfere there.
It could also be added as a callback to (I think that is the one):
  TSourceEditCompletion=class(TSynCompletion)


Also what should happen, if during completion, other commands are invoked
ctrl-e for search as you type
even ctrl-f
 (those already are an issue....)

----------------------------
If I am not mistaken (only had a very brief look at the patch)

You currently have a global bool option: on/off?
Would it be sensible to have a (separate) time delay.   So if the user types fast, it will not interfere?
I seem to have thought of that as a necessity on the bug report. But since I am not actually using this feature (even if avail), I might be wrong. (Or maybe it was using a timeout, but the existing one...)
Equally there might be the (unnecessary) idea, to only trigger if at least n chars of the current word have been typed?

Testing with syncro-edit and multi-caret?
The latter should probably disable it.







On 20/08/2019 18:54, Darius Blaszyk via lazarus wrote:
Now with attachment! ūüėÄ

On Tue, Aug 20, 2019 at 6:48 PM Darius Blaszyk <[hidden email]> wrote:
Hi!

Attached a (still) naive patch that implements automatic completion upon keypress. It's already giving me a big boost in productivity so I thought I might share it here. It would be good to make the identifier invocation a bit smarter. For instance I would like to prevent invocation in case the word is part of a string or comment. Also it should auto hide after the first character gets deleted by backspace. Any tips or hints how to use the codetools to get the required information is appreciated!




--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus