Using include files in code tools

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Using include files in code tools

Free Pascal - General mailing list
When using code tools I've found that it needs to start from a main unit (otherwise other relevant macros may not be set) and then insert includes into the source text. This is fine but when I inspect the node tree (TCodeTreeNode) how do I know which include a node came from?

I need this information so I can get navigate to the include file AND relative text offset into the include file text.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list
On Thu, 7 May 2020 16:26:12 +0700
Ryan Joseph via fpc-pascal <[hidden email]> wrote:

> When using code tools I've found that it needs to start from a main
> unit (otherwise other relevant macros may not be set) and then insert
> includes into the source text. This is fine but when I inspect the
> node tree (TCodeTreeNode) how do I know which include a node came
> from?

Nodes are always associated with a Tool. Tool.MainFilename gives the
file, where parsing started.

 
> I need this information so I can get navigate to the include file AND
> relative text offset into the include file text.

There are plenty of functions for include files. Can you give an
example what you need?

Mattias

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list
On Thu, 7 May 2020 12:26:53 +0200
Mattias Gaertner via fpc-pascal <[hidden email]> wrote:

>[...]how do I know which include a
> > node came from?  
>
> Nodes are always associated with a Tool. Tool.MainFilename gives the
> file, where parsing started.
>  
> > I need this information so I can get navigate to the include file
> > AND relative text offset into the include file text.  
>
> There are plenty of functions for include files. Can you give an
> example what you need?

Tool.CleanPosToCaret(Node.StartPos,CXY)
Tool.CleanPosToCodePos(Node.StartPos,CP)

Mattias

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list
In reply to this post by Free Pascal - General mailing list


> On May 7, 2020, at 5:26 PM, Mattias Gaertner via fpc-pascal <[hidden email]> wrote:
>
> Nodes are always associated with a Tool. Tool.MainFilename gives the
> file, where parsing started.
>

Just curious, can you explain the reasoning of "tools"? I haven't exactly figured out the delegation of tasks in your system.

>
>> I need this information so I can get navigate to the include file AND
>> relative text offset into the include file text.
>
> There are plenty of functions for include files. Can you give an
> example what you need?

I start with CodeToolBoss.Explore after loading the unit and get the current tool from that. I need to start with an actual unit right? I don't think it will parse plain include files on its own, and that won't often work anyways because there are  macros in the unit which includes the include file.

I'm collecting the symbols so that I can return them to the client and it can navigate to a particular file at a line/column number. The file which I navigate to must be the include file but I only have those location relative to the unit, not the include.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list


> On May 7, 2020, at 8:21 PM, Ryan Joseph <[hidden email]> wrote:
>
>>> I need this information so I can get navigate to the include file AND
>>> relative text offset into the include file text.
>>
>> There are plenty of functions for include files. Can you give an
>> example what you need?
>
> I start with CodeToolBoss.Explore after loading the unit and get the current tool from that. I need to start with an actual unit right? I don't think it will parse plain include files on its own, and that won't often work anyways because there are  macros in the unit which includes the include file.
>
> I'm collecting the symbols so that I can return them to the client and it can navigate to a particular file at a line/column number. The file which I navigate to must be the include file but I only have those location relative to the unit, not the include.

sorry to pester but any ideas on this? I still haven't figured it out yet.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list
In reply to this post by Free Pascal - General mailing list
On Thu, 7 May 2020 20:21:35 +0700
Ryan Joseph via fpc-pascal <[hidden email]> wrote:

> > On May 7, 2020, at 5:26 PM, Mattias Gaertner via fpc-pascal
> > <[hidden email]> wrote:
> >
> > Nodes are always associated with a Tool. Tool.MainFilename gives the
> > file, where parsing started.
> >  
>
> Just curious, can you explain the reasoning of "tools"? I haven't
> exactly figured out the delegation of tasks in your system.

Maybe this helps:
https://wiki.freepascal.org/Codetools#Tool.2C_Node.2C_LinkScanner


> >> I need this information so I can get navigate to the include file
> >> AND relative text offset into the include file text.  
> >
> > There are plenty of functions for include files. Can you give an
> > example what you need?  
>
> I start with CodeToolBoss.Explore after loading the unit and get the
> current tool from that. I need to start with an actual unit right?

Yes, if you need the higher level functions like FindDeclaration.

Of course there are lower level functions to parse snippets. See unit
BasicCodetools.


> don't think it will parse plain include files on its own, and that
> won't often work anyways because there are  macros in the unit which
> includes the include file.
>
> I'm collecting the symbols so that I can return them to the client
> and it can navigate to a particular file at a line/column number. The
> file which I navigate to must be the include file but I only have
> those location relative to the unit, not the include.

Use Tool.CleanPosToCaret(Node.StartPos,xyp) to get the file, line and
column.

Mattias


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list


> On May 9, 2020, at 4:36 PM, Mattias Gaertner via fpc-pascal <[hidden email]> wrote:
>
> Use Tool.CleanPosToCaret(Node.StartPos,xyp) to get the file, line and
> column.

Thanks, I was just using the raw Node.StartPos location. Is there any flag in a node to know if it came from an include? That would be helpful because otherwise I need to call CleanPosToCaret on every symbol regardless of where it came from.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list
On Sat, 9 May 2020 20:55:24 +0700
Ryan Joseph via fpc-pascal <[hidden email]> wrote:

> > On May 9, 2020, at 4:36 PM, Mattias Gaertner via fpc-pascal
> > <[hidden email]> wrote:
> >
> > Use Tool.CleanPosToCaret(Node.StartPos,xyp) to get the file, line
> > and column.  
>
> Thanks, I was just using the raw Node.StartPos location. Is there any
> flag in a node to know if it came from an include? That would be
> helpful because otherwise I need to call CleanPosToCaret on every
> symbol regardless of where it came from.

CleanPosToCaret is using a binary search. Compared to the other
operations like parsing, this is is hardly measurable.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Using include files in code tools

Free Pascal - General mailing list


> On May 10, 2020, at 1:20 AM, Mattias Gaertner via fpc-pascal <[hidden email]> wrote:
>
> CleanPosToCaret is using a binary search. Compared to the other
> operations like parsing, this is is hardly measurable.

Thanks, I got it working now.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal