IDE+codetools: identifier completion: Options to disable sorting for history and scope

git-svn-id: trunk@46599 -
This commit is contained in:
mattias 2014-10-18 21:34:06 +00:00
parent 7a2d59468f
commit 43847bb0b3
5 changed files with 173 additions and 77 deletions

View File

@ -50,7 +50,7 @@ uses
{$ENDIF}
Classes, SysUtils, typinfo, FileProcs, CodeTree, CodeAtom, CodeCache,
CustomCodeTool, CodeToolsStrConsts, KeywordFuncLists, BasicCodeTools,
LinkScanner, AVL_Tree, CodeToolMemManager, DefineTemplates, SourceChanger,
LinkScanner, AvgLvlTree, AVL_Tree, CodeToolMemManager, DefineTemplates, SourceChanger,
FindDeclarationTool, PascalReaderTool, PascalParserTool, CodeToolsStructs,
ExprEval;
@ -202,6 +202,8 @@ type
FContext: TFindContext;
FNewMemberVisibility: TCodeTreeNodeDesc;
FContextFlags: TIdentifierListContextFlags;
FSortForHistory: boolean;
FSortForScope: boolean;
FStartAtom: TAtomPosition;
FStartAtomBehind: TAtomPosition;
FStartAtomInFront: TAtomPosition;
@ -211,13 +213,16 @@ type
FFilteredList: TFPList; // list of TIdentifierListItem
FFlags: TIdentifierListFlags;
FHistory: TIdentifierHistoryList;
FItems: TAVLTree; // tree of TIdentifierListItem (completely sorted)
FItems: TAvgLvlTree; // tree of TIdentifierListItem (completely sorted)
FIdentView: TAVLTree; // tree of TIdentifierListItem sorted for identifiers
FUsedTools: TAVLTree; // tree of TFindDeclarationTool
FIdentSearchItem: TIdentifierListSearchItem;
FPrefix: string;
FStartContext: TFindContext;
function CompareIdentListItems(Tree: TAvgLvlTree; Data1, Data2: Pointer): integer;
procedure SetHistory(const AValue: TIdentifierHistoryList);
procedure SetSortForHistory(AValue: boolean);
procedure SetSortForScope(AValue: boolean);
procedure UpdateFilteredList;
function GetFilteredItems(Index: integer): TIdentifierListItem;
procedure SetPrefix(const AValue: string);
@ -247,6 +252,8 @@ type
read GetFilteredItems;
property History: TIdentifierHistoryList read FHistory write SetHistory;
property Prefix: string read FPrefix write SetPrefix;
property SortForHistory: boolean read FSortForHistory write SetSortForHistory;
property SortForScope: boolean read FSortForScope write SetSortForScope;
property StartAtom: TAtomPosition read FStartAtom write FStartAtom;
property StartAtomInFront: TAtomPosition
read FStartAtomInFront write FStartAtomInFront; // in front of variable, not only of identifier
@ -414,46 +421,6 @@ const
CompilerFuncHistoryIndex = 10;
CompilerFuncLevel = 10;
function CompareIdentListItems(Data1, Data2: Pointer): integer;
var
Item1: TIdentifierListItem absolute Data1;
Item2: TIdentifierListItem absolute Data2;
begin
// first sort for Compatibility (lower is better)
if ord(Item1.Compatibility)<ord(Item2.Compatibility) then begin
Result:=-1;
exit;
end else if ord(Item1.Compatibility)>ord(Item2.Compatibility) then begin
Result:=1;
exit;
end;
// then sort for History (lower is better)
if Item1.HistoryIndex<Item2.HistoryIndex then begin
Result:=-1;
exit;
end else if Item1.HistoryIndex>Item2.HistoryIndex then begin
Result:=1;
exit;
end;
// then sort for Level (i.e. scope, lower is better)
if Item1.Level<Item2.Level then begin
Result:=-1;
exit;
end else if Item1.Level>Item2.Level then begin
Result:=1;
exit;
end;
// then sort alpabetically (lower is better)
Result:=CompareIdentifierPtrs(Pointer(Item2.Identifier),Pointer(Item1.Identifier));
if Result<>0 then exit;
// then sort for ParamList (lower is better)
Result:=Item2.CompareParamList(Item1);
end;
function CompareIdentListItemsForIdents(Data1, Data2: Pointer): integer;
var
Item1: TIdentifierListItem absolute Data1;
@ -536,6 +503,53 @@ end;
{ TIdentifierList }
function TIdentifierList.CompareIdentListItems(Tree: TAvgLvlTree; Data1,
Data2: Pointer): integer;
var
Item1: TIdentifierListItem absolute Data1;
Item2: TIdentifierListItem absolute Data2;
begin
if SortForScope then begin
// first sort for Compatibility (lower is better)
if ord(Item1.Compatibility)<ord(Item2.Compatibility) then begin
Result:=-1;
exit;
end else if ord(Item1.Compatibility)>ord(Item2.Compatibility) then begin
Result:=1;
exit;
end;
end;
if SortForHistory then begin
// then sort for History (lower is better)
if Item1.HistoryIndex<Item2.HistoryIndex then begin
Result:=-1;
exit;
end else if Item1.HistoryIndex>Item2.HistoryIndex then begin
Result:=1;
exit;
end;
end;
if SortForScope then begin
// then sort for Level (i.e. scope, lower is better)
if Item1.Level<Item2.Level then begin
Result:=-1;
exit;
end else if Item1.Level>Item2.Level then begin
Result:=1;
exit;
end;
end;
// then sort alpabetically (lower is better)
Result:=CompareIdentifierPtrs(Pointer(Item2.Identifier),Pointer(Item1.Identifier));
if Result<>0 then exit;
// then sort for ParamList (lower is better)
Result:=Item2.CompareParamList(Item1);
end;
procedure TIdentifierList.SetPrefix(const AValue: string);
begin
if FPrefix=AValue then exit;
@ -545,7 +559,7 @@ end;
procedure TIdentifierList.UpdateFilteredList;
var
AnAVLNode: TAVLTreeNode;
AnAVLNode: TAvgLvlTreeNode;
CurItem: TIdentifierListItem;
begin
if not (ilfFilteredListNeedsUpdate in FFlags) then exit;
@ -585,6 +599,20 @@ begin
FHistory:=AValue;
end;
procedure TIdentifierList.SetSortForHistory(AValue: boolean);
begin
if FSortForHistory=AValue then Exit;
FSortForHistory:=AValue;
Clear;
end;
procedure TIdentifierList.SetSortForScope(AValue: boolean);
begin
if FSortForScope=AValue then Exit;
FSortForScope:=AValue;
Clear;
end;
function TIdentifierList.GetFilteredItems(Index: integer): TIdentifierListItem;
begin
UpdateFilteredList;
@ -597,10 +625,12 @@ end;
constructor TIdentifierList.Create;
begin
FFlags:=[ilfFilteredListNeedsUpdate];
FItems:=TAVLTree.Create(@CompareIdentListItems);
FItems:=TAvgLvlTree.CreateObjectCompare(@CompareIdentListItems);
FIdentView:=TAVLTree.Create(@CompareIdentListItemsForIdents);
FIdentSearchItem:=TIdentifierListSearchItem.Create;
FCreatedIdentifiers:=TFPList.Create;
FSortForHistory:=true;
FSortForScope:=true;
end;
destructor TIdentifierList.Destroy;
@ -779,7 +809,7 @@ function TIdentifierList.CompletePrefix(const OldPrefix: string): string;
// search all identifiers beginning with Prefix
// and return the biggest shared prefix of all of them
var
AnAVLNode: TAVLTreeNode;
AnAVLNode: TAvgLvlTreeNode;
CurItem: TIdentifierListItem;
FoundFirst: Boolean;
SamePos: Integer;
@ -820,6 +850,7 @@ function TIdentifierList.CalcMemSize: PtrUInt;
var
i: Integer;
Node: TAVLTreeNode;
AvgNode: TAvgLvlTreeNode;
li: TIdentifierListItem;
hli: TIdentHistListItem;
begin
@ -839,12 +870,12 @@ begin
inc(Result,FHistory.CalcMemSize);
end;
if FItems<>nil then begin
inc(Result,FItems.Count*SizeOf(TAVLTreeNode));
Node:=FItems.FindLowest;
while Node<>nil do begin
li:=TIdentifierListItem(Node.Data);
inc(Result,FItems.Count*SizeOf(TAvgLvlTreeNode));
AvgNode:=FItems.FindLowest;
while AvgNode<>nil do begin
li:=TIdentifierListItem(AvgNode.Data);
inc(Result,li.CalcMemSize);
Node:=FItems.FindSuccessor(Node);
AvgNode:=AvgNode.Successor;
end;
end;
if FIdentView<>nil then begin

