Sign in Join

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

Mailing lists / fpc-pascal / 2020-05

Code tools search paths

10 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

I found out that setting TCodeToolsOptions.FPCOptions (-Fu and -Fi) was doing something because it helped FindDeclaration to search for units not in the same same directory as the main program. However now I've encountered problems with FindReferences (the example Mattias made for me) which seem to be caused by the inclusion of FPCOptions (if I remove the FPC options it properly builds the unit search graph).

reading on https://wiki.lazarus.freepascal.org/Codetools it sounds like I need to be using TDefineTemplate to add unit search paths. Which is the correct way to do this?

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Ryan Joseph
Show quoted text 11 lines
I found out that setting TCodeToolsOptions.FPCOptions (-Fu and -Fi) was doing something because it helped FindDeclaration to search for units not in the same same directory as the main program. However now I've encountered problems with FindReferences (the example Mattias made for me) which seem to be caused by the inclusion of FPCOptions (if I remove the FPC options it properly builds the unit search graph). reading on https://wiki.lazarus.freepascal.org/Codetools it sounds like I need to be using TDefineTemplate to add unit search paths. Which is the correct way to do this?

TDefineTemplates.
see for example
lazarus/components/codetools/examples/setincludepath.pas

Mattias

Reply by email

Ryan Joseph
to Mattias Gaertner
Show quoted text 6 lines
On May 10, 2020, at 4:47 PM, Mattias Gaertner via fpc-pascal wrote: TDefineTemplates. see for example lazarus/components/codetools/examples/setincludepath.pas

Ok, I'll move to this. What are the FPC options for then? I thought I could do things like -Fu and -d with it.

Are include paths and unit paths the same? I just see TDefineTemplate which seems to do both.

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Ryan Joseph
Show quoted text 10 lines
> On May 10, 2020, at 4:47 PM, Mattias Gaertner via fpc-pascal > wrote: > > TDefineTemplates. > see for example > lazarus/components/codetools/examples/setincludepath.pas > Ok, I'll move to this. What are the FPC options for then? I thought I could do things like -Fu and -d with it.

Yes, you can.
They are treated like global options, i.e. as if added to the fpc.cfg.

Are include paths and unit paths the same?

No.

I just see TDefineTemplate which seems to do both.

There are separate macros.

Mattias

Reply by email

Ryan Joseph
to Ryan Joseph: Ok, I'll move to this. What are the FPC options for then? I thought I could do things…
Show quoted text 5 lines
On May 11, 2020, at 10:56 AM, Ryan Joseph wrote: Ok, I'll move to this. What are the FPC options for then? I thought I could do things like -Fu and -d with it. Are include paths and unit paths the same? I just see TDefineTemplate which seems to do both.

Removing the FPCOptions fixed the FindReferences but I still don't seem to be getting your define template system:

If I just want to add unit search paths do I do this? The user is just going to supply absolute paths to the language server (just like they would from the command line).

// add all the unit paths
for Path in Paths do
begin
	DirectoryTemplate := TDefineTemplate.Create('Directory','','',ExpandFileName(Path),da_Directory);
          UnitPathTemplate := TDefineTemplate.Create('???','???',
            UnitPathMacroName,
            UnitPathMacro+';'+ExpandFileName(Path),
            da_Define
            );
          DirectoryTemplate.AddChild(UnitPathTemplate);
          CodeToolBoss.DefineTree.Add(DirectoryTemplate);
end;

Regards,
Ryan Joseph

Reply by email

Ryan Joseph
to Mattias Gaertner: On Mon, 11 May 2020 10:56:32 +0700 Yes, you can. They are treated like global options,…
On May 11, 2020, at 4:55 PM, Mattias Gaertner via fpc-pascal wrote: Yes, you can. They are treated like global options, i.e. as if added to the fpc.cfg.

Then I don't understand why those affect FindReferences but worked for other areas. Using those were easier than what I'm doing with the define templates but maybe I'm confused (see my follow up I just sent).

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Ryan Joseph: Removing the FPCOptions fixed the FindReferences but I still don't seem to be getting…
[...] If I just want to add unit search paths do I do this? The user is just going to supply absolute paths to the language server (just like they would from the command line).

FPC is happy with ppu files. Codetools need sources. So it needs the settings where the ppu files are coming from. Therefore codetools allows to have different settings for each directory.

Show quoted text 5 lines
// add all the unit paths for Path in Paths do begin DirectoryTemplate := TDefineTemplate.Create('Directory','','',ExpandFileName(Path),da_Directory);

This creates a node for directory Path. Path should be your program directory.

Show quoted text 6 lines
UnitPathTemplate := TDefineTemplate.Create('???','???', UnitPathMacroName, UnitPathMacro+';'+ExpandFileName(Path), da_Define ); DirectoryTemplate.AddChild(UnitPathTemplate);

This expands the UnitPath of directory Path with Path. Maybe you meant
UnitPathMacro+';'+ExpandFileName(SomeUnitPath),
?

CodeToolBoss.DefineTree.Add(DirectoryTemplate); end;

Mattias

Reply by email

Ryan Joseph
to Mattias Gaertner
Show quoted text 16 lines
On May 11, 2020, at 6:41 PM, Mattias Gaertner via fpc-pascal wrote: This creates a node for directory Path. Path should be your program directory. > UnitPathTemplate := TDefineTemplate.Create('???','???', > UnitPathMacroName, > UnitPathMacro+';'+ExpandFileName(Path), > da_Define > ); > DirectoryTemplate.AddChild(UnitPathTemplate); This expands the UnitPath of directory Path with Path. Maybe you meant UnitPathMacro+';'+ExpandFileName(SomeUnitPath),

I wanted this to behave like the compiler normally does, that is you supply paths to the units with -Fu and includes with -Fi. What is the way to achieve that here?

For example in my test project I have the directory that contains the program and another direction to test units in other directories so I basically just want:

pp /path/to/test.pas -Fu/path/to/other_units

Pretty simple but I don't seem to be going about it correctly.

Regards,
Ryan Joseph

Reply by email

Ryan Joseph
to Ryan Joseph
Show quoted text 7 lines
On May 11, 2020, at 8:02 PM, Ryan Joseph wrote: I wanted this to behave like the compiler normally does, that is you supply paths to the units with -Fu and includes with -Fi. What is the way to achieve that here? For example in my test project I have the directory that contains the program and another direction to test units in other directories so I basically just want: pp /path/to/test.pas -Fu/path/to/other_units

I still haven't figured this out. I would be happy to use FPCOptions at init time but those break FindReferences for some reason.

Regards,
Ryan Joseph

Reply by email

Mattias Gaertner
to Ryan Joseph
Show quoted text 15 lines
> On May 11, 2020, at 8:02 PM, Ryan Joseph > wrote: > > I wanted this to behave like the compiler normally does, that is > you supply paths to the units with -Fu and includes with -Fi. What > is the way to achieve that here? > > For example in my test project I have the directory that contains > the program and another direction to test units in other > directories so I basically just want: > > pp /path/to/test.pas -Fu/path/to/other_units I still haven't figured this out. I would be happy to use FPCOptions at init time but those break FindReferences for some reason.

Please create bug report with an example.

Mattias

Reply by email