[Lazarus] CodeTools knowledge about a project - find a class

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
Hi,

Does CodeTools only know about the unit or units that are currently
open? Or does in know about all files in a project - and maybe even
associated packages?

The problem
===========
I want to implement a Lazarus IDE feature "open type" - that's if it
doesn't already exist (please let me know). Imagine, you need to have a
look at the "TFoo" class. But, where is the "TFoo" class? Is it in the
"Boo" project or maybe in the Boo_tools.lpk package? Or somewhere else
(in a project search path)?

I would like to be able to simply trigger the "Open Type" shortcut,
which shows me a dialog where I can type "Foo", and a listbox below that
will list all possible class matches with the name "Foo" (similar to
what the Procedure List dialog currently does. I can then simply press
Enter to select the first found option, or press the up/down arrows to
select another match and then press Enter, and it will take me to the
correct unit and class definition.

Ctrl+LClick can already to this - somewhat. But for Ctrl+LClick to work,
you need the correct unit in the uses clause. My problem is, what if you
don't know the unit name either, or the unit name isn't in the uses list
(yet - or might not even be needed at all, you simply wanted to double
check something in the "TFoo" class).

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
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
On Fri, 26 May 2017 11:47:35 +0100
Graeme Geldenhuys via Lazarus <[hidden email]> wrote:

> Hi,
>
> Does CodeTools only know about the unit or units that are currently
> open? Or does in know about all files in a project - and maybe even
> associated packages?

Codetools only knows about the defines for each directory.
But any IDE addon can access source editor and codetools.

 

> The problem
> ===========
> I want to implement a Lazarus IDE feature "open type" - that's if it
> doesn't already exist (please let me know). Imagine, you need to have a
> look at the "TFoo" class. But, where is the "TFoo" class? Is it in the
> "Boo" project or maybe in the Boo_tools.lpk package? Or somewhere else
> (in a project search path)?
>
> I would like to be able to simply trigger the "Open Type" shortcut,
> which shows me a dialog where I can type "Foo", and a listbox below that
> will list all possible class matches with the name "Foo" (similar to
> what the Procedure List dialog currently does. I can then simply press
> Enter to select the first found option, or press the up/down arrows to
> select another match and then press Enter, and it will take me to the
> correct unit and class definition.

Sounds like cody's dictionary:
http://wiki.lazarus.freepascal.org/Cody#Unit_.2F_Identifier_Dictionary

 
> Ctrl+LClick can already to this - somewhat. But for Ctrl+LClick to work,
> you need the correct unit in the uses clause. My problem is, what if you
> don't know the unit name either, or the unit name isn't in the uses list
> (yet - or might not even be needed at all, you simply wanted to double
> check something in the "TFoo" class).


Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 26.05.2017 12:47, Graeme Geldenhuys via Lazarus wrote:

> I want to implement a Lazarus IDE feature "open type" - that's if it
> doesn't already exist (please let me know). Imagine, you need to have
> a look at the "TFoo" class. But, where is the "TFoo" class? Is it in
> the "Boo" project or maybe in the Boo_tools.lpk package? Or somewhere
> else (in a project search path)?
>
> I would like to be able to simply trigger the "Open Type" shortcut,
> which shows me a dialog where I can type "Foo", and a listbox below
> that will list all possible class matches with the name "Foo" (similar
> to what the Procedure List dialog currently does. I can then simply
> press Enter to select the first found option, or press the up/down
> arrows to select another match and then press Enter, and it will take
> me to the correct unit and class definition.

Please share this feature with us when you implemented it! I miss it as
well (I do a simple Search in Files now).

Ondrej
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 2017-05-26 12:01, Mattias Gaertner via Lazarus wrote:
> Sounds like cody's dictionary:
> http://wiki.lazarus.freepascal.org/Cody#Unit_.2F_Identifier_Dictionary

Fantastic! From the wiki description, this sounds exactly like what I
was going to try and implement. Open Source developers are amazing. :)
Thanks for pointing me to this. I'll give it a try immediately.

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
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 2017-05-26 12:06, Ondrej Pokorny via Lazarus wrote:
> Please share this feature with us when you implemented it! I miss it as
> well (I do a simple Search in Files now).

It seems it already exists (as Mattias pointed out) - we just didn’t
know about it. :)  All that remains is to assign a shortcut to it, if a
default one doesn't exist.

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
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
This looks like a nice feature, but it only seems to know stuff you have already open or opened in the current session. It doesn't know all identifiers and whatever might be available from the currently loaded project and packages. For example if you have a unit Foo (either in the project or in one of the packages) but you don't have it opened at any time in the current session, it wont be able to show you anything that Foo exports. If you open Foo then it will, even if you close it after, but if you restart Lazarus it will have forgotten everything.

Also i'd prefer if the Jump to button was default. It is trivial to change this via code (i just set the button's Default property to true) but i'd be nice if it was configurable in options.

