mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 15:59:14 +02:00
codetools: completeblock: complete case colon semicolons
git-svn-id: trunk@20122 -
This commit is contained in:
parent
ffb32090a1
commit
da88c7b562
@ -5228,6 +5228,9 @@ var
|
|||||||
NeedCompletion: Boolean;
|
NeedCompletion: Boolean;
|
||||||
InsertPos: LongInt;
|
InsertPos: LongInt;
|
||||||
NewCode: String;
|
NewCode: String;
|
||||||
|
AfterGap: TGapTyp;
|
||||||
|
FrontGap: TGapTyp;
|
||||||
|
BeautifyFlags: TBeautifyCodeFlags;
|
||||||
|
|
||||||
function EndBlockIsOk: boolean;
|
function EndBlockIsOk: boolean;
|
||||||
begin
|
begin
|
||||||
@ -5301,6 +5304,12 @@ var
|
|||||||
end;
|
end;
|
||||||
btBegin,btFinally,btExcept,btCase:
|
btBegin,btFinally,btExcept,btCase:
|
||||||
if not EndBlockIsOk then exit;
|
if not EndBlockIsOk then exit;
|
||||||
|
btCaseColon,btRepeat:
|
||||||
|
begin
|
||||||
|
// missing semicolon or until
|
||||||
|
NeedCompletion:=true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
btAsm:
|
btAsm:
|
||||||
if (CurPos.StartPos>1) and (Src[CurPos.StartPos-1]<>'@') then begin
|
if (CurPos.StartPos>1) and (Src[CurPos.StartPos-1]<>'@') then begin
|
||||||
if not EndBlockIsOk then exit;
|
if not EndBlockIsOk then exit;
|
||||||
@ -5360,9 +5369,18 @@ var
|
|||||||
if TopBlockType(Stack)=btCase then
|
if TopBlockType(Stack)=btCase then
|
||||||
BeginBlock(Stack,btCaseOf,CurPos.StartPos);
|
BeginBlock(Stack,btCaseOf,CurPos.StartPos);
|
||||||
end else if UpAtomIs('ELSE') then begin
|
end else if UpAtomIs('ELSE') then begin
|
||||||
if TopBlockType(Stack)=btCaseOf then begin
|
case TopBlockType(Stack) of
|
||||||
if not EndBlockIsOk then exit;
|
btCaseOf:
|
||||||
BeginBlock(Stack,btCaseElse,CurPos.StartPos);
|
begin
|
||||||
|
if not EndBlockIsOk then exit;
|
||||||
|
BeginBlock(Stack,btCaseElse,CurPos.StartPos);
|
||||||
|
end;
|
||||||
|
btCaseColon,btRepeat:
|
||||||
|
begin
|
||||||
|
// missing semicolon
|
||||||
|
NeedCompletion:=true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -5382,6 +5400,9 @@ var
|
|||||||
InsertPos:=CleanCursorPos;
|
InsertPos:=CleanCursorPos;
|
||||||
Indent:=CursorBlockIndent;
|
Indent:=CursorBlockIndent;
|
||||||
NewCode:='';
|
NewCode:='';
|
||||||
|
FrontGap:=gtNewLine;
|
||||||
|
AfterGap:=gtNewLine;
|
||||||
|
BeautifyFlags:=[bcfIndentExistingLineBreaks];
|
||||||
case CursorBlock.Typ of
|
case CursorBlock.Typ of
|
||||||
btBegin,btFinally,btExcept,btAsm,btCaseOf,btCaseElse:
|
btBegin,btFinally,btExcept,btAsm,btCaseOf,btCaseElse:
|
||||||
NewCode:='end;';
|
NewCode:='end;';
|
||||||
@ -5390,11 +5411,18 @@ var
|
|||||||
btTry:
|
btTry:
|
||||||
NewCode:='finally'+SourceChangeCache.BeautifyCodeOptions.LineEnd
|
NewCode:='finally'+SourceChangeCache.BeautifyCodeOptions.LineEnd
|
||||||
+'end;';
|
+'end;';
|
||||||
|
btCaseColon:
|
||||||
|
begin
|
||||||
|
NewCode:=';';
|
||||||
|
FrontGap:=gtNone;
|
||||||
|
AfterGap:=gtNone;
|
||||||
|
Include(BeautifyFlags,bcfDoNotIndentFirstLine);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
if NewCode<>'' then begin
|
if NewCode<>'' then begin
|
||||||
NewCode:=SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
NewCode:=SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
||||||
NewCode,Indent,[bcfIndentExistingLineBreaks]);
|
NewCode,Indent,BeautifyFlags);
|
||||||
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,
|
if not SourceChangeCache.Replace(FrontGap,AfterGap,
|
||||||
InsertPos,InsertPos,NewCode) then exit;
|
InsertPos,InsertPos,NewCode) then exit;
|
||||||
if not SourceChangeCache.Apply then exit;
|
if not SourceChangeCache.Apply then exit;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user