Sign in Join

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

Mailing lists / fpc-pascal / 2020-05

Using include files in code tools

9 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

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

Reply by email

Mattias Gaertner
to Ryan Joseph
Show quoted text 5 lines
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

Reply by email

Mattias Gaertner
to Mattias Gaertner
Show quoted text 11 lines
[...]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

Reply by email

Ryan Joseph
to Mattias Gaertner: On Thu, 7 May 2020 16:26:12 +0700 Nodes are always associated with a Tool.…
Show quoted text 5 lines
On May 7, 2020, at 5:26 PM, Mattias Gaertner via fpc-pascal 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.

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

Reply by email

Ryan Joseph
to Ryan Joseph
Show quoted text 11 lines
On May 7, 2020, at 8:21 PM, Ryan Joseph 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

Reply by email

Mattias Gaertner
to Ryan Joseph: Just curious, can you explain the reasoning of "tools"? I haven't exactly figured out the…
Show quoted text 9 lines
> On May 7, 2020, at 5:26 PM, Mattias Gaertner via fpc-pascal > 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

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

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

Reply by email

Ryan Joseph
to Mattias Gaertner
On May 9, 2020, at 4:36 PM, Mattias Gaertner via fpc-pascal 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

Reply by email

Mattias Gaertner
to Ryan Joseph
Show quoted text 10 lines
> On May 9, 2020, at 4:36 PM, Mattias Gaertner via fpc-pascal > 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

Reply by email

Ryan Joseph
to Mattias Gaertner
On May 10, 2020, at 1:20 AM, Mattias Gaertner via fpc-pascal 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

Reply by email