mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-11 18:00:37 +01:00
IDE, Identifier-Completion: fix sorting in identifier completion. Issue #40332 / Restore order-precedence for Compatibility.
This commit is contained in:
parent
cbe5f931fa
commit
afb5e6376c
@ -677,20 +677,18 @@ type
|
|||||||
);
|
);
|
||||||
var
|
var
|
||||||
SecondaryList: TFPList;
|
SecondaryList: TFPList;
|
||||||
RecentPos: array [Boolean, mtPriority..mtSecondary] of Integer;
|
|
||||||
LastMatchPos: Integer;
|
LastMatchPos: Integer;
|
||||||
|
|
||||||
// LowerRecent: mid-word matched in mtPriority
|
procedure InsertItem(Itm: TIdentifierListItem; Sect: TMatchSection; InsertPosFromEnd: Integer); inline;
|
||||||
procedure InsertItem(Itm: TIdentifierListItem; Sect: TMatchSection; AsRecent, AsLowerRecent: boolean); inline;
|
|
||||||
var
|
var
|
||||||
l: TFPList;
|
l: TFPList;
|
||||||
begin
|
begin
|
||||||
{$IFDEF ShowFilteredIdents}
|
if ((FFilteredList.Count + SecondaryList.Count) < 15) or (InsertPosFromEnd > 0) then //////////////////////
|
||||||
DebugLn('::: FILTERED ITEM Prior %d/%d Second %d/%d "%s" (%d) AsRecent %s',
|
{ $IFDEF ShowFilteredIdents}
|
||||||
[RecentPos[False, mtPriority], FFilteredList.Count,
|
DebugLn('::: FILTERED ITEM Prior %d / Second %d "%s" (%d) AsRecent -%d',
|
||||||
RecentPos[False, mtSecondary], SecondaryList.Count,
|
[ FFilteredList.Count, SecondaryList.Count,
|
||||||
Itm.Identifier, ord(Sect), dbgs(AsRecent)]);
|
Itm.Identifier, ord(Sect), InsertPosFromEnd]);
|
||||||
{$ENDIF}
|
{ $ENDIF}
|
||||||
|
|
||||||
case Sect of
|
case Sect of
|
||||||
mtNone: exit;
|
mtNone: exit;
|
||||||
@ -705,16 +703,11 @@ var
|
|||||||
l.Insert(0,Itm)
|
l.Insert(0,Itm)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if AsRecent then begin
|
if InsertPosFromEnd > 0 then begin
|
||||||
l.Insert(RecentPos[AsLowerRecent, Sect], Itm);
|
l.Insert(l.Count - InsertPosFromEnd, Itm);
|
||||||
Inc(RecentPos[AsLowerRecent, Sect]);
|
|
||||||
if not AsLowerRecent then
|
|
||||||
Inc(RecentPos[True, Sect]);
|
|
||||||
Itm.Flags := Itm.Flags + [iliIsRecentItem];
|
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
l.Add(Itm);
|
l.Add(Itm);
|
||||||
Itm.Flags := Itm.Flags - [iliIsRecentItem];
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -736,13 +729,87 @@ var
|
|||||||
Result := mtSecondary;
|
Result := mtSecondary;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
MaxHistoryIndex: array [mtPriority..mtSecondary] of integer;
|
||||||
|
LowerRecentCount: Integer;
|
||||||
|
|
||||||
|
procedure HandleItem(CurItem: TIdentifierListItem; FilterRecenct: boolean);
|
||||||
|
var
|
||||||
|
MatchSection: TMatchSection;
|
||||||
|
IsRecent: Boolean;
|
||||||
|
begin
|
||||||
|
if CurItem.Identifier<>'' then
|
||||||
|
begin
|
||||||
|
MatchSection := WantedMatchSection(CurItem); // setl LastMatchPos;
|
||||||
|
if MatchSection = mtNone then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
IsRecent := CurItem.HistoryIndex <= MaxHistoryIndex[MatchSection];
|
||||||
|
if (not IsRecent) and (LastMatchPos > 0) then
|
||||||
|
MatchSection := mtSecondary;
|
||||||
|
|
||||||
|
if IsRecent = FilterRecenct then begin
|
||||||
|
if LastMatchPos > 0
|
||||||
|
then CurItem.Flags := CurItem.Flags + [iliMatchedMidWord]
|
||||||
|
else CurItem.Flags := CurItem.Flags - [iliMatchedMidWord];
|
||||||
|
if IsRecent
|
||||||
|
then CurItem.Flags := CurItem.Flags + [iliIsRecentItem]
|
||||||
|
else CurItem.Flags := CurItem.Flags - [iliIsRecentItem];
|
||||||
|
|
||||||
|
if IsRecent and (MatchSection = mtPriority) then begin
|
||||||
|
if (LastMatchPos > 0) then begin
|
||||||
|
// Mid-Word matches in the priority section
|
||||||
|
// Keep count, so prefix matches can be inserted before
|
||||||
|
inc(LowerRecentCount);
|
||||||
|
InsertItem(CurItem, MatchSection, 0);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
InsertItem(CurItem, MatchSection, LowerRecentCount);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
InsertItem(CurItem, MatchSection, 0);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure InsertHistoryForComp(ACompat: TIdentifierCompatibility);
|
||||||
|
var
|
||||||
|
j: Integer;
|
||||||
|
CurItem: TIdentifierListItem;
|
||||||
|
begin
|
||||||
|
debugln(['>>> InsertHistoryForComp ', ord(ACompat)]);
|
||||||
|
LowerRecentCount := 0;
|
||||||
|
for j := 0 to length(FFoundHistoryItems) - 1 do begin
|
||||||
|
CurItem := FFoundHistoryItems[j];
|
||||||
|
if (CurItem <> nil) and (CurItem.Compatibility = ACompat) then
|
||||||
|
HandleItem(CurItem, True);
|
||||||
|
end;
|
||||||
|
LowerRecentCount := 0;
|
||||||
|
debugln(['<<< InsertHistoryForComp ', ord(ACompat)]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure InsertHistoryForAllComp;
|
||||||
|
var
|
||||||
|
j: Integer;
|
||||||
|
CurItem: TIdentifierListItem;
|
||||||
|
begin
|
||||||
|
debugln(['>>> InsertHistoryForAllComp ']);
|
||||||
|
LowerRecentCount := 0;
|
||||||
|
for j := 0 to length(FFoundHistoryItems) - 1 do begin
|
||||||
|
CurItem := FFoundHistoryItems[j];
|
||||||
|
if CurItem <> nil then
|
||||||
|
HandleItem(CurItem, True);
|
||||||
|
end;
|
||||||
|
LowerRecentCount := 0;
|
||||||
|
debugln(['>>> InsertHistoryForAllComp ']);
|
||||||
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
AnAVLNode: TAvlTreeNode;
|
AnAVLNode: TAvlTreeNode;
|
||||||
CurItem: TIdentifierListItem;
|
CurItem: TIdentifierListItem;
|
||||||
TotalHistLimit, j: Integer;
|
TotalHistLimit, j: Integer;
|
||||||
MaxHistoryIndex: array [mtPriority..mtSecondary] of integer;
|
|
||||||
MatchSection: TMatchSection;
|
MatchSection: TMatchSection;
|
||||||
IsRecent: Boolean;
|
HistoryCompatDone: TIdentifierCompatibility;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if not (ilfFilteredListNeedsUpdate in FFlags) then exit;
|
if not (ilfFilteredListNeedsUpdate in FFlags) then exit;
|
||||||
@ -757,11 +824,8 @@ begin
|
|||||||
TotalHistLimit := 0;
|
TotalHistLimit := 0;
|
||||||
if FSortForHistory then
|
if FSortForHistory then
|
||||||
TotalHistLimit := FSortForHistoryLimit;
|
TotalHistLimit := FSortForHistoryLimit;
|
||||||
for MatchSection := mtPriority to mtSecondary do begin
|
for MatchSection := mtPriority to mtSecondary do
|
||||||
RecentPos[False, MatchSection] := 0;
|
|
||||||
RecentPos[True, MatchSection] := 0;
|
|
||||||
MaxHistoryIndex[MatchSection] := -1;
|
MaxHistoryIndex[MatchSection] := -1;
|
||||||
end;
|
|
||||||
for MatchSection := mtPriority to mtSecondary do begin
|
for MatchSection := mtPriority to mtSecondary do begin
|
||||||
for j := 0 to length(FFoundHistoryItems) - 1 do begin
|
for j := 0 to length(FFoundHistoryItems) - 1 do begin
|
||||||
if TotalHistLimit <= 0 then
|
if TotalHistLimit <= 0 then
|
||||||
@ -778,27 +842,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
debugln;debugln(['=================================================================== ']);debugln;
|
||||||
SecondaryList := TFPList.Create;
|
SecondaryList := TFPList.Create;
|
||||||
AnAVLNode:=FItems.FindLowest;
|
AnAVLNode:=FItems.FindLowest;
|
||||||
|
if SortMethodForCompletion in IdentComplSortMethodUsingCompatibility then begin
|
||||||
|
HistoryCompatDone := low(TIdentifierCompatibility);
|
||||||
|
InsertHistoryForComp(HistoryCompatDone);
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
HistoryCompatDone := High(TIdentifierCompatibility);
|
||||||
|
InsertHistoryForAllComp;
|
||||||
|
end;
|
||||||
|
|
||||||
while AnAVLNode<>nil do begin
|
while AnAVLNode<>nil do begin
|
||||||
CurItem:=TIdentifierListItem(AnAVLNode.Data);
|
CurItem:=TIdentifierListItem(AnAVLNode.Data);
|
||||||
AnAVLNode:=FItems.FindSuccessor(AnAVLNode);
|
while HistoryCompatDone < CurItem.Compatibility do begin
|
||||||
if CurItem.Identifier<>'' then
|
inc(HistoryCompatDone);
|
||||||
begin
|
InsertHistoryForComp(HistoryCompatDone);
|
||||||
MatchSection := WantedMatchSection(CurItem);
|
|
||||||
if MatchSection = mtNone then
|
|
||||||
Continue;
|
|
||||||
|
|
||||||
IsRecent := CurItem.HistoryIndex <= MaxHistoryIndex[MatchSection];
|
|
||||||
if (not IsRecent) and (LastMatchPos > 0) then
|
|
||||||
MatchSection := mtSecondary;
|
|
||||||
|
|
||||||
if LastMatchPos > 0
|
|
||||||
then CurItem.Flags := CurItem.Flags + [iliMatchedMidWord]
|
|
||||||
else CurItem.Flags := CurItem.Flags - [iliMatchedMidWord];
|
|
||||||
|
|
||||||
InsertItem(CurItem, MatchSection, IsRecent, LastMatchPos > 0);
|
|
||||||
end;
|
end;
|
||||||
|
AnAVLNode:=FItems.FindSuccessor(AnAVLNode);
|
||||||
|
HandleItem(CurItem, False);
|
||||||
|
end;
|
||||||
|
while HistoryCompatDone < high(TIdentifierCompatibility) do begin
|
||||||
|
inc(HistoryCompatDone);
|
||||||
|
InsertHistoryForComp(HistoryCompatDone);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
j := FFilteredList.Count;
|
j := FFilteredList.Count;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user