@@ -28,12 +28,9 @@ void SemicolonAnalyzer::Analyze(FormatState &f, const LuaSyntaxTree &t) {
2828 case EndStmtWithSemicolon::Never: {
2929 // no action needed when there's no semicolons at all!
3030 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- }
3531 if (EndsWithSemicolon (syntaxNode, t)) {
3632 RemoveSemicolon (syntaxNode, t);
33+ InsertNewLineBeforeNextNode (syntaxNode, t);
3734 }
3835 }
3936 break ;
@@ -87,31 +84,26 @@ void SemicolonAnalyzer::AddSemicolon(LuaSyntaxNode n, const LuaSyntaxTree &t) {
8784}
8885
8986void SemicolonAnalyzer::InsertNewLineBeforeNode (LuaSyntaxNode n, const LuaSyntaxTree &t) {
90- std::cout << " Called InsertNewLineBeforeNode" << std::endl;
91- std::cout << n.GetText (t) << std::endl;
9287 auto token = n.GetFirstToken (t); // line breaks are put in front of the statement itself by non-first statements
9388 if (token.IsToken (t)) {
9489 _semicolon[token.GetIndex ()] = SemicolonStrategy::InsertNewLine;
9590 }
9691}
9792
93+ void SemicolonAnalyzer::InsertNewLineBeforeNextNode (LuaSyntaxNode n, const LuaSyntaxTree& t) {
94+ auto token = n.GetNextTokenSkipComment (t);
95+ if (token.IsToken (t) && token.GetStartLine (t) == n.GetEndLine (t)) {
96+ _semicolon[token.GetIndex ()] = SemicolonStrategy::InsertNewLine;
97+ }
98+ }
99+
98100void SemicolonAnalyzer::RemoveSemicolon (LuaSyntaxNode n, const LuaSyntaxTree &t) {
99101 auto token = GetLastNonCommentToken (n, t);
100102 if (token.IsToken (t)) {
101103 _semicolon[token.GetIndex ()] = SemicolonStrategy::Remove;
102104 }
103105}
104106
105- bool SemicolonAnalyzer::IsFirstStmtOfLine (LuaSyntaxNode n, const LuaSyntaxTree &t) {
106- // check if current stmt starts on same line as the previous one ends
107- auto startCurrent = n.GetStartLine (t);
108- auto prev = n.GetPrevToken (t);
109- if (!prev.IsNull (t)) {
110- auto endPrev = prev.GetEndLine (t);
111- return endPrev < startCurrent;
112- }
113- return true ;// there's no previous token
114- }
115107
116108bool SemicolonAnalyzer::IsLastStmtOfLine (LuaSyntaxNode n, const LuaSyntaxTree &t) {
117109 // check if next stmt starts on same line as the current one ends
0 commit comments