22#include " CodeFormatCore/Config/LuaStyleEnum.h"
33#include " CodeFormatCore/Format/FormatState.h"
44#include " LuaParser/Lexer/LuaTokenTypeDetail.h"
5+ #include < iostream>
56
67SemicolonAnalyzer::SemicolonAnalyzer () {
78}
@@ -25,12 +26,15 @@ void SemicolonAnalyzer::Analyze(FormatState &f, const LuaSyntaxTree &t) {
2526 break ;
2627 }
2728 case EndStmtWithSemicolon::Never: {
28- // is on same line as other statement -> needs to go on new line
29- if (!IsFirstStmtOfLine (syntaxNode, t)) {
30- InsertNewLineBeforeNode (syntaxNode, t);
31- }
32- if (EndsWithSemicolon (syntaxNode, t)) {
33- RemoveSemicolon (syntaxNode, t);
29+ // no action needed when there's no semicolons at all!
30+ if (ContainsSemicolon (syntaxNode, t)) {
31+ // is on same line as other statement -> needs to go on new line
32+ if (!IsFirstStmtOfLine (syntaxNode, t)) {
33+ InsertNewLineBeforeNode (syntaxNode, t);
34+ }
35+ if (EndsWithSemicolon (syntaxNode, t)) {
36+ RemoveSemicolon (syntaxNode, t);
37+ }
3438 }
3539 break ;
3640 }
@@ -83,6 +87,8 @@ void SemicolonAnalyzer::AddSemicolon(LuaSyntaxNode n, const LuaSyntaxTree &t) {
8387}
8488
8589void SemicolonAnalyzer::InsertNewLineBeforeNode (LuaSyntaxNode n, const LuaSyntaxTree &t) {
90+ std::cout << " Called InsertNewLineBeforeNode" << std::endl;
91+ std::cout << n.GetText (t) << std::endl;
8692 auto token = n.GetFirstToken (t); // line breaks are put in front of the statement itself by non-first statements
8793 if (token.IsToken (t)) {
8894 _semicolon[token.GetIndex ()] = SemicolonStrategy::InsertNewLine;
@@ -123,6 +129,10 @@ bool SemicolonAnalyzer::EndsWithSemicolon(LuaSyntaxNode n, const LuaSyntaxTree &
123129 return token.GetTokenKind (t) == ' ;' ;
124130}
125131
132+ bool SemicolonAnalyzer::ContainsSemicolon (LuaSyntaxNode n, const LuaSyntaxTree& t) {
133+ return n.GetChildTokens (' ;' , t).size () > 0 ;
134+ }
135+
126136LuaSyntaxNode SemicolonAnalyzer::GetLastNonCommentToken (LuaSyntaxNode n, const LuaSyntaxTree &t) {
127137 auto token = n.GetLastToken (t);
128138 switch (token.GetTokenKind (t)) {
0 commit comments