Skip to content

Commit

Permalink
refactor(plugin): remove support for in unpacking
Browse files Browse the repository at this point in the history
Causes a lot of problems, and the actual implementation
in luaglm/cfxlua is broken.
  • Loading branch information
thelindat committed May 28, 2024
1 parent a139da0 commit cc681e7
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions plugin.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local str_find = string.find
local str_sub = string.sub
local str_gmatch = string.gmatch
local str_gsub = string.gsub

---@param uri string # The uri of file
---@param text string # The content of file
Expand Down Expand Up @@ -47,37 +46,5 @@ function OnSetText(uri, text)
}
end

-- prevent diagnostic errors from in unpacking (a, b, c in t)
-- needs better comment detection (i.e. comment blocks) to prevent nonsense changes to annotations
for comment, vars, inPos, afterInPos, tablePos, tableName, finishPos in str_gmatch(text, '(%-?%-?)([_%w, ]*)%s+()in()[ ]+()([_%w]*%s-%(?.-%)?)()') do
if comment == '' then
if tableName ~= '' and not str_find(vars, '^%s*for%s') then
-- replace 'in' with '='
count = count + 1
diffs[count] = {
start = inPos,
finish = afterInPos - 1,
text = '='
}

local tableVars = ''
vars = str_gsub(vars, '^%s*local%s', '')

-- replace 't' with 't.a, t.b, t.c'
for varName in str_gmatch(str_gsub(vars, '%s+', ''), '([_%w]+)') do
if #tableVars > 0 then tableVars = tableVars .. ',' end
tableVars = tableVars .. tableName .. '.' .. varName
end

count = count + 1
diffs[count] = {
start = tablePos,
finish = finishPos - 1,
text = tableVars
}
end
end
end

return diffs
end

0 comments on commit cc681e7

Please sign in to comment.