IDE: started searching in fpdoc files

git-svn-id: trunk@15964 -
This commit is contained in:
mattias 2008-08-05 21:51:30 +00:00
parent 6366cefff6
commit a261ea868b
8 changed files with 129 additions and 43 deletions

View File

@ -856,7 +856,7 @@ begin
if Root=nil then exit;
ANode:=Root;
while (ANode.NextBrother<>nil) do ANode:=ANode.NextBrother;
debugln('TCodeTree.FindLastPosition A ',Anode.DescAsString,' ANode.StartPos=',dbgs(ANode.StartPos),' ANode.EndPos=',dbgs(ANode.EndPos));
//debugln('TCodeTree.FindLastPosition A ',Anode.DescAsString,' ANode.StartPos=',dbgs(ANode.StartPos),' ANode.EndPos=',dbgs(ANode.EndPos));
Result:=ANode.EndPos;
end;

View File

@ -3586,7 +3586,7 @@ var
and ((not IsComment)
or ((not SkipComments) and UnitStartFound))
then begin
debugln('Identifier with same name found at: ',
{debugln('Identifier with same name found at: ',
dbgs(StartPos),' ',GetIdentifier(@Src[StartPos]),
' CleanDeclCursorPos=',dbgs(CleanDeclCursorPos),
' MaxPos='+dbgs(MaxPos),
@ -3594,10 +3594,10 @@ var
' SkipComments='+dbgs(SkipComments),
' UnitStartFound='+dbgs(UnitStartFound));
if CleanPosToCaret(StartPos,ReferencePos) then
debugln(' x=',dbgs(ReferencePos.X),' y=',dbgs(ReferencePos.Y),' ',ReferencePos.Code.Filename);
debugln(' x=',dbgs(ReferencePos.X),' y=',dbgs(ReferencePos.Y),' ',ReferencePos.Code.Filename);}
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(StartPos,true);
debugln(' CursorNode=',CursorNode.DescAsString,' Forward=',dbgs(CursorNode.SubDesc and ctnsForwardDeclaration));
//debugln(' CursorNode=',CursorNode.DescAsString,' Forward=',dbgs(CursorNode.SubDesc and ctnsForwardDeclaration));
if (DeclarationTool=Self)
and ((StartPos=CleanDeclCursorPos) or (CursorNode=AliasDeclarationNode))
@ -3615,7 +3615,7 @@ var
Params.Flags:=[fdfSearchInParentNodes,fdfSearchInAncestors,
fdfExceptionOnNotFound,fdfIgnoreCurContextNode];
if NodeIsForwardDeclaration(CursorNode) then begin
debugln('Node is forward declaration');
//debugln('Node is forward declaration');
Params.Flags:=Params.Flags+[fdfSearchForward];
end;
Params.ContextNode:=CursorNode;
@ -3636,7 +3636,7 @@ var
raise;
end;
debugln(' Found=',dbgs(Found));
//debugln(' Found=',dbgs(Found));
if Found and (Params.NewNode<>nil) then begin
if (Params.NewNode.Desc=ctnProcedure)
and (Params.NewNode.FirstChild<>nil)
@ -3647,7 +3647,7 @@ var
Params.NewCodeTool.MoveCursorToProcName(Params.NewNode,true);
Params.NewCleanPos:=Params.NewCodeTool.CurPos.StartPos;
end;
debugln('Context=',Params.NewNode.DescAsString,' ',dbgs(Params.NewNode.StartPos),' ',dbgs(DeclarationNode.StartPos));
//debugln('Context=',Params.NewNode.DescAsString,' ',dbgs(Params.NewNode.StartPos),' ',dbgs(DeclarationNode.StartPos));
if (Params.NewNode=DeclarationNode)
or (Params.NewNode=AliasDeclarationNode) then
AddReference;
@ -3797,7 +3797,7 @@ var
end;
// find alias declaration node
debugln('FindDeclarationNode DeclarationNode=',DeclarationNode.DescAsString);
//debugln('FindDeclarationNode DeclarationNode=',DeclarationNode.DescAsString);
AliasDeclarationNode:=nil;
case DeclarationNode.Desc of
@ -3837,7 +3837,7 @@ var
and (AliasDeclarationNode.FirstChild.Desc=ctnProcedureHead) then
AliasDeclarationNode:=AliasDeclarationNode.FirstChild;
if AliasDeclarationNode<>nil then begin
debugln('FindDeclarationNode AliasDeclarationNode=',AliasDeclarationNode.DescAsString);
//debugln('FindDeclarationNode AliasDeclarationNode=',AliasDeclarationNode.DescAsString);
end;
Result:=true;
@ -3845,7 +3845,7 @@ var
begin
Result:=false;
debugln('FindReferences CursorPos=',CursorPos.Code.Filename,' x=',dbgs(CursorPos.X),' y=',dbgs(CursorPos.Y),' SkipComments=',dbgs(SkipComments));
//debugln('FindReferences CursorPos=',CursorPos.Code.Filename,' x=',dbgs(CursorPos.X),' y=',dbgs(CursorPos.Y),' SkipComments=',dbgs(SkipComments));
ListOfPCodeXYPosition:=nil;
Params:=nil;

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<CONFIG>
<Package Version="2">
<Package Version="3">
<Name Value="RunTimeTypeInfoControls"/>
<Author Value="Mattias Gaertner"/>
<CompilerOptions>
@ -37,6 +37,7 @@
<Type Value="LRS"/>
</Item3>
</Files>
<LazDoc Paths="/home/mattias/pascal/wichtig/lazarus/components/rtticontrols/fpdoc/"/>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="3">
<Item1>

View File

@ -208,6 +208,9 @@ type
out CacheWasUsed: boolean;
out AnOwner: TObject;// package or project
CreateIfNotExists: boolean = false): string;
procedure GetFPDocFilenamesForSources(SrcFilenames: TStringToStringTree;
ResolveIncludeFiles: boolean;
var FPDocFilenames: TStringToStringTree);
function FindModuleOwner(const Modulename: string): TObject;
function GetOwnerModuleName(TheOwner: TObject): string;
function ExpandFPDocLinkID(const LinkID, DefaultUnitName,
@ -1248,6 +1251,33 @@ begin
end;
end;
procedure TCodeHelpManager.GetFPDocFilenamesForSources(
SrcFilenames: TStringToStringTree; ResolveIncludeFiles: boolean;
var FPDocFilenames: TStringToStringTree);
var
Node: TAvgLvlTreeNode;
Item: PStringToStringItem;
SrcFilename: String;
CacheWasUsed: boolean;
AnOwner: TObject;
FPDocFilename: String;
begin
Node:=SrcFilenames.Tree.FindLowest;
while Node<>nil do begin
Item:=PStringToStringItem(Node.Data);
SrcFilename:=Item^.Name;
FPDocFilename:=GetFPDocFilenameForSource(SrcFilename,ResolveIncludeFiles,
CacheWasUsed,AnOwner);
//DebugLn(['TCodeHelpManager.GetFPDocFilenamesForSources FPDoc=',FPDocFilename,' Src=',SrcFilename]);
if FPDocFilename<>'' then begin
if FPDocFilenames=nil then
FPDocFilenames:=CreateFilenameToStringTree;
FPDocFilenames[FPDocFilename]:=SrcFilename;
end;
Node:=SrcFilenames.Tree.FindSuccessor(Node);
end;
end;
function TCodeHelpManager.FindModuleOwner(const Modulename: string): TObject;
var
AProject: TLazProject;

View File

@ -31,7 +31,7 @@ interface
uses
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls,
StdCtrls, Buttons, ExtCtrls, AvgLvlTree,
// codetools
AVL_Tree, CodeAtom, CodeCache, CodeToolManager,
// IDE
@ -272,27 +272,23 @@ function GatherFPDocReferences(PascalFiles: TStringList;
DeclarationCode: TCodeBuffer; const DeclarationCaretXY: TPoint;
var TreeOfPCodeXYPosition: TAVLTree): TModalResult;
var
i: Integer;
PascalFilename: string;
Filename: string;
CurOwner: TObject;
CacheWasUsed: boolean;
PascalFilenames, FPDocFilenames: TStringToStringTree;
begin
Result:=mrCancel;
TreeOfPCodeXYPosition:=nil;
PascalFilenames:=nil;
FPDocFilenames:=nil;
try
CleanUpFileList(PascalFiles);
// search fpdoc files
for i:=0 to PascalFiles.Count-1 do begin
PascalFilename:=PascalFiles[i];
Filename:=CodeHelpBoss.GetFPDocFilenameForSource(PascalFilename,true,
CacheWasUsed,CurOwner);
if Filename='' then continue;
end;
PascalFilenames:=CreateFilenameToStringTree;
PascalFilenames.AddValues(PascalFiles);
CodeHelpBoss.GetFPDocFilenamesForSources(PascalFilenames,true,FPDocFilenames);
Result:=mrOk;
finally
PascalFilenames.Free;
FPDocFilenames.Free;
if Result<>mrOk then
CodeToolBoss.FreeTreeOfPCodeXYPosition(TreeOfPCodeXYPosition);
end;

View File

@ -232,6 +232,11 @@ procedure FreeListObjects(List: TList; FreeList: boolean);
procedure FreeListObjects(List: TFPList; FreeList: boolean);
function CompareMemStreamText(s1, s2: TMemoryStream): Boolean;
function CompareStringToStringItemsFilename(Data1, Data2: Pointer): integer;
function ComparePAnsiStringWithStrToStrItemFilename(Key, Data: Pointer): Integer;
function CreateFilenameToStringTree: TStringToStringTree;
implementation
@ -2588,6 +2593,23 @@ begin
end;
end;
function CompareStringToStringItemsFilename(Data1, Data2: Pointer): integer;
begin
Result:=CompareFilenames(PStringToStringItem(Data1)^.Name,
PStringToStringItem(Data2)^.Name);
end;
function ComparePAnsiStringWithStrToStrItemFilename(Key, Data: Pointer
): Integer;
begin
Result:=CompareFilenames(PAnsiString(Key)^,PStringToStringItem(Data)^.Name);
end;
function CreateFilenameToStringTree: TStringToStringTree;
begin
Result:=TStringToStringTree.Create(@CompareStringToStringItemsFilename,
@ComparePAnsiStringWithStrToStrItemFilename);
end;
end.

View File

@ -12282,7 +12282,7 @@ var
ExtraFiles: TStrings;
Files: TStringList;
Identifier: string;
TreeOfPCodeXYPosition: TAVLTree;
PascalReferences, FPDocReferences: TAVLTree;
begin
Result:=mrCancel;
if not BeginCodeTool(TargetSrcEdit,TargetUnitInfo,[]) then exit;
@ -12314,7 +12314,8 @@ begin
Files:=nil;
OwnerList:=nil;
TreeOfPCodeXYPosition:=nil;
PascalReferences:=nil;
FPDocReferences:=nil;
try
// create the file list
Files:=TStringList.Create;
@ -12363,30 +12364,39 @@ begin
// search pascal source references
Result:=GatherIdentifierReferences(Files,DeclarationUnitInfo.Source,
DeclarationCaretXY,Options.SearchInComments,TreeOfPCodeXYPosition);
DeclarationCaretXY,Options.SearchInComments,PascalReferences);
if CodeToolBoss.ErrorMessage<>'' then
DoJumpToCodeToolBossError;
if Result<>mrOk then begin
debugln('TMainIDE.DoFindRenameIdentifier unable to gather identifiers');
debugln('TMainIDE.DoFindRenameIdentifier GatherIdentifierReferences failed');
exit;
end;
// ToDo: designer references
// ToDo: search lfm source references
{$IFDEF EnableFPDocRename}
// ToDo: search fpdoc references
Result:=GatherFPDocReferences(Files,DeclarationUnitInfo.Source,
DeclarationCaretXY,FPDocReferences);
if Result<>mrOk then begin
debugln('TMainIDE.DoFindRenameIdentifier GatherFPDocReferences failed');
exit;
end;
{$ENDIF}
// ToDo: search lfm source references
// ToDo: search i18n references
// ToDo: designer references
// show result
if (not Options.Rename) or (not Rename) then begin
CreateSearchResultWindow;
Result:=ShowIdentifierReferences(DeclarationUnitInfo.Source,
DeclarationCaretXY,TreeOfPCodeXYPosition);
DeclarationCaretXY,PascalReferences);
if Result<>mrOk then exit;
end;
// rename identifier
if Options.Rename and Rename then begin
if not CodeToolBoss.RenameIdentifier(TreeOfPCodeXYPosition,
if not CodeToolBoss.RenameIdentifier(PascalReferences,
Identifier,Options.RenameTo)
then begin
DoJumpToCodeToolBossError;
@ -12399,7 +12409,8 @@ begin
finally
Files.Free;
OwnerList.Free;
CodeToolBoss.FreeTreeOfPCodeXYPosition(TreeOfPCodeXYPosition);
CodeToolBoss.FreeTreeOfPCodeXYPosition(FPDocReferences);
CodeToolBoss.FreeTreeOfPCodeXYPosition(PascalReferences);
end;
end;

View File

@ -177,8 +177,9 @@ type
TStringToStringTree = class
private
FCompareItems: TListSortCompare;
FCompareNameWithItem: TListSortCompare;
FItems: TAvgLvlTree;
fCaseSensitive: Boolean;
function GetCount: Integer;
function GetValues(const Name: string): string;
procedure SetValues(const Name: string; const AValue: string);
@ -186,10 +187,13 @@ type
function GetNode(Node: TAvgLvlTreeNode; out Name, Value: string): Boolean;
public
constructor Create(CaseSensitive: boolean);
constructor Create(const ACompareItems, ACompareNameWithItem: TListSortCompare);
destructor Destroy; override;
procedure Clear;
function Contains(const Name: string): Boolean;
procedure Add(const Name, Value, Delimiter: string);
procedure AddNameValues(List: TStrings);
procedure AddValues(List: TStrings);
function GetFirst(out Name, Value: string): Boolean;
function GetLast(out Name, Value: string): Boolean;
function GetNext(const Name: string; out NextName, NextValue: string): Boolean;
@ -197,11 +201,13 @@ type
property Count: Integer read GetCount;
property Values[const Name: string]: string read GetValues write SetValues; default;
property Tree: TAvgLvlTree read FItems;
property CompareItems: TListSortCompare read FCompareItems;
property CompareNameWithItem: TListSortCompare read FCompareNameWithItem;
end;
function CompareStringToStringItems(Data1, Data2: Pointer): integer;
function CompareStringToStringItemsI(Data1, Data2: Pointer): integer;
function ComparePAnsiStringWithStrToStrItem(Key, Data: Pointer): Integer;
function CompareStringToStringItemsI(Data1, Data2: Pointer): integer;
function ComparePAnsiStringWithStrToStrItemI(Key, Data: Pointer): Integer;
@ -1362,10 +1368,7 @@ end;
function TStringToStringTree.FindNode(const Name: string): TAvgLvlTreeNode;
begin
if fCaseSensitive then
Result:=FItems.FindKey(@Name,@ComparePAnsiStringWithStrToStrItem)
else
Result:=FItems.FindKey(@Name,@ComparePAnsiStringWithStrToStrItemI)
Result:=FItems.FindKey(@Name,FCompareNameWithItem);
end;
function TStringToStringTree.GetNode(Node: TAvgLvlTreeNode;
@ -1387,11 +1390,18 @@ end;
constructor TStringToStringTree.Create(CaseSensitive: boolean);
begin
fCaseSensitive:=CaseSensitive;
if fCaseSensitive then
FItems:=TAvgLvlTree.Create(@CompareStringToStringItems)
if CaseSensitive then
Create(@CompareStringToStringItems,@ComparePAnsiStringWithStrToStrItem)
else
FItems:=TAvgLvlTree.Create(@CompareStringToStringItemsI);
Create(@CompareStringToStringItemsI,@ComparePAnsiStringWithStrToStrItemI);
end;
constructor TStringToStringTree.Create(const ACompareItems,
ACompareNameWithItem: TListSortCompare);
begin
FCompareItems:=ACompareItems;
FCompareNameWithItem:=ACompareNameWithItem;
FItems:=TAvgLvlTree.Create(FCompareItems);
end;
destructor TStringToStringTree.Destroy;
@ -1431,6 +1441,22 @@ begin
Values[Name]:=OldValue;
end;
procedure TStringToStringTree.AddNameValues(List: TStrings);
var
i: Integer;
begin
for i:=0 to List.Count-1 do
Values[List.Names[i]]:=List.ValueFromIndex[i];
end;
procedure TStringToStringTree.AddValues(List: TStrings);
var
i: Integer;
begin
for i:=0 to List.Count-1 do
Values[List[i]]:='';
end;
function TStringToStringTree.GetFirst(out Name, Value: string): Boolean;
begin
Result:=GetNode(Tree.FindLowest,Name,Value);