mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 01:02:41 +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)
|
||||
CreateChildNode;
|
||||
CurNode.Desc:=ctnClassPublished;
|
||||
CurNode.StartPos:=LastAtoms.GetValueAt(0).EndPos;
|
||||
if CurPos.Flag=cafEdgedBracketOpen then
|
||||
ReadGUID;
|
||||
// parse till "end" of class/object
|
||||
|
@ -43,7 +43,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileProcs, CodeToolsStrConsts, CodeCache, BasicCodeTools,
|
||||
LinkScanner, AVL_Tree, CodeBeautifier, KeywordFuncLists;
|
||||
typinfo, LinkScanner, AVL_Tree, CodeBeautifier, KeywordFuncLists;
|
||||
|
||||
type
|
||||
// Insert policy types for class parts (properties, variables, method defs)
|
||||
@ -323,6 +323,7 @@ function ForwardProcBodyInsertPolicyNameToPolicy(
|
||||
const s: string): TForwardProcBodyInsertPolicy;
|
||||
function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
|
||||
|
||||
function dbgs(g: TGapTyp): string; overload;
|
||||
|
||||
implementation
|
||||
|
||||
@ -387,6 +388,11 @@ begin
|
||||
Result:=DefaultUsesInsertPolicy;
|
||||
end;
|
||||
|
||||
function dbgs(g: TGapTyp): string;
|
||||
begin
|
||||
Result:=GetEnumName(typeinfo(g),ord(g));
|
||||
end;
|
||||
|
||||
function CompareSourceChangeCacheEntry(NodeData1, NodeData2: pointer): integer;
|
||||
var
|
||||
Entry1, Entry2: TSourceChangeCacheEntry;
|
||||
|
@ -5322,7 +5322,7 @@ var
|
||||
p: LongInt;
|
||||
begin
|
||||
if NewCode='' then exit(true);
|
||||
// avoid changing current line
|
||||
// try to avoid changing current line
|
||||
if (FrontGap=gtEmptyLine) then begin
|
||||
p:=FromPos;
|
||||
while (p>1) and (Src[p-1] in [' ',#9]) do dec(p);
|
||||
@ -5372,7 +5372,7 @@ var
|
||||
AfterGap:=gtNone;
|
||||
end;
|
||||
{$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}
|
||||
// insert
|
||||
if not SourceChangeCache.Replace(FrontGap,AfterGap,
|
||||
@ -5913,12 +5913,19 @@ var
|
||||
if CleanCursorPos<StartNode.StartPos then exit;
|
||||
LastIndent:=GetLineIndent(Src,StartNode.Parent.StartPos);
|
||||
MoveCursorToNodeStart(StartNode);
|
||||
//debugln(['CompleteClassSection ',dbgstr(copy(Src,StartNode.StartPos-10,10)),'|',dbgstr(copy(Src,StartNode.StartPos,10))]);
|
||||
Indent:=GetLineIndent(Src,CurPos.StartPos);
|
||||
if Indent<LastIndent then
|
||||
LastIndent:=Indent;
|
||||
ReadNextAtom;
|
||||
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
|
||||
ReadNextAtom;
|
||||
if CurPos.Flag=cafEqual then begin
|
||||
@ -5943,7 +5950,7 @@ var
|
||||
end;
|
||||
end else
|
||||
exit(true);
|
||||
|
||||
//debugln(['CompleteClassSection NeedCompletion=',NeedCompletion]);
|
||||
if NeedCompletion>0 then begin
|
||||
InsertPos:=NeedCompletion;
|
||||
Result:=Replace('end;',InsertPos,InsertPos,LastIndent,
|
||||
@ -6038,7 +6045,9 @@ begin
|
||||
StartNode:=StartNode.Parent;
|
||||
if not CompleteStatements(Stack) then exit;
|
||||
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;
|
||||
end
|
||||
else if StartNode.Desc in AllClassInterfaces then begin
|
||||
|
Loading…
Reference in New Issue
Block a user