Finally while it does seem to remember unit names, this is as a byproduct of units being symbols and when you jump to a unit it puts the cursor to the top of the file. It'd be nice if it had a special case for units that only switched/opened the unit file without moving the cursor so you can quickly jump between files with the same shortcut.

TBH i think such a "quick jump" would be a good thing to have in the base IDE out of the box. Popular modern IDEs provide this functionality these days and it is even included in some editors like Sublime. I think the necessary low level functionality is almost there and it is mainly a matter of tying everything together.


On Fri, May 26, 2017 at 2:11 PM, Graeme Geldenhuys via Lazarus <[hidden email]> wrote:
On 2017-05-26 12:06, Ondrej Pokorny via Lazarus wrote:
Please share this feature with us when you implemented it! I miss it as
well (I do a simple Search in Files now).

It seems it already exists (as Mattias pointed out) - we just didn’t know about it. :)  All that remains is to assign a shortcut to it, if a default one doesn't exist.

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
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
On Fri, 26 May 2017 17:49:35 +0300
Kostas Michalopoulos via Lazarus <[hidden email]> wrote:

> This looks like a nice feature, but it only seems to know stuff you have
> already open or opened in the current session. It doesn't know all
> identifiers and whatever might be available from the currently loaded
> project and packages. For example if you have a unit Foo (either in the
> project or in one of the packages) but you don't have it opened at any time
> in the current session, it wont be able to show you anything that Foo
> exports. If you open Foo then it will, even if you close it after, but if
> you restart Lazarus it will have forgotten everything.

No. It stores all learned identifiers in a file:
http://wiki.lazarus.freepascal.org/Cody#Unit_.2F_Identifier_Dictionary

For example on this machine the dictionary knows over a million
identifiers. It needs some clean up dialog. ;)

 
> Also i'd prefer if the Jump to button was default. It is trivial to change
> this via code (i just set the button's Default property to true) but i'd be
> nice if it was configurable in options.

Feel free to submit a patch.

 
> Finally while it does seem to remember unit names, this is as a byproduct
> of units being symbols and when you jump to a unit it puts the cursor to
> the top of the file. It'd be nice if it had a special case for units that
> only switched/opened the unit file without moving the cursor so you can
> quickly jump between files with the same shortcut.

Feel free to add an option for that too.

 
> TBH i think such a "quick jump" would be a good thing to have in the base
> IDE out of the box. Popular modern IDEs provide this functionality these
> days and it is even included in some editors like Sublime. I think the
> necessary low level functionality is almost there and it is mainly a matter
> of tying everything together.

It needs some work to make it "newbie" safe.

Mattias



>
>
> On Fri, May 26, 2017 at 2:11 PM, Graeme Geldenhuys via Lazarus <
> [hidden email]> wrote:
>
> > On 2017-05-26 12:06, Ondrej Pokorny via Lazarus wrote:
> >  
> >> Please share this feature with us when you implemented it! I miss it as
> >> well (I do a simple Search in Files now).
> >>  
> >
> > It seems it already exists (as Mattias pointed out) - we just didn’t know
> > about it. :)  All that remains is to assign a shortcut to it, if a default
> > one doesn't exist.
> >
> > 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
> > --
> > _______________________________________________
> > Lazarus mailing list
> > [hidden email]
> > http://lists.lazarus-ide.org/listinfo/lazarus
> >  
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list

No. It stores all learned identifiers in a file:

But then why does it behave as i mentioned? When i restart Lazarus it has forgotten everything.


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
On Fri, 26 May 2017 18:24:12 +0300
Kostas Michalopoulos via Lazarus <[hidden email]> wrote:

