1

Check for comments in addition to strings

This commit is contained in:
Alex Yatskov 2024-05-02 17:35:41 -07:00
parent a9b2f24d46
commit ca45fc2fdb

View File

@ -14,11 +14,11 @@ function Cursor:is_valid()
return self.row > 0 and self.col > 0 return self.row > 0 and self.col > 0
end end
function Cursor:is_string() function Cursor:is_literal()
assert(self:is_valid()) assert(self:is_valid())
local syn_id = vim.fn.synID(self.row, self.col, false) local syn_id = vim.fn.synID(self.row, self.col, false)
local syn_attr = vim.fn.synIDattr(syn_id, 'name') local syn_attr = vim.fn.synIDattr(syn_id, 'name')
return syn_attr:find('String$') return syn_attr:find('String$') or syn_attr:find('Comment$')
end end
function Cursor.get_current() function Cursor.get_current()
@ -86,7 +86,7 @@ function BracePair:find_closest(backward)
local ignore_func = function() local ignore_func = function()
local cursor = Cursor.get_current() local cursor = Cursor.get_current()
return cursor:is_string() return cursor:is_literal()
end end
local escaped_pair = self:get_escaped() local escaped_pair = self:get_escaped()
@ -305,7 +305,7 @@ function ParamList:flush()
end end
function ParamList:update(char, brace_stack, cursor) function ParamList:update(char, brace_stack, cursor)
if not cursor:is_string() then if not cursor:is_literal() then
brace_stack:update(char) brace_stack:update(char)
if brace_stack:empty() and char == ',' then if brace_stack:empty() and char == ',' then
self:flush() self:flush()