[Lazarus] CodeTools: what is an "identifier"

Bernd Kreuss prof7bit at googlemail.com
Wed Jul 28 18:30:07 CEST 2010


Mattias Gaertner wrote:
> I wrote an example in codebrowser.pas:
> function TCodeBrowserView.GetCodeHelp

I'm now trying your example and it seems to suffer from the same problem
that I found with my experiments. I inserted some debugln into your
method and look at stdout to see the problem. The following is your code
and I only inserted the debugln() at this position:

>     // parse unit
>     CodeToolBoss.Explore(Node.CodePos.Code,Tool,false,false);
>     if Tool=nil then exit;
>     // find source position in parsed code
>     CleanPos:=Node.CodePos.P;
>     // find node
>     CTNode:=Tool.FindDeepestNodeAtPos(CleanPos,false);
> 
>     // here is something wrong already, exactly the
>     // same thing that happened to me when trying to do this
>     debugln(['  Node ', Node.Desc, ' ', node.Identifier]);
>     debugln(['CTNode ', CTNode.Desc, ' ', Tool.ExtractIdentifier(CleanPos)]);
>     debugln(['text -->', Copy(Node.CodePos.Code.Source, CTNode.StartPos, CTNode.EndPos - CTNode.StartPos), '<--']);

Now I simply call your method right at the beginning of GetTVNodeHint()
without any other code to easily experiment with it and see how it
behaves in the original environment where it is supposed to work.

To test it I select LCL in the code browser and then I go to the very
first unit i find there (ActnList) and hover the mouse over some nodes
from the beginning of the list and everything still looks normal. (I
insert it here as email quote to (hopefully) prevent line wrapping and
also attach some output from my console as text document just in case it
is not easily readable here):

>   Node 21 ApplicationActionComponent
> CTNode 21 ApplicationActionComponent
> text -->ApplicationActionComponent: TComponent = nil;<--

or the following is also ok although of course it won't show the correct
identifier yet but the node is found correctly, it displays exactly as
expected:

>   Node 60 CreateAction(TheOwner:TComponent;ActionClass:TBasicActionClass)
> CTNode 60 function
> text -->function CreateAction(TheOwner: TComponent;
>   ActionClass: TBasicActionClass): TBasicAction;<--


and the following is an example of a class definition, everything is
fine, exactly as expected:

>   Node 20 TAction
> CTNode 20 TAction
> text -->TAction = class(TCustomAction)
>   public
>     constructor Create(AOwner: TComponent); override;
>   published
>     property AutoCheck;
>     property Caption;
>     property Checked;
>     property DisableIfNoHandler default True;
>     property Enabled;
>     property GroupIndex;
>     property HelpContext;
>     property HelpKeyword;
>     property HelpType;
>     property Hint;
>     property ImageIndex;
>     property OnExecute;
>     property OnHint;
>     property OnUpdate;
>     property SecondaryShortCuts;
>     property ShortCut;
>     property Visible;
>   end;<--

Now i go down in the list to the unit "Forms" there are many more that
won't work, Forms is just an example. I use the very first definition in
this unit, it is var Application: TApplication; now see how CTNode looks
like:

>   Node 21 Application
> CTNode 21 xceptionObject
> text --> Application: TApplication = ni<--

or a procedure:

>   Node 60 CreateWidgetset(AWidgetsetClass:TWidgetsetClass)
> CTNode 60 procedure
> text -->procedure CreateWidgetse<--

or a class:

>   Node 20 TApplication
> CTNode 21 cationHandlers
> text --> }
> 
>   TApplication = class(TCustomApplication)
>   private
>     FApplic<--

I didn't make any edits in any of these units and have none of them open
in the source editor, the whole project (except my little change in
codebrowser.pas) is right from the svn server and immediately before
this experiment did a clean compile of everything and didn't change
anything.

These are the exact same results that I had when doing it with
BuildTree() and BuildSubTreeAndFindDeepestNodeAtPos(). Can you reproduce
this? If not then what else should I debugln() here to narrow it down?

Bernd
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: some_more_examples_of_the_output.txt
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20100728/4c35a120/attachment-0004.txt>


More information about the Lazarus mailing list