View File

@ -61,6 +61,8 @@ type
// General
FAdjustTopLineDueToComment: boolean;
FIdentComplSortForHistory: boolean;
FIdentComplSortForScope: boolean;
FJumpCentered: boolean;
FCursorBeyondEOL: boolean;
FSkipForwardDeclarations: boolean;
@ -219,6 +221,10 @@ type
read FIdentComplReplaceIdentifier write FIdentComplReplaceIdentifier;
property IdentComplShowHelp: boolean read FIdentComplShowHelp
write FIdentComplShowHelp;
property IdentComplSortForHistory: boolean read FIdentComplSortForHistory
write FIdentComplSortForHistory;
property IdentComplSortForScope: boolean read FIdentComplSortForScope
write FIdentComplSortForScope;
// indentation
property IndentOnLineBreak: boolean read FIndentOnLineBreak
@ -482,6 +488,10 @@ begin
'CodeToolsOptions/IdentifierCompletion/ReplaceIdentifier',true);
FIdentComplShowHelp:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/ShowHelp',false);
FIdentComplSortForHistory:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/SortForHistory',true);
FIdentComplSortForScope:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/SortForScope',true);
// indentation
FIndentOnLineBreak :=
@ -624,6 +634,10 @@ begin
FIdentComplReplaceIdentifier,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/ShowHelp',
FIdentComplShowHelp,false);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/SortForHistory',
FIdentComplSortForHistory,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/SortForScope',
FIdentComplSortForScope,true);
// indentation
XMLConfig.SetDeleteValue('CodeToolsOptions/Indentation/OnLineBreak/Enabled'
@ -743,6 +757,8 @@ begin
FIdentComplAddParameterBrackets:=CodeToolsOpts.FIdentComplAddParameterBrackets;
FIdentComplReplaceIdentifier:=CodeToolsOpts.FIdentComplReplaceIdentifier;
FIdentComplShowHelp:=CodeToolsOpts.FIdentComplShowHelp;
FIdentComplSortForHistory:=CodeToolsOpts.FIdentComplSortForHistory;
FIdentComplSortForScope:=CodeToolsOpts.FIdentComplSortForScope;
end
else
Clear;
@ -797,6 +813,8 @@ begin
FIdentComplAddParameterBrackets:=true;
FIdentComplReplaceIdentifier:=true;
FIdentComplShowHelp:=false;
FIdentComplSortForHistory:=true;
FIdentComplSortForScope:=true;
// indentation
FIndentOnLineBreak:=true;
@ -869,6 +887,8 @@ begin
and (FIdentComplAddParameterBrackets=CodeToolsOpts.FIdentComplAddParameterBrackets)
and (FIdentComplReplaceIdentifier=CodeToolsOpts.FIdentComplReplaceIdentifier)
and (FIdentComplShowHelp=CodeToolsOpts.FIdentComplShowHelp)
and (FIdentComplSortForHistory=CodeToolsOpts.FIdentComplSortForHistory)
and (FIdentComplSortForScope=CodeToolsOpts.FIdentComplSortForScope)
;
end;
@ -933,7 +953,12 @@ begin
// CreateCode - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AssignTo(Boss.SourceChangeCache.BeautifyCodeOptions);
Boss.SetPropertyVariablename:=SetPropertyVariablename;
//
// Identifier Completion - - - - - - - - - - - - - - - - - - - - - - - - - -
Boss.IdentifierList.SortForHistory:=IdentComplSortForHistory;
Boss.IdentifierList.SortForScope:=IdentComplSortForScope;
// Code Templates- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
aFilename:=CodeCompletionTemplateFileName;
IDEMacros.SubstituteMacros(aFilename);
aFilename:=TrimFilename(aFilename);

View File

@ -1,10 +1,10 @@
object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompletionOptionsFrame
Left = 0
Height = 300
Height = 415
Top = 0
Width = 400
ClientHeight = 300
ClientWidth = 400
Width = 537
ClientHeight = 415
ClientWidth = 537
TabOrder = 0
Visible = False
DesignLeft = 514
@ -15,9 +15,9 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Height = 24
Top = 0
Width = 400
Width = 537
Anchors = [akTop, akLeft, akRight]
Caption = 'ICAddSemicolonCheckBox'
TabOrder = 0
@ -29,9 +29,9 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 25
Width = 400
Height = 24
Top = 30
Width = 537
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
Caption = 'ICAddAssignOperatorCheckBox'
@ -44,9 +44,9 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 75
Width = 400
Height = 24
Top = 90
Width = 537
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
Caption = 'ICAutoStartAfterPointCheckBox'
@ -59,9 +59,9 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 100
Width = 400
Height = 24
Top = 120
Width = 537
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
Caption = 'ICAutoAddParameterBracketsCheckBox'
@ -74,11 +74,11 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 150
Width = 400
Height = 24
Top = 188
Width = 537
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
BorderSpacing.Top = 10
Caption = 'ICShowHelpCheckBox'
ParentShowHint = False
ShowHint = True
@ -91,11 +91,11 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 125
Width = 400
Height = 24
Top = 154
Width = 537
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
BorderSpacing.Top = 10
Caption = 'ICReplaceCheckBox'
ParentShowHint = False
ShowHint = True
@ -108,12 +108,35 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 50
Width = 400
Height = 24
Top = 60
Width = 537
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 6
Caption = 'ICAddDoCheckBox'
TabOrder = 6
end
object ICSortForHistoryCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICShowHelpCheckBox
AnchorSideTop.Side = asrBottom
Left = 0
Height = 24
Top = 222
Width = 170
BorderSpacing.Top = 10
Caption = 'ICSortForHistoryCheckBox'
TabOrder = 7
end
object ICSortForScopeCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ICSortForHistoryCheckBox
AnchorSideTop.Side = asrBottom
Left = 0
Height = 24
Top = 246
Width = 164
Caption = 'ICSortForScopeCheckBox'
TabOrder = 8
end
end

View File

@ -40,6 +40,8 @@ type
ICAddSemicolonCheckBox: TCheckBox;
ICReplaceCheckBox: TCheckBox;
ICShowHelpCheckBox: TCheckBox;
ICSortForHistoryCheckBox: TCheckBox;
ICSortForScopeCheckBox: TCheckBox;
private
public
function GetTitle: String; override;
@ -68,10 +70,16 @@ begin
ICAddDoCheckBox.Caption:=lisAddKeywordDo;
ICAutoStartAfterPointCheckBox.Caption:=lisAutomaticallyInvokeAfterPoint;
ICAutoAddParameterBracketsCheckBox.Caption:=lisAddParameterBrackets;
ICReplaceCheckBox.Caption:=lisReplaceWholeIdentifier;
ICReplaceCheckBox.Hint:=lisEnableReplaceWholeIdentifierDisableReplacePrefix;
ICShowHelpCheckBox.Caption:=lisShowHelp;
ICShowHelpCheckBox.Hint:=lisBestViewedByInstallingAHTMLControlLikeTurbopowerip;
ICSortForHistoryCheckBox.Caption:=lisShowRecentlyUsedIdentifiersAtTop;
ICSortForScopeCheckBox.Caption:=lisSortForScope;
ICSortForScopeCheckBox.Hint:=lisForExampleShowAtTopTheLocalVariablesThenTheMembers;
end;
procedure TCodetoolsIndentifierCompletionOptionsFrame.ReadSettings(
@ -86,6 +94,8 @@ begin
ICAutoAddParameterBracketsCheckBox.Checked:=IdentComplAddParameterBrackets;
ICReplaceCheckBox.Checked:=IdentComplReplaceIdentifier;
ICShowHelpCheckBox.Checked:=IdentComplShowHelp;
ICSortForHistoryCheckBox.Checked:=IdentComplSortForHistory;
ICSortForScopeCheckBox.Checked:=IdentComplSortForScope;
end;
end;
@ -101,6 +111,8 @@ begin
IdentComplAddParameterBrackets:=ICAutoAddParameterBracketsCheckBox.Checked;
IdentComplReplaceIdentifier:=ICReplaceCheckBox.Checked;
IdentComplShowHelp:=ICShowHelpCheckBox.Checked;
IdentComplSortForHistory:=ICSortForHistoryCheckBox.Checked;
IdentComplSortForScope:=ICSortForScopeCheckBox.Checked;
end;
end;

View File

@ -5213,6 +5213,11 @@ resourcestring
lisShowHelp = 'Show help';
lisBestViewedByInstallingAHTMLControlLikeTurbopowerip = 'Best viewed by '
+'installing a HTML control like turbopoweriprodsgn';
lisShowRecentlyUsedIdentifiersAtTop = 'Show recently used identifiers at top';
lisSortForScope = 'Sort for scope';
lisForExampleShowAtTopTheLocalVariablesThenTheMembers = 'For example show at'
+' top the local variables, then the members of current class, then of the'
+' ancestors, then the current unit, then of used units';
lisShowEmptyUnitsPackages = 'Show empty units/packages';
lisUsePackageInProject = 'Use package %s in project';
lisUsePackageInProject2 = 'Use package in project';