mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 21:42:51 +02:00
codetools: parser: fixed starting class section on first space, completeblock: complete class at end of source
git-svn-id: trunk@30180 -
This commit is contained in:
parent
d23a694b2c
commit
3db7df3317
@ -3813,6 +3813,7 @@ begin
|
|||||||
// start the first class section (always published)
|
// start the first class section (always published)
|
||||||
CreateChildNode;
|
CreateChildNode;
|
||||||
CurNode.Desc:=ctnClassPublished;
|
CurNode.Desc:=ctnClassPublished;
|
||||||
|
CurNode.StartPos:=LastAtoms.GetValueAt(0).EndPos;
|
||||||
if CurPos.Flag=cafEdgedBracketOpen then
|
if CurPos.Flag=cafEdgedBracketOpen then
|
||||||
ReadGUID;
|
ReadGUID;
|
||||||
// parse till "end" of class/object
|
// parse till "end" of class/object
|
||||||
|
@ -43,7 +43,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileProcs, CodeToolsStrConsts, CodeCache, BasicCodeTools,
|
Classes, SysUtils, FileProcs, CodeToolsStrConsts, CodeCache, BasicCodeTools,
|
||||||
LinkScanner, AVL_Tree, CodeBeautifier, KeywordFuncLists;
|
typinfo, LinkScanner, AVL_Tree, CodeBeautifier, KeywordFuncLists;
|
||||||
|
|
||||||
type
|
type
|
||||||
// Insert policy types for class parts (properties, variables, method defs)
|
// Insert policy types for class parts (properties, variables, method defs)
|
||||||
@ -323,6 +323,7 @@ function ForwardProcBodyInsertPolicyNameToPolicy(
|
|||||||
const s: string): TForwardProcBodyInsertPolicy;
|
const s: string): TForwardProcBodyInsertPolicy;
|
||||||
function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
|
function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
|
||||||
|
|
||||||
|
function dbgs(g: TGapTyp): string; overload;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -387,6 +388,11 @@ begin
|
|||||||
Result:=DefaultUsesInsertPolicy;
|
Result:=DefaultUsesInsertPolicy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function dbgs(g: TGapTyp): string;
|
||||||
|
begin
|
||||||
|
Result:=GetEnumName(typeinfo(g),ord(g));
|
||||||
|
end;
|
||||||
|
|
||||||
function CompareSourceChangeCacheEntry(NodeData1, NodeData2: pointer): integer;
|
function CompareSourceChangeCacheEntry(NodeData1, NodeData2: pointer): integer;
|
||||||
var
|
var
|
||||||
Entry1, Entry2: TSourceChangeCacheEntry;
|
Entry1, Entry2: TSourceChangeCacheEntry;
|
||||||
|
@ -5322,7 +5322,7 @@ var
|
|||||||
p: LongInt;
|
p: LongInt;
|
||||||
begin
|
begin
|
||||||
if NewCode='' then exit(true);
|
if NewCode='' then exit(true);
|
||||||
// avoid changing current line
|
// try to avoid changing current line
|
||||||
if (FrontGap=gtEmptyLine) then begin
|
if (FrontGap=gtEmptyLine) then begin
|
||||||
p:=FromPos;
|
p:=FromPos;
|
||||||
while (p>1) and (Src[p-1] in [' ',#9]) do dec(p);
|
while (p>1) and (Src[p-1] in [' ',#9]) do dec(p);
|
||||||
@ -5372,7 +5372,7 @@ var
|
|||||||
AfterGap:=gtNone;
|
AfterGap:=gtNone;
|
||||||
end;
|
end;
|
||||||
{$IFDEF ShowCompleteBlock}
|
{$IFDEF ShowCompleteBlock}
|
||||||
debugln(['Replace Indent=',Indent,' NewCode="',dbgstr(NewCode),'" Replace="',DbgStr(copy(Src,FromPos-5,5)),'|',dbgstr(copy(Src,FromPos,ToPos-FromPos)),'|',dbgstr(copy(Src,ToPos,5)),'"']);
|
debugln(['Replace Indent=',Indent,' NewCode="',dbgstr(NewCode),'" Replace: InFront="',DbgStr(copy(Src,FromPos-15,15)),'",Replace="',dbgstr(copy(Src,FromPos,ToPos-FromPos)),'",Behind="',dbgstr(copy(Src,ToPos,15)),'" FrontGap=',dbgs(FrontGap),' AfterGap=',dbgs(AfterGap)]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// insert
|
// insert
|
||||||
if not SourceChangeCache.Replace(FrontGap,AfterGap,
|
if not SourceChangeCache.Replace(FrontGap,AfterGap,
|
||||||
@ -5913,12 +5913,19 @@ var
|
|||||||
if CleanCursorPos<StartNode.StartPos then exit;
|
if CleanCursorPos<StartNode.StartPos then exit;
|
||||||
LastIndent:=GetLineIndent(Src,StartNode.Parent.StartPos);
|
LastIndent:=GetLineIndent(Src,StartNode.Parent.StartPos);
|
||||||
MoveCursorToNodeStart(StartNode);
|
MoveCursorToNodeStart(StartNode);
|
||||||
|
//debugln(['CompleteClassSection ',dbgstr(copy(Src,StartNode.StartPos-10,10)),'|',dbgstr(copy(Src,StartNode.StartPos,10))]);
|
||||||
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
||||||
if Indent<LastIndent then
|
if Indent<LastIndent then
|
||||||
LastIndent:=Indent;
|
LastIndent:=Indent;
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
NeedCompletion:=0;
|
NeedCompletion:=0;
|
||||||
if CurPos.Flag=cafWord then begin
|
if (CurPos.StartPos>SrcLen) then begin
|
||||||
|
{ For example:
|
||||||
|
TMyClass = class
|
||||||
|
<EOF>
|
||||||
|
}
|
||||||
|
NeedCompletion:=CleanCursorPos;
|
||||||
|
end else if CurPos.Flag=cafWord then begin
|
||||||
if AtomIsIdentifier(false) then begin
|
if AtomIsIdentifier(false) then begin
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if CurPos.Flag=cafEqual then begin
|
if CurPos.Flag=cafEqual then begin
|
||||||
@ -5943,7 +5950,7 @@ var
|
|||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
exit(true);
|
exit(true);
|
||||||
|
//debugln(['CompleteClassSection NeedCompletion=',NeedCompletion]);
|
||||||
if NeedCompletion>0 then begin
|
if NeedCompletion>0 then begin
|
||||||
InsertPos:=NeedCompletion;
|
InsertPos:=NeedCompletion;
|
||||||
Result:=Replace('end;',InsertPos,InsertPos,LastIndent,
|
Result:=Replace('end;',InsertPos,InsertPos,LastIndent,
|
||||||
@ -6038,7 +6045,9 @@ begin
|
|||||||
StartNode:=StartNode.Parent;
|
StartNode:=StartNode.Parent;
|
||||||
if not CompleteStatements(Stack) then exit;
|
if not CompleteStatements(Stack) then exit;
|
||||||
end
|
end
|
||||||
else if StartNode.Desc in AllClassSections then begin
|
else if (StartNode.Desc in AllClassSections)
|
||||||
|
or ((StartNode.Desc in AllClassSubSections) and (StartNode.Parent.Desc in AllClassSections))
|
||||||
|
then begin
|
||||||
if not CompleteClassSection(Stack) then exit;
|
if not CompleteClassSection(Stack) then exit;
|
||||||
end
|
end
|
||||||
else if StartNode.Desc in AllClassInterfaces then begin
|
else if StartNode.Desc in AllClassInterfaces then begin
|
||||||
|
Loading…
Reference in New Issue
Block a user