codetools: ComplteBlock: fixed nested proc begin

This commit is contained in:
mattias 2025-12-26 14:19:53 +01:00
parent 478a8037e7
commit c8d7a04afa
2 changed files with 46 additions and 11 deletions

View File

@ -7124,7 +7124,10 @@ var
case CursorBlock.Typ of
btBegin,btAsm:
begin
if Stack.Top=0 then
if (Stack.Top=0)
and (StartNode.Desc=ctnBeginBlock)
and ((StartNode.Parent=nil)
or (StartNode.Parent.Desc in AllSourceTypes+[ctnInterface,ctnImplementation])) then
NewCode:='end.'
else
NewCode:='end'+NewCode;

View File

@ -40,6 +40,8 @@ type
procedure TestCompleteBlock_ProgamBeginMissingEnd;
procedure TestCompleteBlockClassStart;
procedure TestCompleteBlockBegin;
procedure TestCompleteBlockProcBegin; // todo
procedure TestCompleteBlock_NestedProcBegin;
procedure TestCompleteBlockRepeatMissingUntil;
procedure TestCompleteBlockRepeatUntil;
procedure TestCompleteBlockCase;
@ -280,16 +282,46 @@ begin
+' end;'+LineEnding
+' writeln;'+LineEnding
+'end.');
{ Todo: Not implemented yet
CompleteBlock('procedure a;'+LineEnding
+'begin|'+LineEnding
+'begin'+LineEnding
+'end.',
'procedure a;'+LineEnding
+'begin|'+LineEnding
+'end;'+LineEnding
+'begin'+LineEnding
+'end.');}
end;
procedure TTestCodetoolsCompleteBlock.TestCompleteBlockProcBegin;
begin
exit; // todo
CompleteBlock(
'program '+DefUnitName+';'+LineEnding
+'procedure a;'+LineEnding
+'begin|'+LineEnding
+'begin'+LineEnding
+'end.',
'program '+DefUnitName+';'+LineEnding
+'procedure a;'+LineEnding
+'begin|'+LineEnding
+'end;'+LineEnding
+'begin'+LineEnding
+'end.');
end;
procedure TTestCodetoolsCompleteBlock.TestCompleteBlock_NestedProcBegin;
begin
CompleteBlock(
'program '+DefUnitName+';'+LineEnding
+'procedure a;'+LineEnding
+' procedure Sub;'+LineEnding
+' begin|'+LineEnding
+'begin'+LineEnding
+'end;'+LineEnding
+'begin'+LineEnding
+'end.',
'program '+DefUnitName+';'+LineEnding
+'procedure a;'+LineEnding
+' procedure Sub;'+LineEnding
+' begin|'+LineEnding
+' end;'+LineEnding
+'begin'+LineEnding
+'end;'+LineEnding
+'begin'+LineEnding
+'end.');
end;
procedure TTestCodetoolsCompleteBlock.TestCompleteBlockRepeatMissingUntil;