1
This commit is contained in:
Alex Yatskov 2024-04-25 20:44:39 -07:00
parent 72ac7e3dff
commit a74c1b5c33

View File

@ -224,6 +224,7 @@ function Param.new(text, pair)
local param = { local param = {
text = text, text = text,
pair = pair, pair = pair,
offset = nil,
} }
return setmetatable(param, Param.mt) return setmetatable(param, Param.mt)
@ -233,8 +234,12 @@ function Param:append(char)
self.text = self.text .. char self.text = self.text .. char
end end
function Param:flush() function Param:capture()
self.text = self.text:match('^%s*(.-)%s*$') self.offset = #self.text
end
function Param:stripped()
return self.text:match('^%s*(.-)%s*$')
end end
-- --
@ -255,7 +260,6 @@ end
function ParamList:flush() function ParamList:flush()
if self.current then if self.current then
self.current:flush()
table.insert(self.parsed, self.current) table.insert(self.parsed, self.current)
self.current = nil self.current = nil
end end
@ -275,6 +279,10 @@ function ParamList:update(char, brace_stack, range, cursor)
else else
self.current = Param.new(char, range) self.current = Param.new(char, range)
end end
if cursor == Cursor.get_current() then
self.current:capture()
end
end end
function ParamList:parse(range) function ParamList:parse(range)
@ -357,9 +365,9 @@ function WrapContext:wrap()
if not first_param then if not first_param then
line = line .. ', ' line = line .. ', '
end end
line = line .. param.text line = line .. param:stripped()
else else
line = line .. self.indent .. self.opt.line_prefix .. param.text line = line .. self.indent .. self.opt.line_prefix .. param:stripped()
if not last_param or self.opt.tail_comma then if not last_param or self.opt.tail_comma then
line = line .. ',' line = line .. ','
end end
@ -391,7 +399,7 @@ function WrapContext:unwrap()
local line = self.indent .. self.prefix local line = self.indent .. self.prefix
for i, param in ipairs(self.params.parsed) do for i, param in ipairs(self.params.parsed) do
line = line .. param.text line = line .. param:stripped()
if i < #self.params.parsed then if i < #self.params.parsed then
line = line .. ', ' line = line .. ', '
end end