Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CodeFormatCore/src/Format/Analyzer/LineBreakAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "CodeFormatCore/Format/FormatState.h"
#include "LuaParser/Lexer/LuaTokenTypeDetail.h"
#include <algorithm>
#include <cstdio>
Comment thread
notpeter marked this conversation as resolved.
Outdated

using NodeKind = LuaSyntaxNodeKind;

Expand Down Expand Up @@ -107,8 +108,14 @@ void LineBreakAnalyzer::ComplexAnalyze(FormatState &f, const LuaSyntaxTree &t) {

} else {
switch (stmt.GetTokenKind(t)) {
case TK_SHORT_COMMENT:
case TK_LONG_COMMENT:
{
auto nextToken = stmt.GetNextToken(t).GetTokenKind(t);
if (nextToken == TK_SHORT_COMMENT) {
break;
}
}
Comment thread
notpeter marked this conversation as resolved.
case TK_SHORT_COMMENT:
case TK_SHEBANG: {
BreakAfter(stmt, t, style.line_space_after_comment);
break;
Expand Down
28 changes: 28 additions & 0 deletions Test/src/FormatResult_unitest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,3 +1147,31 @@ only_latin = {
}
)", style));
}

TEST(Format, issue_170) {
EXPECT_TRUE(TestHelper::TestFormatted(
R"(
--[[]]
)",
R"(
--[[]]
)"));
EXPECT_TRUE(TestHelper::TestFormatted(
R"(
--[[]]--
)",
R"(
--[[]] --
)"));
EXPECT_TRUE(TestHelper::TestFormatted(
R"(
--[[-----------

]]-------------
)",
R"(
--[[-----------

]] -------------
)"));
}