Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-12

Extending the IDE auto-coding functionality

9 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

[this is not a rant or talking any product down]

Having spent some recent months with Eclipse and IntelliJ IDEA developing in Java, and now coming back to Lazarus and Delphi, I've come to the realisation how far behind Lazarus and Delphi IDE's are with assisting the developer. [I know Eclipse has massive resources. I don't know about IDEA]

I'm curious to know how big a task or a difficulty level (1-5) it is to implement the following in Lazarus IDE?

1) Auto define a class for you.
For example, in my unit I define a variable

  var obj: TMyObject;
  When I now compile it obviously complains that TMyObject doesn't
  exist. In Eclipse Ctrl+1 would suggest to me that it defines that
  class. Why can't Lazarus IDE do that too?
  The suggestions could be.
    1. Add unit  to uses clause that does define that class.
    2. Define class in same unit.
    3. Define a unit unit and then define TMyObject in that new
       unit. Automatically add that new unit to the project, and
       add that unit name to the uses clause of the unit I was
       working on.

2) Auto define methods or field variables.
For example, I call a non-existing method of a class.

     var obj: TMyObject;
     begin
        ...
        obj.SomeMethod();
   SomeMethod() doesn't exist. So can't Lazarus suggest to define that
   method for me.
   On the same front, if I called the method as follows:
       obj.SomeMethod(sString, bBoolean);
   where sString and bBoolean are known variables, than Lazarus would
   know that SomeMethod takes a String and a Boolean as parameter types.
   So when it auto-generates SomeMethod() it intelligently defines it
   with the correct parameter types.

The whole point here is that you code-first, then let the IDE suggests solutions. That keeps my train of thought on the problem I'm working on, and not about managing project files.

Such things are now standard in Eclipse and IDEA, and they are *extremely useful* features. I can't think that Lazarus and Delphi doesn't include these features too. After all, the IDE is supposed to be clever and make the job of the developer easier, no?

Now I'm not suggesting others implement this - though they are welcome too. I'm equally curious to give this a stab myself, because the above 2 items are just the tip of the iceberg for such code-assisting features. I have a loads more suggestions like the above.

How much of the project's code does Lazarus IDE know or understand at any point in time? Does it only know about the code (classes, variables, methods etc) in open files, or does it know about all files in the project? ie: some cached syntax tree of the whole project. I guess CodeTools would play a large role in this?

This also makes me wonder... I have read somewhere, a year or two ago, about a Object Pascal language plugin for Eclipse. Would that mean, Eclipse can already code-assist the developer with Object Pascal too - like it does for Java? Anybody know this language plugin and where I could find it? I would love to give it a try.

I welcome any further discussions on this topic. eg: More features like this, where and when Lazarus could code-assist (eg: after compilation, maybe right-clicking on the erro in the Messages window or somewhere sooner? etc). If this is not the correct location for such discussions, where could be?

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Werner Pamler
to Graeme Geldenhuys

I'd turn these features off in the same way I turn off most of the features when the IDE pretends to be able to guess what I am thinking. What if my fingers are too slow and I type "TChekbox" instead of "TCheckbox"? According to your idea the IDE will pollute my source code and add the skeleton of a new class. No.

Reply by email

Graeme Geldenhuys
to Werner Pamler: I'd turn these features off in the same way I turn off most of the features when the IDE…
Werner Pamler wrote
I'd turn these features off in the same way I turn off most of the features when the IDE pretends to be able to guess what I am thinking.

No, the difference between what I'm suggesting (how Eclipse works) is that I have to manually trigger the suggestion list - be that via a shortcut, or a icon in the gutter, or a right-click popup in the Messages window. I don't want these suggestions to auto popup like the class/method suggestions list eg: after I type a . (dot)), or auto code template (eg: begin..end pairs). My suggestion it something always manually triggered by the developer.

Think of it like the current "Refactoring" support. It's there, but only if you manually trigger it.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Martin Frb: invoke "Identifier dictionary" (one key press), select correct entry from list (up/down…
Martin Frb wrote
Cody,

Ah, I forgot about Cody. I remember somebody mention it once to me about a year or so ago. Not sure what everything it does, but I'll take a look.

Is Cody something included with Lazarus as standard, or a manually installed package? I'll search the wiki in the mean time.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Martin Frb
to Graeme Geldenhuys: No, the difference between what I'm suggesting (how Eclipse works) is that I have to…
Graeme Geldenhuys wrote 5 lines
No, the difference between what I'm suggesting (how Eclipse works) is that I have to manually trigger the suggestion list - be that via a shortcut, or a icon in the gutter, or a right-click popup in the Messages window.
procedure TForm1.FormCreate(Sender: TObject);
begin
   foo := 1;
end;
unit1.pas(33,3) Error: Identifier not found "foo"

Now I can right click that message in the message window, or the red (!) in the gutter:
- Create local variable foo
- Search Identifier
- Show Cody dictionary for "foo"

So the concept is there. IIRC it is called "quick fix".

But yes, there are plenty of solutions that still could be added....

Reply by email

Martin Frb
to Graeme Geldenhuys: Ah, I forgot about Cody. I remember somebody mention it once to me about a year or so…
Graeme Geldenhuys wrote 8 lines
On 17/12/2018 18:06, Martin Frb via lazarus wrote: > Cody, Ah, I forgot about Cody. I remember somebody mention it once to me about a year or so ago. Not sure what everything it does, but I'll take a look. Is Cody something included with Lazarus as standard, or a manually installed package? I'll search the wiki in the mean time.

It comes with the installer, i.e. it is in the install dir. But you then need to install it as a package.

Reply by email

Mattias Gaertner
to Graeme Geldenhuys: No, the difference between what I'm suggesting (how Eclipse works) is that I have to…
Show quoted text 14 lines
Graeme Geldenhuys via lazarus hat am 17. Dezember 2018 um 19:07 geschrieben: On 17/12/2018 17:56, Werner Pamler via lazarus wrote: > I'd turn these features off in the same way I turn off most of the > features when the IDE pretends to be able to guess what I am thinking. No, the difference between what I'm suggesting (how Eclipse works) is that I have to manually trigger the suggestion list - be that via a shortcut, or a icon in the gutter, or a right-click popup in the Messages window. I don't want these suggestions to auto popup like the class/method suggestions list eg: after I type a . (dot)), or auto code template (eg: begin..end pairs). My suggestion it something always manually triggered by the developer.

I guess you mean a Quickfix. It adds a menu item/icon depending on a compiler message. In this case: identifier not found. Should not be too hard to extend the existing one.

Mattias

Reply by email

Graeme Geldenhuys
to Mattias Gaertner
Mattias Gaertner wrote
I guess you mean a Quickfix.

OK, now I have the terminology. :)

It adds a menu item/icon depending on a compiler message. In this case: identifier not found. Should not be too hard to extend the existing one.

Thanks, I'll start there. As Martin said, it sounds like a lot of functionality is already in place..... ready to be extended.

Regards,
Graeme

Reply by email