Sign in Join

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

Mailing lists / lazarus / 2017-01

Feature Request: more intelligent code completion

7 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,

I've using the Eclipse IDE for a while now, and the developer is really spoilt with intelligent code/class completion. I'm wondering if Lazarus IDE could benefit of some of those features too.

For example - improved (more intelligent) code completion.

I have this code:

======================================
procedure TBuildDelphiProjects.DoRun;
var
  lProjDirName: string;
  lDefFile: string; // global defaults INI file
  lFullProjFile: string;
begin
  CaseSensitiveOptions:=True;
  if HasOption('h','help') then
    WriteHelp(0)
  else if not HasOption('p','project') then
    WriteHelp(1)
  else
  begin
    FVerbose := HasOption('V','verbose');
    BuildProject.Verbose := FVerbose;    //  <-- I just typed this.
======================================

Now the BuildProject class doesn't have a Verbose property. The TBuildDelphiProjects class does have a FVerbose field of type boolean. So the data type of FVerbose is known, so to deduce what the missing property "Verbose"'s data type should be is known (or should be known).

Now if I press Ctrl+Shift+C to code/class complete, Lazarus generates the following, which has no relevance to what I typed! It doesn't even solve the compiler error problem.

===================================
procedure TBuildDelphiProjects.DoRun;
var
  lProjDirName: string;
  lDefFile: string; // global defaults INI file
  lFullProjFile: string;
  Verbose: Boolean;              //  <---- Lazarus inserted this???
begin
  CaseSensitiveOptions:=True;
  if HasOption('h','help') then
    WriteHelp(0)
  else if not HasOption('p','project') then
    WriteHelp(1)
  else
  begin
    FVerbose := HasOption('V','verbose');
    BuildProject.Verbose := FVerbose;
===================================

It would have been a lot more logical, and to actually generate compilable code, if Lazarus prompted me (user configurable) to say that it wants to implement the missing property "Verbose" for the object BuildProject (of type TBuildProject). The property simply needs to ask what visibility do I want the Verbose property... Public of Published (as TBuildProject is defined in another unit)?

Lazarus (v1.3 and v1.7) generated the same code as show above, and neither is compilable afterwards! So I don't know what Lazarus was trying to achieve by introducing that local Verbose: boolean variable.

This is the compiler output I get when I try to compile my project before and after the code/class completion was triggered.

  builddelphiprojects.lpr(79,18) Error: identifier idents no member
"Verbose"

After using Eclipse for some time now, such shortcuts for the developer is a massive time saver. It also works fantastically well if you do Test Driven Development. I'm sure Lazarus IDE could benefit from such code completion improvements too.

I can file this as a feature request on Mantis if need 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

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 34 lines
Hi, I've using the Eclipse IDE for a while now, and the developer is really spoilt with intelligent code/class completion. I'm wondering if Lazarus IDE could benefit of some of those features too. For example - improved (more intelligent) code completion. I have this code: ====================================== procedure TBuildDelphiProjects.DoRun; var lProjDirName: string; lDefFile: string; // global defaults INI file lFullProjFile: string; begin CaseSensitiveOptions:=True; if HasOption('h','help') then WriteHelp(0) else if not HasOption('p','project') then WriteHelp(1) else begin FVerbose := HasOption('V','verbose'); BuildProject.Verbose := FVerbose; // <-- I just typed this. ====================================== Now the BuildProject class doesn't have a Verbose property. The TBuildDelphiProjects class does have a FVerbose field of type boolean. So the data type of FVerbose is known, so to deduce what the missing property "Verbose"'s data type should be is known (or should be known).

I'm not sure that I want the IDE to modify another class than the one I am working in at the moment, when I press "code completion" ?

Michael.

Reply by email

Mattias Gaertner
to Graeme Geldenhuys: I've using the Eclipse IDE for a while now, and the developer is really spoilt with…
Show quoted text 5 lines
[...] Now the BuildProject class doesn't have a Verbose property. The TBuildDelphiProjects class does have a FVerbose field of type boolean. So the data type of FVerbose is known, so to deduce what the missing property "Verbose"'s data type should be is known (or should be known).

It did correctly deduce the datatype Boolean, did it not? The only missing thing is to place it at the right place, somewhere in TBuildDelphiProjects or its ancestors. Since this is not yet implemented you have to do that manually.