> > No. It stores all learned identifiers in a file:
> >  
>
> But then why does it behave as i mentioned? When i restart Lazarus it has
> forgotten everything.

What platform?

What happens when you click on Tools / Options / Codetools / IDE
Integration / Save dictionary now?

Move the mouse over the button and wait for the hint to find out where
it stores the file.

Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
Actually it works fine, after peppering the code with writelns to see the flow, i figured out what was the issue: there is a 10 minute interval (by default) between saves and the dictionary is only saved at the interval. I expected it to be saved when exiting the IDE regardless of when the last save was.

I added a Save; call right at the beginning of the OnIDEClose callback, like this

procedure TCodyUnitDictionary.OnIDEClose(Sender: TObject);
begin
  Save; // Save the dictionary before closing the IDE
  fClosing:=true;
  FreeAndNil(fTimer);
end;

And it seems to behave as i expect it now. This way it wont lose any data when i restart the IDE (which i do often when working with custom controls).

TBH i'm not sure the approach of only scanning what you have loaded is enough since it still wont show anything from a unit i haven't already loaded before. For example if i show the dialog looking for TGraphic it will only show up after i have already used it at least once. So if i have an empty database i get this:

1. Open the identifier db dialog (i have set it up as Alt+`)
2. Start typing TGraph
3. Nothing shows up
4. Press Ctrl+Space in a form code (e.g. Unit1 in the default empty project)
5. Start typing TGraph so that it shows in the completion dialog
6. Press esc to cancel the completion dialog
7. Open the identifier db dialog again
8. Start typing TGraph
9. Now TGraphic (and other stuff) show up

I think there needs to be a way for the dialog to also know whatever is or can be known with the currently loaded packages and units, not just whatever you have encountered so far. That information seems to already be available in the IDE in other places.


On Fri, May 26, 2017 at 6:38 PM, Mattias Gaertner via Lazarus <[hidden email]> wrote:
On Fri, 26 May 2017 18:24:12 +0300
Kostas Michalopoulos via Lazarus <[hidden email]> wrote:

> > No. It stores all learned identifiers in a file:
> >
>
> But then why does it behave as i mentioned? When i restart Lazarus it has
> forgotten everything.

What platform?

What happens when you click on Tools / Options / Codetools / IDE
Integration / Save dictionary now?

Move the mouse over the button and wait for the hint to find out where
it stores the file.

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


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Lazarus] CodeTools knowledge about a project - find a class

Free Pascal - Lazarus mailing list
On Fri, 26 May 2017 19:29:00 +0300
Kostas Michalopoulos via Lazarus <[hidden email]> wrote:

> Actually it works fine, after peppering the code with writelns to see the
> flow, i figured out what was the issue: there is a 10 minute interval (by
> default) between saves and the dictionary is only saved at the interval. I
> expected it to be saved when exiting the IDE regardless of when the last
> save was.

Saving takes some time when the file is big. I prefer a fast closing
IDE.
Maybe some option can be added.

 

> I added a Save; call right at the beginning of the OnIDEClose callback,
> like this
>
> procedure TCodyUnitDictionary.OnIDEClose(Sender: TObject);
> begin
>   Save; // Save the dictionary before closing the IDE
>   fClosing:=true;
>   FreeAndNil(fTimer);
> end;
>
> And it seems to behave as i expect it now. This way it wont lose any data
> when i restart the IDE (which i do often when working with custom controls).

Why that? Simply start a second instance for testing.

 
> TBH i'm not sure the approach of only scanning what you have loaded is
> enough since it still wont show anything from a unit i haven't already
> loaded before.

Yes, the empty database on first use is currently the show stopper.
It would be great, if it somehow (TM) knows at least the FPC and Lazarus
sources after install.


>[...]
> I think there needs to be a way for the dialog to also know whatever is or
> can be known with the currently loaded packages and units, not just
> whatever you have encountered so far. That information seems to already be
> available in the IDE in other places.

The IDE parses the sources on demand when information is needed. It is
not available per se.
Since parsing a project can take some seconds even on fast machines,
this is not done automatically.
Maybe the dictionary can start parsing the project on idle when it is
shown to update its database.

Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Loading...