cody: dictionary: checkif unit is in FPC source directory

git-svn-id: trunk@33792 -
This commit is contained in:
mattias 2011-11-26 03:01:23 +00:00
parent ac1cc4103f
commit 12ad33ebb0

View File

@ -47,9 +47,11 @@ uses
Graphics, Dialogs, ButtonPanel, StdCtrls, ExtCtrls, LCLType, Graphics, Dialogs, ButtonPanel, StdCtrls, ExtCtrls, LCLType,
PackageIntf, LazIDEIntf, SrcEditorIntf, ProjectIntf, PackageIntf, LazIDEIntf, SrcEditorIntf, ProjectIntf,
CodeCache, BasicCodeTools, CustomCodeTool, CodeToolManager, UnitDictionary, CodeCache, BasicCodeTools, CustomCodeTool, CodeToolManager, UnitDictionary,
CodeTree, LinkScanner, CodeTree, LinkScanner, DefineTemplates,
CodyStrConsts, CodyUtils; CodyStrConsts, CodyUtils;
const
PackageNameFPCSrcDir = 'FPCSrcDir';
type type
TCodyUnitDictionary = class; TCodyUnitDictionary = class;
@ -140,6 +142,7 @@ type
procedure GetCurOwnerOfUnit; procedure GetCurOwnerOfUnit;
procedure AddToUsesSection; procedure AddToUsesSection;
procedure UpdateTool; procedure UpdateTool;
function GetFPCSrcDir(const Directory: string): string;
public public
CurIdentifier: string; CurIdentifier: string;
CurIdentStart: integer; CurIdentStart: integer;
@ -282,6 +285,7 @@ var
UDGroup: TUDUnitGroup; UDGroup: TUDUnitGroup;
ok: Boolean; ok: Boolean;
OldChangeStamp: Int64; OldChangeStamp: Int64;
UnitSet: TFPCUnitSetCache;
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
@ -325,6 +329,23 @@ begin
EndCritSec; EndCritSec;
end; end;
end; end;
// check if in FPC source directory
UnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
if (UnitSet<>nil) and (UnitSet.FPCSourceDirectory<>'')
and FileIsInPath(fParsingTool.MainFilename,UnitSet.FPCSourceDirectory)
then begin
BeginCritSec;
try
UDGroup:=AddUnitGroup(
AppendPathDelim(UnitSet.FPCSourceDirectory)+PackageNameFPCSrcDir+'.lpk',
PackageNameFPCSrcDir);
UDGroup.AddUnit(UDUnit);
finally
EndCritSec;
end;
end;
if ChangeStamp<>OldChangeStamp then begin if ChangeStamp<>OldChangeStamp then begin
if fTimer=nil then begin if fTimer=nil then begin
fTimer:=TTimer.Create(nil); fTimer:=TTimer.Create(nil);
@ -591,6 +612,9 @@ var
Found: Integer; Found: Integer;
GroupNode: TAVLTreeNode; GroupNode: TAVLTreeNode;
Group: TUDUnitGroup; Group: TUDUnitGroup;
FPCSrcDir: String;
Dir: String;
UseGroup: Boolean;
begin begin
Filter:=GetFilterEditText; Filter:=GetFilterEditText;
FilterP:=PChar(Filter); FilterP:=PChar(Filter);
@ -598,6 +622,7 @@ begin
sl:=TStringList.Create; sl:=TStringList.Create;
try try
Found:=0; Found:=0;
FPCSrcDir:=ChompPathDelim(GetFPCSrcDir(''));
Node:=CodyUnitDictionary.Identifiers.FindLowest; Node:=CodyUnitDictionary.Identifiers.FindLowest;
//debugln(['TCodyIdentifiersDlg.UpdateItemsList Filter="',Filter,'"']); //debugln(['TCodyIdentifiersDlg.UpdateItemsList Filter="',Filter,'"']);
while Node<>nil do begin while Node<>nil do begin
@ -606,21 +631,32 @@ begin
inc(Found); inc(Found);
if Found<MaxItems then begin if Found<MaxItems then begin
Item:=TUDIdentifier(Node.Data); Item:=TUDIdentifier(Node.Data);
if FileExistsCached(Item.DUnit.Filename) then begin
GroupNode:=Item.DUnit.UnitGroups.FindLowest; GroupNode:=Item.DUnit.UnitGroups.FindLowest;
while GroupNode<>nil do begin while GroupNode<>nil do begin
Group:=TUDUnitGroup(GroupNode.Data); Group:=TUDUnitGroup(GroupNode.Data);
if (Group.Filename='') UseGroup:=false;
or (FileExistsCached(Group.Filename)) then begin if Group.Name='' then begin
s:=Item.Name+' in '+Item.DUnit.Name; // it's a unit without package
if Group.Name<>'' then begin UseGroup:=true
s:=s+' of '+Group.Name; end else if Group.Name=PackageNameFPCSrcDir then begin
// it's a FPC source directory
// => check if it is the current one
Dir:=ExtractFilePath(Group.Filename);
UseGroup:=CompareFilenames(Dir,FPCSrcDir)=0;
end else if FileExistsCached(Group.Filename) then begin
// lpk exists
UseGroup:=true;
end; end;
if UseGroup then begin
s:=Item.Name+' in '+Item.DUnit.Name;
if Group.Name<>'' then
s:=s+' of '+Group.Name;
if FileExistsCached(Item.DUnit.Filename) then begin
FItems.Add(Item.Name+#10+Item.DUnit.Filename+#10+Group.Filename); FItems.Add(Item.Name+#10+Item.DUnit.Filename+#10+Group.Filename);
sl.Add(s); sl.Add(s);
end; end;
GroupNode:=Item.DUnit.UnitGroups.FindSuccessor(GroupNode);
end; end;
GroupNode:=Item.DUnit.UnitGroups.FindSuccessor(GroupNode);
end; end;
end; end;
end; end;
@ -822,6 +858,16 @@ begin
CurNode:=CurTool.FindDeepestNodeAtPos(CurCleanPos,false); CurNode:=CurTool.FindDeepestNodeAtPos(CurCleanPos,false);
end; end;
function TCodyIdentifiersDlg.GetFPCSrcDir(const Directory: string): string;
var
UnitSet: TFPCUnitSetCache;
begin
Result:='';
UnitSet:=CodeToolBoss.GetUnitSetForDirectory(Directory);
if (UnitSet<>nil) then
Result:=ChompPathDelim(UnitSet.FPCSourceDirectory);
end;
finalization finalization
FreeAndNil(CodyUnitDictionary); FreeAndNil(CodyUnitDictionary);