Show quoted text 5 lines
[...] It would have been a lot more logical, and to actually generate compilable code, if Lazarus prompted me (user configurable) to say that it wants to implement the missing property "Verbose" for the object BuildProject (of type TBuildProject).

There are currently two code completions: the interactive Ctrl+Shift+X and the non interactive Ctrl+Shift+C.
In this case you almost always wants the interactive version. And this dialog needs to be extended with options for what to create (in which class, a var or a property, what kind of property).

[...] Lazarus (v1.3 and v1.7) generated the same code as show above, and neither is compilable afterwards! So I don't know what Lazarus was trying to achieve by introducing that local Verbose: boolean variable.

It is a half implemented feature.

[...] I can file this as a feature request on Mantis if need be.

Yes, please.

Mattias

Reply by email

Mattias Gaertner
to Michael Van Canneyt: I'm not sure that I want the IDE to modify another class than the one I am working in at…
Show quoted text 8 lines
[...] > Now the BuildProject class doesn't have a Verbose property. The > TBuildDelphiProjects class does have a FVerbose field of type boolean. > So the data type of FVerbose is known, so to deduce what the missing > property "Verbose"'s data type should be is known (or should be known). I'm not sure that I want the IDE to modify another class than the one I am working in at the moment, when I press "code completion" ?

+1
Only the interactive code completion should do that.

Mattias

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: I'm not sure that I want the IDE to modify another class than the one I am working in at…
Michael Van Canneyt wrote
I'm not sure that I want the IDE to modify another class than the one I am working in at the moment, when I press "code completion" ?

Well, then maybe introduce another action - an intermediate step that the developer must confirm.

Again, Eclipse does this very nicely. It gives a error icon in the gutter (the icon can change to a hint icon for other functionality like possible refactoring suggestions etc). If you click the icon, it presents a list of actions (a keyboard shortcut will show that list as well, so you are not forced to use the mouse).

Then simply pick the "Create property in class XYZ..." option. Eclipse goes even further and shows you another window next to the popup window of how the generated code snippet will look like - but this is obviously not needed for Lazarus IDE.

I know Eclipse has a massive developer team (compared to Lazarus), and Lazarus can't compete with the amount of features Eclipse has. But allowing Lazarus to generate code that is not even compilable is not acceptable - its a big let down.

And as I mentioned, this feature is a massive advantage in Test Driven Development, where you often write the API (method) calls first, then implement them afterwards to resolve the compilation error.

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 Mattias Gaertner: On Mon, 30 Jan 2017 11:09:19 +0000 It did correctly deduce the datatype Boolean, did it…
Mattias Gaertner wrote
It did correctly deduce the datatype Boolean, did it not?

Yes it did.

The only missing thing is to place it at the right place,

Indeed. The code I wrote was "BuildProject.Verbose := ...", so it should query the data type of the BuildProject object, and make the class completion suggestion for that class.

There are currently two code completions: the interactive Ctrl+Shift+X and the non interactive Ctrl+Shift+C. In this case you almost always wants the interactive version.

Ah, so we learn something new. I didn't know about the interactive one. I also see Lazarus v1.3 didn't have that functionality - I guess I need to update that development VM with a newer Lazarus.

And this dialog needs to be extended with options for what to create (in which class, a var or a property, what kind of property).

Yes. I just tried the interactive code completion now - just to see what it does. It created a public variable bit in the wrong class. It didn't use the BuildProject object, but rather the class I was in. So in this case the generated code also didn't make any sense of leave code that is actually compilable.

It is a half implemented feature.

Indeed, it seems the functionality is almost there.

> I can file this as a feature request on Mantis if need be. Yes, please.

Reported as....

http://mantis.freepascal.org/view.php?id=31299

Thanks Mattias.

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

Ondrej Pokorny
to Graeme Geldenhuys

Ctrl+Shift+X is a new feature for upcoming 1.8:
http://wiki.freepascal.org/Lazarus_1.8.0_release_notes

It cannot create properties - neither in the current class nor in a different class.

It's a rather easy feature to add because CodeTools already have everything that is needed for it. The "most complex" thing is the dialog
- the user needs to choose Getters/Setters and maybe also the ancestor class where to put the property.

A handy feature indeed.

Ondrej

Reply by email