Skip to content

Commit fe5239b

Browse files
committed
Outdent line after an anon func argument
Fix anonymous function argument causes following line to be incorrectly indented. Add tests: indented chained functions: worked before and still works indented chained anonymous function arguments: broken before and now works
1 parent fa810f8 commit fe5239b

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

indent/lua.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ function GetLuaIndent()
120120
let i = -1
121121
endif
122122

123+
" special case: end}) -- line after end of call w/ anon func should outdent again
124+
if i >= 0 && contents_prev =~# s:anon_func_end
125+
let i -= 1
126+
endif
127+
123128
" restore cursor
124129
call setpos(".", original_cursor_pos)
125130

test/indent.vader

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Before:
2+
setlocal expandtab shiftwidth=4 tabstop=4
3+
4+
Given lua (chained functions):
5+
if true then
6+
local data = self.kitchen
7+
:getCheese()
8+
:enjoyCheese(self
9+
:getHead()
10+
:getMouth())
11+
end
12+
13+
Do (reindent):
14+
gg=G
15+
16+
Expect lua (indented):
17+
if true then
18+
local data = self.kitchen
19+
:getCheese()
20+
:enjoyCheese(self
21+
:getHead()
22+
:getMouth())
23+
end
24+
25+
Given lua (chained anonymous function arguments):
26+
if false then
27+
local data = self.kitchen
28+
:eatCheese({fn = function()
29+
return 10
30+
end})
31+
:digestCheese(function()
32+
return 1
33+
end)
34+
35+
self:Func()
36+
end
37+
38+
Do (reindent):
39+
gg=G
40+
41+
Expect lua (indented):
42+
if false then
43+
local data = self.kitchen
44+
:eatCheese({fn = function()
45+
return 10
46+
end})
47+
:digestCheese(function()
48+
return 1
49+
end)
50+
51+
self:Func()
52+
end
53+

0 commit comments

Comments
 (0)