mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 13:50:06 +02:00
MG: codecompletion: improved separation of vars, methods and props
git-svn-id: trunk@3137 -
This commit is contained in:
parent
396d1012c2
commit
cf4d7edc1e
@ -209,8 +209,8 @@ procedure TCodeCompletionCodeTool.AddClassInsertion(PosNode: TCodeTreeNode;
|
|||||||
{ add an insert request entry to the list of insertions
|
{ add an insert request entry to the list of insertions
|
||||||
For example: a request to insert a new variable or a new method to the class
|
For example: a request to insert a new variable or a new method to the class
|
||||||
|
|
||||||
PosNode: The node, to which the request belongs. e.g. the property node, if
|
PosNode: optional. The node, to which the request belongs. e.g. the
|
||||||
the insert is the auto created private variable
|
property node, if the insert is the auto created private variable.
|
||||||
CleanDef: The skeleton of the new insertion. e.g. the variablename or the
|
CleanDef: The skeleton of the new insertion. e.g. the variablename or the
|
||||||
method header without parameter names.
|
method header without parameter names.
|
||||||
Def: The insertion code.
|
Def: The insertion code.
|
||||||
@ -842,7 +842,7 @@ var ANodeExt: TCodeTreeNodeExtension;
|
|||||||
ClassSectionNode, ANode, InsertNode: TCodeTreeNode;
|
ClassSectionNode, ANode, InsertNode: TCodeTreeNode;
|
||||||
Indent, InsertPos: integer;
|
Indent, InsertPos: integer;
|
||||||
CurCode: string;
|
CurCode: string;
|
||||||
IsVariable: boolean;
|
IsVariable, InsertBehind: boolean;
|
||||||
begin
|
begin
|
||||||
ANodeExt:=FirstInsert;
|
ANodeExt:=FirstInsert;
|
||||||
// insert all nodes of specific type
|
// insert all nodes of specific type
|
||||||
@ -877,61 +877,105 @@ begin
|
|||||||
InsertPos:=NewPrivatSectionInsertPos;
|
InsertPos:=NewPrivatSectionInsertPos;
|
||||||
end else begin
|
end else begin
|
||||||
// there is an existing class section to insert into
|
// there is an existing class section to insert into
|
||||||
|
|
||||||
|
// find a nice insert position
|
||||||
InsertNode:=nil; // the new part will be inserted after this node
|
InsertNode:=nil; // the new part will be inserted after this node
|
||||||
// nil means insert as first
|
// nil means insert as first
|
||||||
|
InsertBehind:=true;
|
||||||
ANode:=ClassSectionNode.FirstChild;
|
ANode:=ClassSectionNode.FirstChild;
|
||||||
|
|
||||||
|
// skip the class GUID
|
||||||
if (ANode<>nil) and (ANode.Desc=ctnClassGUID) then
|
if (ANode<>nil) and (ANode.Desc=ctnClassGUID) then
|
||||||
ANode:=ANode.NextBrother;
|
ANode:=ANode.NextBrother;
|
||||||
|
|
||||||
|
// insert methods behind variables
|
||||||
if not IsVariable then begin
|
if not IsVariable then begin
|
||||||
// insert procs after variables
|
|
||||||
while (ANode<>nil) and (ANode.Desc=ctnVarDefinition) do begin
|
while (ANode<>nil) and (ANode.Desc=ctnVarDefinition) do begin
|
||||||
InsertNode:=ANode;
|
InsertNode:=ANode;
|
||||||
ANode:=ANode.NextBrother;
|
ANode:=ANode.NextBrother;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// find a nice position between similar siblings
|
||||||
case ASourceChangeCache.BeautifyCodeOptions.ClassPartInsertPolicy of
|
case ASourceChangeCache.BeautifyCodeOptions.ClassPartInsertPolicy of
|
||||||
cpipAlphabetically:
|
|
||||||
begin
|
cpipAlphabetically:
|
||||||
while ANode<>nil do begin
|
begin
|
||||||
if (IsVariable) then begin
|
while ANode<>nil do begin
|
||||||
if (ANode.Desc<>ctnVarDefinition)
|
if (IsVariable) then begin
|
||||||
or (CompareNodeIdentChars(ANode,ANodeExt.Txt)<0) then
|
// the insertion is a new variable
|
||||||
break;
|
if (ANode.Desc<>ctnVarDefinition)
|
||||||
end else begin
|
or (CompareNodeIdentChars(ANode,ANodeExt.Txt)<0) then
|
||||||
case ANode.Desc of
|
break;
|
||||||
ctnProcedure:
|
end else begin
|
||||||
begin
|
// the insertion is a new method
|
||||||
CurCode:=ExtractProcName(ANode,[]);
|
case ANode.Desc of
|
||||||
if AnsiCompareStr(CurCode,ANodeExt.ExtTxt2)>0 then
|
ctnProcedure:
|
||||||
break;
|
begin
|
||||||
end;
|
CurCode:=ExtractProcName(ANode,[]);
|
||||||
ctnProperty:
|
if AnsiCompareStr(CurCode,ANodeExt.ExtTxt2)>0 then
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
ctnProperty:
|
||||||
|
begin
|
||||||
|
if ASourceChangeCache.BeautifyCodeOptions
|
||||||
|
.MixMethodsAndPorperties then
|
||||||
begin
|
begin
|
||||||
CurCode:=ExtractPropName(ANode,false);
|
CurCode:=ExtractPropName(ANode,false);
|
||||||
if AnsiCompareStr(CurCode,ANodeExt.ExtTxt2)>0 then
|
if AnsiCompareStr(CurCode,ANodeExt.ExtTxt2)>0 then
|
||||||
break;
|
break;
|
||||||
end;
|
end else
|
||||||
end;
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
InsertNode:=ANode;
|
|
||||||
ANode:=ANode.NextBrother;
|
|
||||||
end;
|
end;
|
||||||
|
InsertNode:=ANode;
|
||||||
|
ANode:=ANode.NextBrother;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
else
|
else
|
||||||
// cpipLast
|
// cpipLast
|
||||||
begin
|
begin
|
||||||
while ANode<>nil do begin
|
while ANode<>nil do begin
|
||||||
if (IsVariable) and (ANode.Desc<>ctnVarDefinition) then
|
if (IsVariable) then begin
|
||||||
break;
|
// the insertion is a variable
|
||||||
|
if (ANode.Desc<>ctnVarDefinition) then
|
||||||
|
break;
|
||||||
|
end else begin
|
||||||
|
// the insertion is a method
|
||||||
|
if (not ASourceChangeCache.BeautifyCodeOptions
|
||||||
|
.MixMethodsAndPorperties)
|
||||||
|
and (ANode.Desc=ctnProperty) then
|
||||||
|
break;
|
||||||
|
end;
|
||||||
InsertNode:=ANode;
|
InsertNode:=ANode;
|
||||||
ANode:=ANode.NextBrother;
|
ANode:=ANode.NextBrother;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if InsertNode<>nil then begin
|
if InsertNode<>nil then begin
|
||||||
// insert after InsertNode
|
|
||||||
|
if (not IsVariable) and (InsertNode.Desc=ctnVarDefinition)
|
||||||
|
and (InsertNode.NextBrother<>nil) then begin
|
||||||
|
// insertion is a new method and it should be inserted behind
|
||||||
|
// variables. Because methods and variables should be separated
|
||||||
|
// there is a next node, insert the new method in front of the next
|
||||||
|
// node, instead of inserting it right behind the variable.
|
||||||
|
// This makes sure to use existing separation comments/empty lines.
|
||||||
|
InsertNode:=InsertNode.NextBrother;
|
||||||
|
InsertBehind:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
Indent:=GetLineIndent(Src,InsertNode.StartPos);
|
Indent:=GetLineIndent(Src,InsertNode.StartPos);
|
||||||
InsertPos:=FindFirstLineEndAfterInCode(InsertNode.EndPos);
|
if InsertBehind then begin
|
||||||
|
// insert behind InsertNode
|
||||||
|
InsertPos:=FindFirstLineEndAfterInCode(InsertNode.EndPos);
|
||||||
|
end else begin
|
||||||
|
// insert in front of InsertNode
|
||||||
|
InsertPos:=InsertNode.StartPos;
|
||||||
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
// insert as first variable/proc
|
// insert as first variable/proc
|
||||||
Indent:=GetLineIndent(Src,ClassSectionNode.StartPos)
|
Indent:=GetLineIndent(Src,ClassSectionNode.StartPos)
|
||||||
|
Loading…
Reference in New Issue
Block a user