mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-25 13:49:16 +02:00
cody: identifier dictionary: support unit sources in default unit path
git-svn-id: trunk@58015 -
This commit is contained in:
parent
6deedf42c5
commit
0eda8b3796
@ -52,6 +52,7 @@ uses
|
||||
|
||||
const
|
||||
PackageNameFPCSrcDir = 'FPCSrcDir';
|
||||
PackageNameDefault = 'PCCfg';
|
||||
type
|
||||
TCodyUnitDictionary = class;
|
||||
|
||||
@ -345,8 +346,12 @@ begin
|
||||
exit;
|
||||
end;
|
||||
// a fpc unit is better
|
||||
if CheckFlag(i1.GroupName=PackageNameDefault,i2.GroupName=PackageNameDefault,Result) then begin
|
||||
//debugln(['CompareCodyIdentifiersScope fpc.cfg unit ',i1.Identifier,' GroupName 1=',i1.GroupName,' 2=',i2.GroupName]);
|
||||
exit;
|
||||
end;
|
||||
if CheckFlag(i1.GroupName=PackageNameFPCSrcDir,i2.GroupName=PackageNameFPCSrcDir,Result) then begin
|
||||
//debugln(['CompareCodyIdentifiersScope fpc unit ',i1.Identifier,' GroupName 1=',i1.GroupName,' 2=',i2.GroupName]);
|
||||
//debugln(['CompareCodyIdentifiersScope fpcsrcdir unit ',i1.Identifier,' GroupName 1=',i1.GroupName,' 2=',i2.GroupName]);
|
||||
exit;
|
||||
end;
|
||||
// a near directory is better
|
||||
@ -529,6 +534,8 @@ var
|
||||
ok: Boolean;
|
||||
OldChangeStamp: Int64;
|
||||
UnitSet: TFPCUnitSetCache;
|
||||
CfgCache: TPCTargetConfigCache;
|
||||
DefaultFile: String;
|
||||
begin
|
||||
// check without critical section if currently loading/saving
|
||||
if fLoadSaveThread<>nil then
|
||||
@ -581,9 +588,11 @@ begin
|
||||
|
||||
// check if in FPC source directory
|
||||
UnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
|
||||
if (UnitSet<>nil) and (UnitSet.FPCSourceDirectory<>'')
|
||||
if UnitSet<>nil then begin
|
||||
if (UnitSet.FPCSourceDirectory<>'')
|
||||
and FileIsInPath(fParsingTool.MainFilename,UnitSet.FPCSourceDirectory)
|
||||
then begin
|
||||
// unit in FPC source directory
|
||||
BeginCritSec;
|
||||
try
|
||||
UDGroup:=AddUnitGroup(
|
||||
@ -593,6 +602,25 @@ begin
|
||||
finally
|
||||
EndCritSec;
|
||||
end;
|
||||
end else begin
|
||||
CfgCache:=UnitSet.GetConfigCache(false);
|
||||
if (CfgCache<>nil) and (CfgCache.Units<>nil) then begin
|
||||
DefaultFile:=CfgCache.Units[ExtractFileNameOnly(fParsingTool.MainFilename)];
|
||||
if CompareFilenames(DefaultFile,fParsingTool.MainFilename)=0 then
|
||||
begin
|
||||
// unit source is in default compiler unit path
|
||||
BeginCritSec;
|
||||
try
|
||||
UDGroup:=AddUnitGroup(
|
||||
ExtractFilePath(UnitSet.CompilerFilename)+PackageNameDefault+'.lpk',
|
||||
PackageNameDefault);
|
||||
UDGroup.AddUnit(UDUnit);
|
||||
finally
|
||||
EndCritSec;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
if ChangeStamp<>OldChangeStamp then begin
|
||||
@ -1055,7 +1083,7 @@ var
|
||||
procedure AddItems(AddExactMatches: boolean);
|
||||
var
|
||||
FPCSrcFilename: String;
|
||||
Dir: String;
|
||||
Dir, aFilename: String;
|
||||
Group: TUDUnitGroup;
|
||||
GroupNode: TAVLTreeNode;
|
||||
Item: TUDIdentifier;
|
||||
@ -1116,6 +1144,16 @@ var
|
||||
continue; // the unit has no ppu file
|
||||
end;
|
||||
end;
|
||||
end else if Group.Name=PackageNameDefault then begin
|
||||
// unit was in default unit path
|
||||
// => check if this is still the case
|
||||
if CfgCache<>nil then begin
|
||||
aFilename:=CfgCache.Units[Item.DUnit.Name];
|
||||
if aFilename='' then
|
||||
continue; // the unit is not in current default unit path
|
||||
if CompareFilenames(aFilename,Item.DUnit.Filename)<>0 then
|
||||
continue; // this is another unit (e.g. from another compiler target)
|
||||
end;
|
||||
end else if FileExistsCached(Group.Filename) then begin
|
||||
// lpk exists
|
||||
end else begin
|
||||
@ -1168,8 +1206,12 @@ begin
|
||||
for i:=0 to FItems.Count-1 do begin
|
||||
Item:=TCodyIdentifier(FItems[i]);
|
||||
s:=Item.Identifier+' in '+Item.Unit_Name;
|
||||
if Item.GroupName<>'' then
|
||||
if Item.GroupName<>'' then begin
|
||||
if Item.GroupName=PackageNameDefault then
|
||||
s:=s+' in compiler unit path'
|
||||
else
|
||||
s:=s+' of '+Item.GroupName;
|
||||
end;
|
||||
sl.Add(s);
|
||||
end;
|
||||
if Found>sl.Count then
|
||||
@ -1228,6 +1270,8 @@ begin
|
||||
continue; // other project is always far away
|
||||
if Item.GroupName=PackageNameFPCSrcDir then
|
||||
continue; // FPC unit
|
||||
if Item.GroupName=PackageNameDefault then
|
||||
continue; // FPC unit
|
||||
if CurOwner=nil then continue;
|
||||
// package unit
|
||||
Item.InUsedPackage:=PackageEditingInterface.IsOwnerDependingOnPkg(CurOwner,
|
||||
@ -1481,13 +1525,16 @@ begin
|
||||
NewUnitInPath:=true;
|
||||
end
|
||||
else if (CurUnitPath<>'')
|
||||
// and FilenameIsAbsolute(CurMainFilename) then begin
|
||||
// MainPath:=ExtractFilePath(CurMainFilename);
|
||||
// if (FindPathInSearchPath(PChar(MainPath),length(MainPath),
|
||||
and FilenameIsAbsolute(NewUnitName) then begin
|
||||
NewUnitDir:=ExtractFilePath(NewUnitName);
|
||||
if (FindPathInSearchPath(PChar(NewUnitDir),length(NewUnitDir),
|
||||
PChar(CurUnitPath),length(CurUnitPath))<>nil)
|
||||
then begin
|
||||
// in unit search path
|
||||
debugln(['TCodyIdentifiersDlg.UseIdentifier in unit search path of owner MainPath="',NewUnitDir,'" CurUnitPath="',CurUnitPath,'"']);
|
||||
debugln(['TCodyIdentifiersDlg.UseIdentifier in unit search path of owner NewUnitDir="',NewUnitDir,'" CurUnitPath="',CurUnitPath,'"']);
|
||||
NewUnitInPath:=true;
|
||||
end;
|
||||
end;
|
||||
@ -1510,6 +1557,9 @@ begin
|
||||
mtConfirmation, [mrOk, crsExtendUnitPath, mrCancel])<> mrOk then exit;
|
||||
end else
|
||||
NewUnitInPath:=true;
|
||||
end else if NewGroupName=PackageNameDefault then begin
|
||||
// new unit is in default compiler unit path
|
||||
NewUnitInPath:=true;
|
||||
end else if NewGroupName<>'' then begin
|
||||
// new unit is part of a package
|
||||
debugln(['TCodyIdentifiersDlg.UseIdentifier unit is part of a package in "'+NewGroupFilename+'"']);
|
||||
@ -1530,15 +1580,21 @@ begin
|
||||
mrOk, crsCloseOtherPackageAndOpenNew]) <> mrOk
|
||||
then exit;
|
||||
end;
|
||||
end else begin
|
||||
end;
|
||||
if not NewUnitInPath then begin
|
||||
// new unit is a rogue unit (no package)
|
||||
debugln(['TCodyIdentifiersDlg.UseIdentifier unit is not in a package']);
|
||||
if UnitSet.GetUnitToSourceTree(false).Contains(NewUnitName) then
|
||||
NewUnitInPath:=true;
|
||||
end;
|
||||
end;
|
||||
|
||||
// open package to get the compiler settings to parse the unit
|
||||
if (CurOwner<>nil) and (not NewUnitInPath)
|
||||
and (NewGroupName<>'') and (NewGroupName<>PackageNameFPCSrcDir) then begin
|
||||
if (CurOwner<>nil)
|
||||
and (not NewUnitInPath)
|
||||
and (NewGroupName<>'')
|
||||
and (NewGroupName<>PackageNameFPCSrcDir)
|
||||
and (NewGroupName<>PackageNameDefault) then begin
|
||||
if not OpenDependency then exit;
|
||||
end;
|
||||
|
||||
@ -1572,8 +1628,11 @@ begin
|
||||
debugln(['TCodyIdentifiersDlg.UseIdentifier CurOwner=',DbgSName(CurOwner),' ',NewUnitInPath]);
|
||||
if (CurOwner<>nil) and (not NewUnitInPath) then begin
|
||||
debugln(['TCodyIdentifiersDlg.UseIdentifier not in unit path, connecting pkg="',NewGroupName,'" ...']);
|
||||
if (NewGroupName<>'') and (NewGroupName<>PackageNameFPCSrcDir) then begin
|
||||
if (NewGroupName<>'') then begin
|
||||
// add dependency
|
||||
if (NewGroupName<>PackageNameFPCSrcDir)
|
||||
and (NewGroupName<>PackageNameDefault)
|
||||
then
|
||||
if not AddDependency then exit;
|
||||
end else if FilenameIsAbsolute(NewUnitFilename)
|
||||
and FilenameIsAbsolute(CurMainFilename) then begin
|
||||
@ -1613,7 +1672,9 @@ begin
|
||||
end;
|
||||
|
||||
// open package to get proper settings
|
||||
if (NewGroupName<>'') and (NewGroupName<>PackageNameFPCSrcDir) then begin
|
||||
if (NewGroupName<>'')
|
||||
and (NewGroupName<>PackageNameFPCSrcDir)
|
||||
and (NewGroupName<>PackageNameDefault) then begin
|
||||
Pkg:=PackageEditingInterface.FindPackageWithName(NewGroupName);
|
||||
if (Pkg=nil) or (CompareFilenames(Pkg.Filename,NewGroupFilename)<>0) then
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user