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
|
const
|
||||||
PackageNameFPCSrcDir = 'FPCSrcDir';
|
PackageNameFPCSrcDir = 'FPCSrcDir';
|
||||||
|
PackageNameDefault = 'PCCfg';
|
||||||
type
|
type
|
||||||
TCodyUnitDictionary = class;
|
TCodyUnitDictionary = class;
|
||||||
|
|
||||||
@ -345,8 +346,12 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
// a fpc unit is better
|
// 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
|
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;
|
exit;
|
||||||
end;
|
end;
|
||||||
// a near directory is better
|
// a near directory is better
|
||||||
@ -529,6 +534,8 @@ var
|
|||||||
ok: Boolean;
|
ok: Boolean;
|
||||||
OldChangeStamp: Int64;
|
OldChangeStamp: Int64;
|
||||||
UnitSet: TFPCUnitSetCache;
|
UnitSet: TFPCUnitSetCache;
|
||||||
|
CfgCache: TPCTargetConfigCache;
|
||||||
|
DefaultFile: String;
|
||||||
begin
|
begin
|
||||||
// check without critical section if currently loading/saving
|
// check without critical section if currently loading/saving
|
||||||
if fLoadSaveThread<>nil then
|
if fLoadSaveThread<>nil then
|
||||||
@ -581,17 +588,38 @@ begin
|
|||||||
|
|
||||||
// check if in FPC source directory
|
// check if in FPC source directory
|
||||||
UnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
|
UnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
|
||||||
if (UnitSet<>nil) and (UnitSet.FPCSourceDirectory<>'')
|
if UnitSet<>nil then begin
|
||||||
and FileIsInPath(fParsingTool.MainFilename,UnitSet.FPCSourceDirectory)
|
if (UnitSet.FPCSourceDirectory<>'')
|
||||||
then begin
|
and FileIsInPath(fParsingTool.MainFilename,UnitSet.FPCSourceDirectory)
|
||||||
BeginCritSec;
|
then begin
|
||||||
try
|
// unit in FPC source directory
|
||||||
UDGroup:=AddUnitGroup(
|
BeginCritSec;
|
||||||
AppendPathDelim(UnitSet.FPCSourceDirectory)+PackageNameFPCSrcDir+'.lpk',
|
try
|
||||||
PackageNameFPCSrcDir);
|
UDGroup:=AddUnitGroup(
|
||||||
UDGroup.AddUnit(UDUnit);
|
AppendPathDelim(UnitSet.FPCSourceDirectory)+PackageNameFPCSrcDir+'.lpk',
|
||||||
finally
|
PackageNameFPCSrcDir);
|
||||||
EndCritSec;
|
UDGroup.AddUnit(UDUnit);
|
||||||
|
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;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1055,7 +1083,7 @@ var
|
|||||||
procedure AddItems(AddExactMatches: boolean);
|
procedure AddItems(AddExactMatches: boolean);
|
||||||
var
|
var
|
||||||
FPCSrcFilename: String;
|
FPCSrcFilename: String;
|
||||||
Dir: String;
|
Dir, aFilename: String;
|
||||||
Group: TUDUnitGroup;
|
Group: TUDUnitGroup;
|
||||||
GroupNode: TAVLTreeNode;
|
GroupNode: TAVLTreeNode;
|
||||||
Item: TUDIdentifier;
|
Item: TUDIdentifier;
|
||||||
@ -1116,6 +1144,16 @@ var
|
|||||||
continue; // the unit has no ppu file
|
continue; // the unit has no ppu file
|
||||||
end;
|
end;
|
||||||
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
|
end else if FileExistsCached(Group.Filename) then begin
|
||||||
// lpk exists
|
// lpk exists
|
||||||
end else begin
|
end else begin
|
||||||
@ -1168,8 +1206,12 @@ begin
|
|||||||
for i:=0 to FItems.Count-1 do begin
|
for i:=0 to FItems.Count-1 do begin
|
||||||
Item:=TCodyIdentifier(FItems[i]);
|
Item:=TCodyIdentifier(FItems[i]);
|
||||||
s:=Item.Identifier+' in '+Item.Unit_Name;
|
s:=Item.Identifier+' in '+Item.Unit_Name;
|
||||||
if Item.GroupName<>'' then
|
if Item.GroupName<>'' then begin
|
||||||
s:=s+' of '+Item.GroupName;
|
if Item.GroupName=PackageNameDefault then
|
||||||
|
s:=s+' in compiler unit path'
|
||||||
|
else
|
||||||
|
s:=s+' of '+Item.GroupName;
|
||||||
|
end;
|
||||||
sl.Add(s);
|
sl.Add(s);
|
||||||
end;
|
end;
|
||||||
if Found>sl.Count then
|
if Found>sl.Count then
|
||||||
@ -1228,6 +1270,8 @@ begin
|
|||||||
continue; // other project is always far away
|
continue; // other project is always far away
|
||||||
if Item.GroupName=PackageNameFPCSrcDir then
|
if Item.GroupName=PackageNameFPCSrcDir then
|
||||||
continue; // FPC unit
|
continue; // FPC unit
|
||||||
|
if Item.GroupName=PackageNameDefault then
|
||||||
|
continue; // FPC unit
|
||||||
if CurOwner=nil then continue;
|
if CurOwner=nil then continue;
|
||||||
// package unit
|
// package unit
|
||||||
Item.InUsedPackage:=PackageEditingInterface.IsOwnerDependingOnPkg(CurOwner,
|
Item.InUsedPackage:=PackageEditingInterface.IsOwnerDependingOnPkg(CurOwner,
|
||||||
@ -1474,20 +1518,23 @@ begin
|
|||||||
debugln(['TCodyIdentifiersDlg.UseIdentifier same unit CurMainFilename="',CurMainFilename,'" NewUnitFilename="',NewUnitFilename,'"']);
|
debugln(['TCodyIdentifiersDlg.UseIdentifier same unit CurMainFilename="',CurMainFilename,'" NewUnitFilename="',NewUnitFilename,'"']);
|
||||||
end
|
end
|
||||||
else if (CompareFilenames(ExtractFilePath(CurMainFilename),
|
else if (CompareFilenames(ExtractFilePath(CurMainFilename),
|
||||||
ExtractFilePath(NewUnitFilename))=0)
|
ExtractFilePath(NewUnitFilename))=0)
|
||||||
then begin
|
then begin
|
||||||
// same directory
|
// same directory
|
||||||
debugln(['TCodyIdentifiersDlg.UseIdentifier same directory CurMainFilename="',CurMainFilename,'" NewUnitFilename="',NewUnitFilename,'"']);
|
debugln(['TCodyIdentifiersDlg.UseIdentifier same directory CurMainFilename="',CurMainFilename,'" NewUnitFilename="',NewUnitFilename,'"']);
|
||||||
NewUnitInPath:=true;
|
NewUnitInPath:=true;
|
||||||
end
|
end
|
||||||
else if (CurUnitPath<>'')
|
else if (CurUnitPath<>'')
|
||||||
|
// and FilenameIsAbsolute(CurMainFilename) then begin
|
||||||
|
// MainPath:=ExtractFilePath(CurMainFilename);
|
||||||
|
// if (FindPathInSearchPath(PChar(MainPath),length(MainPath),
|
||||||
and FilenameIsAbsolute(NewUnitName) then begin
|
and FilenameIsAbsolute(NewUnitName) then begin
|
||||||
NewUnitDir:=ExtractFilePath(NewUnitName);
|
NewUnitDir:=ExtractFilePath(NewUnitName);
|
||||||
if (FindPathInSearchPath(PChar(NewUnitDir),length(NewUnitDir),
|
if (FindPathInSearchPath(PChar(NewUnitDir),length(NewUnitDir),
|
||||||
PChar(CurUnitPath),length(CurUnitPath))<>nil)
|
PChar(CurUnitPath),length(CurUnitPath))<>nil)
|
||||||
then begin
|
then begin
|
||||||
// in unit search path
|
// 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;
|
NewUnitInPath:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1510,6 +1557,9 @@ begin
|
|||||||
mtConfirmation, [mrOk, crsExtendUnitPath, mrCancel])<> mrOk then exit;
|
mtConfirmation, [mrOk, crsExtendUnitPath, mrCancel])<> mrOk then exit;
|
||||||
end else
|
end else
|
||||||
NewUnitInPath:=true;
|
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
|
end else if NewGroupName<>'' then begin
|
||||||
// new unit is part of a package
|
// new unit is part of a package
|
||||||
debugln(['TCodyIdentifiersDlg.UseIdentifier unit is part of a package in "'+NewGroupFilename+'"']);
|
debugln(['TCodyIdentifiersDlg.UseIdentifier unit is part of a package in "'+NewGroupFilename+'"']);
|
||||||
@ -1530,15 +1580,21 @@ begin
|
|||||||
mrOk, crsCloseOtherPackageAndOpenNew]) <> mrOk
|
mrOk, crsCloseOtherPackageAndOpenNew]) <> mrOk
|
||||||
then exit;
|
then exit;
|
||||||
end;
|
end;
|
||||||
end else begin
|
end;
|
||||||
|
if not NewUnitInPath then begin
|
||||||
// new unit is a rogue unit (no package)
|
// new unit is a rogue unit (no package)
|
||||||
debugln(['TCodyIdentifiersDlg.UseIdentifier unit is not in a package']);
|
debugln(['TCodyIdentifiersDlg.UseIdentifier unit is not in a package']);
|
||||||
|
if UnitSet.GetUnitToSourceTree(false).Contains(NewUnitName) then
|
||||||
|
NewUnitInPath:=true;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// open package to get the compiler settings to parse the unit
|
// open package to get the compiler settings to parse the unit
|
||||||
if (CurOwner<>nil) and (not NewUnitInPath)
|
if (CurOwner<>nil)
|
||||||
and (NewGroupName<>'') and (NewGroupName<>PackageNameFPCSrcDir) then begin
|
and (not NewUnitInPath)
|
||||||
|
and (NewGroupName<>'')
|
||||||
|
and (NewGroupName<>PackageNameFPCSrcDir)
|
||||||
|
and (NewGroupName<>PackageNameDefault) then begin
|
||||||
if not OpenDependency then exit;
|
if not OpenDependency then exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1572,9 +1628,12 @@ begin
|
|||||||
debugln(['TCodyIdentifiersDlg.UseIdentifier CurOwner=',DbgSName(CurOwner),' ',NewUnitInPath]);
|
debugln(['TCodyIdentifiersDlg.UseIdentifier CurOwner=',DbgSName(CurOwner),' ',NewUnitInPath]);
|
||||||
if (CurOwner<>nil) and (not NewUnitInPath) then begin
|
if (CurOwner<>nil) and (not NewUnitInPath) then begin
|
||||||
debugln(['TCodyIdentifiersDlg.UseIdentifier not in unit path, connecting pkg="',NewGroupName,'" ...']);
|
debugln(['TCodyIdentifiersDlg.UseIdentifier not in unit path, connecting pkg="',NewGroupName,'" ...']);
|
||||||
if (NewGroupName<>'') and (NewGroupName<>PackageNameFPCSrcDir) then begin
|
if (NewGroupName<>'') then begin
|
||||||
// add dependency
|
// add dependency
|
||||||
if not AddDependency then exit;
|
if (NewGroupName<>PackageNameFPCSrcDir)
|
||||||
|
and (NewGroupName<>PackageNameDefault)
|
||||||
|
then
|
||||||
|
if not AddDependency then exit;
|
||||||
end else if FilenameIsAbsolute(NewUnitFilename)
|
end else if FilenameIsAbsolute(NewUnitFilename)
|
||||||
and FilenameIsAbsolute(CurMainFilename) then begin
|
and FilenameIsAbsolute(CurMainFilename) then begin
|
||||||
// extend unit path
|
// extend unit path
|
||||||
@ -1613,7 +1672,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// open package to get proper settings
|
// 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);
|
Pkg:=PackageEditingInterface.FindPackageWithName(NewGroupName);
|
||||||
if (Pkg=nil) or (CompareFilenames(Pkg.Filename,NewGroupFilename)<>0) then
|
if (Pkg=nil) or (CompareFilenames(Pkg.Filename,NewGroupFilename)<>0) then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user