Sign in Join

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

Mailing lists / fpc-pascal / 2022-10

Exploring block statements with CodeTools not working

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Hairy Pixels

I’m trying to look at the code in a the begin..end section of this sample program but for some reason when it gets to the BeginBlock node child count is always 0 (other nodes are as expected though). I’m calling Explore correctly I think so what could the problem be?

Here is the little test program I’m using along with a snippet which explores the code and walks the tree.

Btw, I understand this question is basically for Mattias but I don’t know where else to post. Does Mattias prefer I post in one of these forums https://forum.lazarus.freepascal.org or maybe email privately with code tools questions?

========================

  program test;
  var
    A: Integer;
  begin
    A := 1;
  end.

========================

CodeToolBoss.Explore(Code, Tool, true);
Node := tool.Tree.Root;
while Node  nil do
  begin
    writeln(Node.DescAsString, ‘ -> ’, Node.ChildCount);
    Node := Node.Next;
  end;

Regards,
Ryan Joseph

Reply by email

Ondrej Pokorny
to Hairy Pixels
Hairy Pixels wrote
Btw, I understand this question is basically for Mattias but I don’t know where else to post. Does Mattias prefer I post in one of these forums https://forum.lazarus.freepascal.org or maybe email privately with code tools questions?

Though I am not Mattias and cannot comment on his preferences: CodeTools are part of the Lazarus project, hence the question belongs to the Lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus or one of the IDE categories in the forum.

Ondrej

Reply by email

Hairy Pixels
to Mattias Gaertner
On Oct 16, 2022, at 4:17 PM, Mattias Gaertner via fpc-pascal wrote: That's correct. There are no nodes for simple statements like "a:=1".

Really? I was going to use this to find unknown identifiers (for LSP diagnostics) and try to implement LSP’s new inlay parameter hints feature. I didn’t see function calls appear as nodes either. Is there anything at all that’s captured in code blocks?

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Hairy Pixels
Show quoted text 10 lines
> On Oct 16, 2022, at 4:17 PM, Mattias Gaertner via fpc-pascal > wrote: > > That's correct. There are no nodes for simple statements like > "a:=1". Really? I was going to use this to find unknown identifiers (for LSP diagnostics) and try to implement LSP’s new inlay parameter hints feature. I didn’t see function calls appear as nodes either. Is there anything at all that’s captured in code blocks?

Blocks like WHILE and TRY.

Codetools are optimized for finding declarations of a few expressions between edits. To find the parameters, call for each identifier followed by ( the FindCodeContext function.

Mattias

Reply by email

Hairy Pixels
to Mattias Gaertner
Show quoted text 7 lines
On Oct 16, 2022, at 9:53 PM, Mattias Gaertner via fpc-pascal wrote: Blocks like WHILE and TRY. Codetools are optimized for finding declarations of a few expressions between edits. To find the parameters, call for each identifier followed by ( the FindCodeContext function.

So inlay hints need to be computed with a document range so we don’t know a single X,Y position we could use to call FindCodeContext. If I had a list of identifiers which were function calls in begin blocks I could call FindCodeContext based on those. Is that possible?

If not maybe I could make a Tool subclass? I tried this once but I couldn’t figure out how that may work and I was confused about all the different types of tools and how they fit together.

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Hairy Pixels
Show quoted text 13 lines
> On Oct 16, 2022, at 9:53 PM, Mattias Gaertner via fpc-pascal > wrote: > > Blocks like WHILE and TRY. > > Codetools are optimized for finding declarations of a few > expressions between edits. To find the parameters, call for each > identifier followed by ( the FindCodeContext function. So inlay hints need to be computed with a document range so we don’t know a single X,Y position we could use to call FindCodeContext. If I had a list of identifiers which were function calls in begin blocks I could call FindCodeContext based on those. Is that possible?

Yes

Mattias

Reply by email

Hairy Pixels
to Mattias Gaertner
Show quoted text 8 lines
On Oct 17, 2022, at 3:31 PM, Mattias Gaertner via fpc-pascal wrote: > So inlay hints need to be computed with a document range so we don’t > know a single X,Y position we could use to call FindCodeContext. If I > had a list of identifiers which were function calls in begin blocks I > could call FindCodeContext based on those. Is that possible? Yes

Not following. :) If it possible to get a list of identifiers in a begin block how would you do that?

Lets say we have this program. Does CodeTools have any way to know there is a DoThis(1) call inside that begin end block without giving it an explicit position? Ideally I could give it the position of the begin block since we do get that node and it would give me back a list of identifiers which have their document position so I could perform operations on that later.

===========================

program test;
procedure DoThis(param: integer);
begin
end;
begin
  DoThis(1);
end.

Regards,
Ryan Joseph

Reply by email