mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 07:55:58 +02:00
ident compl: added sorting, ignoring redefinitions, brackets, properties
git-svn-id: trunk@3767 -
This commit is contained in:
parent
a0bcf62aa6
commit
05fd8f14d1
@ -139,6 +139,8 @@ const
|
|||||||
[ctnProgram,ctnPackage,ctnLibrary,ctnUnit];
|
[ctnProgram,ctnPackage,ctnLibrary,ctnUnit];
|
||||||
AllUsableSourceTypes =
|
AllUsableSourceTypes =
|
||||||
[ctnUnit];
|
[ctnUnit];
|
||||||
|
AllFindContextDescs = AllIdentifierDefinitions +
|
||||||
|
[ctnClass,ctnClassInterface,ctnProcedure];
|
||||||
|
|
||||||
|
|
||||||
// CodeTreeNodeSubDescriptors
|
// CodeTreeNodeSubDescriptors
|
||||||
@ -180,6 +182,7 @@ type
|
|||||||
function HasAsChild(Node: TCodeTreeNode): boolean;
|
function HasAsChild(Node: TCodeTreeNode): boolean;
|
||||||
function HasParentOfType(ParentDesc: TCodeTreeNodeDesc): boolean;
|
function HasParentOfType(ParentDesc: TCodeTreeNodeDesc): boolean;
|
||||||
function GetNodeOfType(ADesc: TCodeTreeNodeDesc): TCodeTreeNode;
|
function GetNodeOfType(ADesc: TCodeTreeNodeDesc): TCodeTreeNode;
|
||||||
|
function GetFindContextParent: TCodeTreeNode;
|
||||||
function GetLevel: integer;
|
function GetLevel: integer;
|
||||||
function DescAsString: string;
|
function DescAsString: string;
|
||||||
function GetRoot: TCodeTreeNode;
|
function GetRoot: TCodeTreeNode;
|
||||||
@ -481,6 +484,13 @@ begin
|
|||||||
Result:=Result.Parent;
|
Result:=Result.Parent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeTreeNode.GetFindContextParent: TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
Result:=Parent;
|
||||||
|
while (Result<>nil) and (not (Result.Desc in AllFindContextDescs)) do
|
||||||
|
Result:=Result.Parent;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeTreeNode.GetLevel: integer;
|
function TCodeTreeNode.GetLevel: integer;
|
||||||
var ANode: TCodeTreeNode;
|
var ANode: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
|
@ -75,6 +75,10 @@ type
|
|||||||
TIdentifierCompatibilities = set of TIdentifierCompatibility;
|
TIdentifierCompatibilities = set of TIdentifierCompatibility;
|
||||||
|
|
||||||
TIdentifierListItem = class
|
TIdentifierListItem = class
|
||||||
|
private
|
||||||
|
FParamList: string;
|
||||||
|
FParamListValid: boolean;
|
||||||
|
function GetParamList: string;
|
||||||
public
|
public
|
||||||
Compatibility: TIdentifierCompatibility;
|
Compatibility: TIdentifierCompatibility;
|
||||||
HasChilds: boolean; // identifier can contain childs (class, record)
|
HasChilds: boolean; // identifier can contain childs (class, record)
|
||||||
@ -84,6 +88,7 @@ type
|
|||||||
Node: TCodeTreeNode;
|
Node: TCodeTreeNode;
|
||||||
Tool: TFindDeclarationTool;
|
Tool: TFindDeclarationTool;
|
||||||
function AsString: string;
|
function AsString: string;
|
||||||
|
property ParamList: string read GetParamList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TIdentifierListFlag = (ilfFilteredListNeedsUpdate);
|
TIdentifierListFlag = (ilfFilteredListNeedsUpdate);
|
||||||
@ -94,7 +99,8 @@ type
|
|||||||
FFilteredList: TList;
|
FFilteredList: TList;
|
||||||
FFlags: TIdentifierListFlags;
|
FFlags: TIdentifierListFlags;
|
||||||
FHistory: TIdentifierHistoryList;
|
FHistory: TIdentifierHistoryList;
|
||||||
FItems: TAVLTree; // tree of TIdentifierListItem
|
FItems: TAVLTree; // tree of TIdentifierListItem (completely sorted)
|
||||||
|
FIdentView: TAVLTree; // tree of TIdentHistListItem sorted for identifiers
|
||||||
FPrefix: string;
|
FPrefix: string;
|
||||||
procedure SetHistory(const AValue: TIdentifierHistoryList);
|
procedure SetHistory(const AValue: TIdentifierHistoryList);
|
||||||
procedure UpdateFilteredList;
|
procedure UpdateFilteredList;
|
||||||
@ -205,7 +211,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// then sort alpabetically (lower is better)
|
// then sort alpabetically (lower is better)
|
||||||
Result:=CompareIdentifiers(Item1.Identifier,Item2.Identifier);
|
Result:=CompareIdentifiers(Item2.Identifier,Item1.Identifier);
|
||||||
|
if Result<>0 then exit;
|
||||||
|
|
||||||
|
// then sort for ParamList (lower is better)
|
||||||
|
Result:=AnsiCompareText(Item2.ParamList,Item1.ParamList);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CompareIdentListItemsForIdents(Data1, Data2: Pointer): integer;
|
||||||
|
var
|
||||||
|
Item1: TIdentifierListItem;
|
||||||
|
Item2: TIdentifierListItem;
|
||||||
|
begin
|
||||||
|
Item1:=TIdentifierListItem(Data1);
|
||||||
|
Item2:=TIdentifierListItem(Data2);
|
||||||
|
|
||||||
|
// sort alpabetically (lower is better)
|
||||||
|
Result:=CompareIdentifiers(Item2.Identifier,Item1.Identifier);
|
||||||
|
if Result<>0 then exit;
|
||||||
|
|
||||||
|
// then sort for ParamList (lower is better)
|
||||||
|
Result:=AnsiCompareText(Item2.ParamList,Item1.ParamList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareIdentHistListItem(Data1, Data2: Pointer): integer;
|
function CompareIdentHistListItem(Data1, Data2: Pointer): integer;
|
||||||
@ -216,37 +242,24 @@ begin
|
|||||||
Item1:=TIdentHistListItem(Data1);
|
Item1:=TIdentHistListItem(Data1);
|
||||||
Item2:=TIdentHistListItem(Data2);
|
Item2:=TIdentHistListItem(Data2);
|
||||||
|
|
||||||
Result:=CompareIdentifiers(PChar(Item1.Identifier),PChar(Item2.Identifier));
|
Result:=CompareIdentifiers(PChar(Item2.Identifier),PChar(Item1.Identifier));
|
||||||
if Result<>0 then exit;
|
if Result<>0 then exit;
|
||||||
|
|
||||||
Result:=CompareIdentifiers(PChar(Item1.ParamList),PChar(Item2.ParamList));
|
Result:=CompareIdentifiers(PChar(Item2.ParamList),PChar(Item1.ParamList));
|
||||||
end;
|
|
||||||
|
|
||||||
function GetParamList(IdentItem: TIdentifierListItem): string;
|
|
||||||
begin
|
|
||||||
Result:='';
|
|
||||||
case IdentItem.Node.Desc of
|
|
||||||
ctnProcedure:
|
|
||||||
Result:=IdentItem.Tool.ExtractProcHead(IdentItem.Node,
|
|
||||||
[phpWithoutClassKeyword,phpWithoutClassName,phpWithoutName,phpInUpperCase]);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareIdentItemWithHistListItem(Data1, Data2: Pointer): integer;
|
function CompareIdentItemWithHistListItem(Data1, Data2: Pointer): integer;
|
||||||
var
|
var
|
||||||
IdentItem: TIdentifierListItem;
|
IdentItem: TIdentifierListItem;
|
||||||
HistItem: TIdentHistListItem;
|
HistItem: TIdentHistListItem;
|
||||||
ParamList: String;
|
|
||||||
begin
|
begin
|
||||||
IdentItem:=TIdentifierListItem(Data1);
|
IdentItem:=TIdentifierListItem(Data1);
|
||||||
HistItem:=TIdentHistListItem(Data2);
|
HistItem:=TIdentHistListItem(Data2);
|
||||||
|
|
||||||
Result:=CompareIdentifiers(IdentItem.Identifier,PChar(HistItem.Identifier));
|
Result:=CompareIdentifiers(PChar(HistItem.Identifier),IdentItem.Identifier);
|
||||||
if Result<>0 then exit;
|
if Result<>0 then exit;
|
||||||
|
|
||||||
ParamList:=GetParamList(IdentItem);
|
Result:=AnsiCompareText(HistItem.ParamList,IdentItem.ParamList);
|
||||||
if (ParamList<>'') then
|
|
||||||
Result:=AnsiCompareText(ParamList,HistItem.ParamList);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIdentifierList }
|
{ TIdentifierList }
|
||||||
@ -303,12 +316,14 @@ constructor TIdentifierList.Create;
|
|||||||
begin
|
begin
|
||||||
FFlags:=[ilfFilteredListNeedsUpdate];
|
FFlags:=[ilfFilteredListNeedsUpdate];
|
||||||
FItems:=TAVLTree.Create(@CompareIdentListItems);
|
FItems:=TAVLTree.Create(@CompareIdentListItems);
|
||||||
|
FIdentView:=TAVLTree.Create(@CompareIdentListItemsForIdents);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TIdentifierList.Destroy;
|
destructor TIdentifierList.Destroy;
|
||||||
begin
|
begin
|
||||||
Clear;
|
Clear;
|
||||||
FItems.Free;
|
FItems.Free;
|
||||||
|
FIdentView.Free;
|
||||||
FFilteredList.Free;
|
FFilteredList.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
@ -316,15 +331,25 @@ end;
|
|||||||
procedure TIdentifierList.Clear;
|
procedure TIdentifierList.Clear;
|
||||||
begin
|
begin
|
||||||
FItems.FreeAndClear;
|
FItems.FreeAndClear;
|
||||||
|
FIdentView.Clear;
|
||||||
Include(FFlags,ilfFilteredListNeedsUpdate);
|
Include(FFlags,ilfFilteredListNeedsUpdate);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIdentifierList.Add(NewItem: TIdentifierListItem);
|
procedure TIdentifierList.Add(NewItem: TIdentifierListItem);
|
||||||
|
var
|
||||||
|
AnAVLNode: TAVLTreeNode;
|
||||||
begin
|
begin
|
||||||
if History<>nil then
|
AnAVLNode:=FIdentView.FindKey(NewItem,@CompareIdentListItemsForIdents);
|
||||||
NewItem.HistoryIndex:=History.GetHistoryIndex(NewItem);
|
if AnAVLNode=nil then begin
|
||||||
FItems.Add(NewItem);
|
if History<>nil then
|
||||||
Include(FFlags,ilfFilteredListNeedsUpdate);
|
NewItem.HistoryIndex:=History.GetHistoryIndex(NewItem);
|
||||||
|
FItems.Add(NewItem);
|
||||||
|
FIdentView.Add(NewItem);
|
||||||
|
Include(FFlags,ilfFilteredListNeedsUpdate);
|
||||||
|
end else begin
|
||||||
|
// redefined identifier -> ignore
|
||||||
|
NewItem.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIdentifierList.Count: integer;
|
function TIdentifierList.Count: integer;
|
||||||
@ -346,6 +371,7 @@ function TIdentCompletionTool.CollectAllIdentifiers(
|
|||||||
var
|
var
|
||||||
NewItem: TIdentifierListItem;
|
NewItem: TIdentifierListItem;
|
||||||
Ident: PChar;
|
Ident: PChar;
|
||||||
|
CurContextParent: TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
// proceed searching ...
|
// proceed searching ...
|
||||||
Result:=ifrProceedSearch;
|
Result:=ifrProceedSearch;
|
||||||
@ -355,10 +381,11 @@ begin
|
|||||||
' "',StringToPascalConst(copy(FoundContext.Tool.Src,FoundContext.Node.StartPos,50)),'"'
|
' "',StringToPascalConst(copy(FoundContext.Tool.Src,FoundContext.Node.StartPos,50)),'"'
|
||||||
,' ',fdfIgnoreUsedUnits in Params.Flags);
|
,' ',fdfIgnoreUsedUnits in Params.Flags);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
if LastGatheredIdentParent<>FoundContext.Node.Parent then begin
|
CurContextParent:=FoundContext.Node.GetFindContextParent;
|
||||||
|
if LastGatheredIdentParent<>CurContextParent then begin
|
||||||
// new context level
|
// new context level
|
||||||
LastGatheredIdentParent:=FoundContext.Node.Parent;
|
LastGatheredIdentParent:=CurContextParent;
|
||||||
inc(LastGatheredIdentLevel);
|
inc(LastGatheredIdentLevel);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -506,6 +533,18 @@ end;
|
|||||||
|
|
||||||
{ TIdentifierListItem }
|
{ TIdentifierListItem }
|
||||||
|
|
||||||
|
function TIdentifierListItem.GetParamList: string;
|
||||||
|
begin
|
||||||
|
if not FParamListValid then begin
|
||||||
|
if Node.Desc=ctnProcedure then
|
||||||
|
FParamList:=Tool.ExtractProcHead(Node,
|
||||||
|
[phpWithoutClassKeyword,phpWithoutClassName,
|
||||||
|
phpWithoutName,phpInUpperCase]);
|
||||||
|
FParamListValid:=true;
|
||||||
|
end;
|
||||||
|
Result:=FParamList;
|
||||||
|
end;
|
||||||
|
|
||||||
function TIdentifierListItem.AsString: string;
|
function TIdentifierListItem.AsString: string;
|
||||||
begin
|
begin
|
||||||
Result:=IdentifierCompatibilityNames[Compatibility];
|
Result:=IdentifierCompatibilityNames[Compatibility];
|
||||||
@ -585,7 +624,7 @@ begin
|
|||||||
NewHistItem:=TIdentHistListItem.Create;
|
NewHistItem:=TIdentHistListItem.Create;
|
||||||
NewHistItem.Identifier:=GetIdentifier(NewItem.Identifier);
|
NewHistItem.Identifier:=GetIdentifier(NewItem.Identifier);
|
||||||
NewHistItem.NodeDesc:=NewItem.Node.Desc;
|
NewHistItem.NodeDesc:=NewItem.Node.Desc;
|
||||||
NewHistItem.ParamList:=GetParamList(NewItem);
|
NewHistItem.ParamList:=NewItem.ParamList;
|
||||||
AdjustIndex:=0;
|
AdjustIndex:=0;
|
||||||
end;
|
end;
|
||||||
NewHistItem.HistoryIndex:=0;
|
NewHistItem.HistoryIndex:=0;
|
||||||
|
@ -205,6 +205,8 @@ type
|
|||||||
InUpperCase: boolean): string;
|
InUpperCase: boolean): string;
|
||||||
function ExtractPropType(PropNode: TCodeTreeNode;
|
function ExtractPropType(PropNode: TCodeTreeNode;
|
||||||
InUpperCase, EmptyIfIndexed: boolean): string;
|
InUpperCase, EmptyIfIndexed: boolean): string;
|
||||||
|
function ExtractProperty(PropNode: TCodeTreeNode;
|
||||||
|
Attr: TProcHeadAttributes): string;
|
||||||
function ExtractProcName(ProcNode: TCodeTreeNode;
|
function ExtractProcName(ProcNode: TCodeTreeNode;
|
||||||
Attr: TProcHeadAttributes): string;
|
Attr: TProcHeadAttributes): string;
|
||||||
function ExtractProcHead(ProcNode: TCodeTreeNode;
|
function ExtractProcHead(ProcNode: TCodeTreeNode;
|
||||||
@ -3202,6 +3204,39 @@ begin
|
|||||||
Result:=GetAtom;
|
Result:=GetAtom;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPascalParserTool.ExtractProperty(PropNode: TCodeTreeNode;
|
||||||
|
Attr: TProcHeadAttributes): string;
|
||||||
|
begin
|
||||||
|
Result:='';
|
||||||
|
ExtractProcHeadPos:=phepNone;
|
||||||
|
if (PropNode=nil) or (PropNode.StartPos<1) or (PropNode.Desc<>ctnProperty)
|
||||||
|
then exit;
|
||||||
|
// start extraction
|
||||||
|
InitExtraction;
|
||||||
|
MoveCursorToNodeStart(PropNode);
|
||||||
|
ExtractNextAtom(false,Attr);
|
||||||
|
// parse 'property'
|
||||||
|
ExtractNextAtom(phpWithStart in Attr,Attr);
|
||||||
|
ExtractProcHeadPos:=phepStart;
|
||||||
|
// parse name
|
||||||
|
ExtractNextAtom(not (phpWithoutName in Attr),Attr);
|
||||||
|
ExtractProcHeadPos:=phepName;
|
||||||
|
// read parameter list
|
||||||
|
if (CurPos.Flag=cafEdgedBracketOpen) then
|
||||||
|
ReadParamList(false,true,Attr);
|
||||||
|
ExtractProcHeadPos:=phepParamList;
|
||||||
|
// read result type
|
||||||
|
if (CurPos.Flag=cafColon) then begin
|
||||||
|
ExtractNextAtom(phpWithResultType in Attr,Attr);
|
||||||
|
if not AtomIsIdentifier(false) then exit;
|
||||||
|
ExtractNextAtom(phpWithResultType in Attr,Attr);
|
||||||
|
ExtractProcHeadPos:=phepResultType;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// copy memorystream to Result string
|
||||||
|
Result:=GetExtraction;
|
||||||
|
end;
|
||||||
|
|
||||||
function TPascalParserTool.ExtractProcName(ProcNode: TCodeTreeNode;
|
function TPascalParserTool.ExtractProcName(ProcNode: TCodeTreeNode;
|
||||||
Attr: TProcHeadAttributes): string;
|
Attr: TProcHeadAttributes): string;
|
||||||
var
|
var
|
||||||
@ -3428,6 +3463,7 @@ begin
|
|||||||
ExtractNextAtom(phpWithResultType in Attr,Attr);
|
ExtractNextAtom(phpWithResultType in Attr,Attr);
|
||||||
ExtractProcHeadPos:=phepResultType;
|
ExtractProcHeadPos:=phepResultType;
|
||||||
end;
|
end;
|
||||||
|
// read 'of object'
|
||||||
if UpAtomIs('OF') then begin
|
if UpAtomIs('OF') then begin
|
||||||
if IsProcType then begin
|
if IsProcType then begin
|
||||||
ExtractNextAtom(phpWithOfObject in Attr,Attr);
|
ExtractNextAtom(phpWithOfObject in Attr,Attr);
|
||||||
@ -3981,9 +4017,10 @@ begin
|
|||||||
ReadNextAtom; // read 'property'
|
ReadNextAtom; // read 'property'
|
||||||
ReadNextAtom; // read name
|
ReadNextAtom; // read name
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if CurPos.Flag=cafEdgedBracketOpen then
|
if CurPos.Flag=cafEdgedBracketOpen then begin
|
||||||
ReadTilBracketClose(true);
|
ReadTilBracketClose(true);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
|
end;
|
||||||
Result:=(CurPos.Flag<>cafColon);
|
Result:=(CurPos.Flag<>cafColon);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -152,6 +152,13 @@ begin
|
|||||||
phpWithOfObject]);
|
phpWithOfObject]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
ctnProperty:
|
||||||
|
begin
|
||||||
|
s:=IdentItem.Tool.ExtractProperty(IdentItem.Node,
|
||||||
|
[phpWithoutName,phpWithVarModifiers,
|
||||||
|
phpWithParameterNames,phpWithDefaultValues,phpWithResultType]);
|
||||||
|
end;
|
||||||
|
|
||||||
ctnVarDefinition:
|
ctnVarDefinition:
|
||||||
begin
|
begin
|
||||||
ANode:=IdentItem.Tool.FindTypeNodeOfDefinition(IdentItem.Node);
|
ANode:=IdentItem.Tool.FindTypeNodeOfDefinition(IdentItem.Node);
|
||||||
|
Loading…
Reference in New Issue
Block a user