Sign in Join

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

Mailing lists / lazarus / 2017-05

CodeTools knowledge about a project - find a class

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

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

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 5 lines
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.

Show quoted text 15 lines
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

Show quoted text 5 lines
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

Reply by email

Ondrej Pokorny
to Graeme Geldenhuys: Does CodeTools only know about the unit or units that are currently open? Or does in know…
Graeme Geldenhuys wrote 13 lines
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

Reply by email

Graeme Geldenhuys
to Mattias Gaertner: On Fri, 26 May 2017 11:47:35 +0100 Codetools only knows about the defines for each…
Mattias Gaertner wrote

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

Reply by email

Graeme Geldenhuys
to Ondrej Pokorny: Please share this feature with us when you implemented it! I miss it as well (I do a…
Ondrej Pokorny 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

Reply by email

Kostas Michalopoulos
to Graeme Geldenhuys

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 <

Show quoted text 26 lines
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 http://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170526/7cb8d4af/attachment-0001.html>

Reply by email

Mattias Gaertner
to Kostas Michalopoulos

On Fri, 26 May 2017 17:49:35 +0300

Kostas Michalopoulos wrote 8 lines
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.

Show quoted text 5 lines
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.

Show quoted text 5 lines
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

Show quoted text 29 lines
On Fri, May 26, 2017 at 2:11 PM, Graeme Geldenhuys via Lazarus < > 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 > > http://lists.lazarus-ide.org/listinfo/lazarus >

Reply by email

Mattias Gaertner
to Kostas Michalopoulos

On Fri, 26 May 2017 18:24:12 +0300

Kostas Michalopoulos wrote 5 lines
> 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

Reply by email

Kostas Michalopoulos
to Mattias Gaertner

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 <

Show quoted text 26 lines
wrote: On Fri, 26 May 2017 18:24:12 +0300 Kostas Michalopoulos via Lazarus 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 http://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170526/6c5f68b2/attachment-0001.html>

Reply by email

Mattias Gaertner
to Kostas Michalopoulos

On Fri, 26 May 2017 19:29:00 +0300

Kostas Michalopoulos wrote 5 lines
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.

Show quoted text 12 lines
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.

Show quoted text 5 lines
[...] 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

Reply by email

Ondrej Pokorny
to Graeme Geldenhuys: It seems it already exists (as Mattias pointed out) - we just didn’t know about it. :) …
Graeme Geldenhuys wrote
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.

I absolutely fell in love with FPC/Lazarus now. It offers everything I need.

Another wishes would be a faster compiler (it won't happen I know :) ), a better+faster debugger (I hope for fpDebug in the future) and maybe full Cocoa support (which I don't need yet, though). But these are minor issues.

It's very impressive what the FPC and Lazarus teams and other component vendors achieved.

Ondrej

Reply by email