[Lazarus] Extending the IDE auto-coding functionality

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Mon Dec 17 18:24:22 CET 2018


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


More information about the Lazarus mailing list