Skip to content

Commit 417d457

Browse files
authored
Merge pull request #187 from Koihik/dev
fix: avoid break line before shorter explist
2 parents 57b7f96 + 5a59bf5 commit 417d457

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ if(NOT "${TEST_COMPILE_RESULT}" OR (NOT "${TEST_RUN_RESULT}" EQUAL 0))
6161
message(FATAL_ERROR "Your compiler does not fully support the C++17 standard and libraries")
6262
endif()
6363

64+
if( ${CMAKE_BUILD_TYPE} MATCHES "Debug")
65+
add_definitions(-DDEBUG)
66+
endif()
6467

6568
include_directories(
6669
${PROJECT_SOURCE_DIR}/generated/

src/FormatVisitor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
using namespace antlr4;
1010

11-
// #define LOG_FLAG
1211
// #define LOG_FUNC_VISIT
1312

14-
#ifdef LOG_FLAG
13+
#ifdef DEBUG
1514

1615
static int logIndentSize = 0;
1716
static std::string LOG_INDENT = " ";
@@ -50,7 +49,7 @@ void func_end(std::string funcName) {
5049
#endif
5150

5251
void print_cost() {
53-
#ifdef LOG_FLAG
52+
#ifdef DEBUG
5453
for (auto p : countMp) {
5554
std::cout << p.first << " called " << p.second << " times" << std::endl;
5655
}
@@ -891,7 +890,8 @@ antlrcpp::Any FormatVisitor::visitExplist(LuaParser::ExplistContext* ctx) {
891890
// var:foo(xxxx .. xxxx) -- no break
892891
// longlonglonglongvar:foo(
893892
// xxxx .. xxxx) -- break
894-
if (lines > 1 && cur_columns() > config_.get<int>("column_limit") / 2) {
893+
int column_limit = config_.get<int>("column_limit");
894+
if (lines > 1 && cur_columns() > column_limit / 2 && expLength >= column_limit / 4) {
895895
beyondLimit = true;
896896
}
897897
if (!functioncallLpHasBreak_.empty() && functioncallLpHasBreak_.back()) {

test/test_format_file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-104.lua");
8383
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-156.lua");
8484
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-162.lua");
8585
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-168.lua");
86+
TEST_FILE(PROJECT_PATH "/test/testdata/issues/issue-186.lua");
8687

8788
TEST_FILE(PROJECT_PATH "/test/testdata/issues/PR-100.lua");
8889
TEST_FILE(PROJECT_PATH "/test/testdata/issues/PR-108.lua");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
self.buf, self.win, self.buf_closer = floatbuf({
2+
win_width = self.rect.width,
3+
win_height = self.rect.height,
4+
x = self.rect.pos_x,
5+
y = self.rect.pos_y,
6+
loc = loc,
7+
prompt = self.prompt,
8+
enter = opts.enter,
9+
ft = opts.ft,
10+
syntax = opts.syntax,
11+
relative = opts.relative
12+
})

test/testdata/issues/issue-186.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
self.buf, self.win, self.buf_closer = floatbuf({
2+
win_width = self.rect.width,
3+
win_height = self.rect.height,
4+
x = self.rect.pos_x,
5+
y = self.rect.pos_y,
6+
loc = loc,
7+
prompt = self.prompt,
8+
enter = opts.enter,
9+
ft = opts.ft,
10+
syntax = opts.syntax,
11+
relative = opts.relative
12+
})

0 commit comments

Comments
 (0)