[Lazarus] Lazarus Codetools

Mattias Gaertner nc-gaertnma at netcologne.de
Wed Jul 28 11:03:00 CEST 2010


On Wed, 28 Jul 2010 09:50:58 +0400
Дмитрий Курашкин <dkurashkin at gmail.com> wrote:

> Hi to all!
> 
> I am using Lazarus 2 years. Now I want to try develop some features for
> Lazarus.

Great!

> I want make something like Eclipse (java IDE) feature. When user move mouse
> cursor over class property or method, my patch mast show hint window, which
> allow make some changes in class definition: change type, scope, set and get
> methods, etc. It will works as powerful refactoring tool. I think it will be
> very nice feature!
> 
> I have seen some source files, but they hasn't comments, so I can't
> understand how it works or must waste a lot of time for understanding.

The above functions are probably not simple extensions, so I have to
explain some more:

The codetools do all the parsing and refactoring. The IDE just adds menu
items, setup dialogs, short cuts. Because the codetools are a normal
package you can write command line programs to test functions. This
greatly help debugging. There are already many such utilities in
components/codetools/examples. 

See here
http://wiki.lazarus.freepascal.org/Codetools

Maybe I can use this opportunity to add an extensive example.

Refactoring tools are put into the popup menu of the source editor
(like eclipse) and in the main menu (there is already a feature
request for that). Your tools should be put there too.

And when that works you can extend the hint window.


> I would be very much obliged to you if you can ask me where source codes
> contains following:
> 
>    - hint window in code editor: it's showning condition, content (variable
>    description, for example), etc.

The source editor has a timer and some flags to show the hint window.

See ide/sourceeditor.pp
TSourceNotebook.ShowSynEditHint

Your refactoring tools should not run when the completion box is
open. So this needs to be checked somewhere.

It then calls Manager.OnShowHintForSource which calls in ide/main.pp
TMainIDE.OnSrcNotebookShowHintForSource

This checks the current state. For example while debugging it
evaluates the identifier under the cursor.
Then it asks the codetools for declaration and comments.
Then it asks the help system, which normally searches the fpdoc files.
Then it has a hint as html.
This is passed to source editor to show its hint window.

See ide/sourceeditor.pp
TSourceNotebook.ActivateHint

It calls LazarusHelp.CreateHint which calls ide/helpmanager.pas
TIDEHelpManager.CreateHint.

I guess, you want to add some buttons to the hint window as eclipse
does.


>    - getting information about variables, classes, types, functions, for
>    example:
> 
> user writes:
> *
> uses *AncectorClass;

Do you mean
uses UnitOfAncectorClass;
?

 
> *type *
>   TMyChild = *class *(TMyAncector)
> 
>   *end*;
> 
> 
> How can I recieve code of *TMyAncector *class as string or string list?

The codetools can search for its nodes, file, clean position and source
position. Then you can parse it token by token, or iterate all its
child nodes or as extract it as string or whatever fits.

 
> Please, ask me which units of IDE sources can help me?
> 
> P. S. I found modules *FindDeclarationTool, CodeTree, CodeCache* In
> $LazarusDir$/components/examples/codetools. Is it units what I need?

Yes.

Can you explain what each of your functions should do exactly? Then I
can write some docs how to do that.


Mattias




More information about the Lazarus mailing list