Skip to content

Commit fb3b060

Browse files
authored
Merge pull request #944 from kevinhwang91/improve-postfix
feat(postfix): add templates
2 parents 8623701 + 43f774f commit fb3b060

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

script/core/completion/postfix.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,60 @@ register 'xpcall' {
133133
end
134134
}
135135

136+
register 'local' {
137+
function (state, source, callback)
138+
if source.type ~= 'getglobal'
139+
and source.type ~= 'getfield'
140+
and source.type ~= 'getmethod'
141+
and source.type ~= 'getindex'
142+
and source.type ~= 'getlocal'
143+
and source.type ~= 'call'
144+
and source.type ~= 'table' then
145+
return
146+
end
147+
local subber = subString(state)
148+
callback(string.format('local $1 = %s$0'
149+
, subber(source.start + 1, source.finish)
150+
))
151+
end
152+
}
153+
154+
register 'ipairs' {
155+
function (state, source, callback)
156+
if source.type ~= 'getglobal'
157+
and source.type ~= 'getfield'
158+
and source.type ~= 'getmethod'
159+
and source.type ~= 'getindex'
160+
and source.type ~= 'getlocal'
161+
and source.type ~= 'call'
162+
and source.type ~= 'table' then
163+
return
164+
end
165+
local subber = subString(state)
166+
callback(string.format('for ${1:i}, ${2:v} in ipairs(%s) do\n\t$0\nend'
167+
, subber(source.start + 1, source.finish)
168+
))
169+
end
170+
}
171+
172+
register 'pairs' {
173+
function (state, source, callback)
174+
if source.type ~= 'getglobal'
175+
and source.type ~= 'getfield'
176+
and source.type ~= 'getmethod'
177+
and source.type ~= 'getindex'
178+
and source.type ~= 'getlocal'
179+
and source.type ~= 'call'
180+
and source.type ~= 'table' then
181+
return
182+
end
183+
local subber = subString(state)
184+
callback(string.format('for ${1:k}, ${2:v} in pairs(%s) do\n\t$0\nend'
185+
, subber(source.start + 1, source.finish)
186+
))
187+
end
188+
}
189+
136190
register 'insert' {
137191
function (state, source, callback)
138192
if source.type ~= 'getglobal'

0 commit comments

Comments
 (0)