If any code, including a comment, has a scope starter keyword in it, such as “function”, “do”, “then” or so on, the script editor will detect this and not close the outer scope when you click it.
Reproduction code:
local function name()
-- do
end
Now you can’t fold the name
function because of “do”.
This also means that comments can end a scope and be included in a fold it should not be, such as:
if true then
-- end
-- test
end
This will cause the second comment and actual end
keyword not to be folded.
Same thing goes for multi-line comment syntax.
This doesn’t just apply to comments, then
in elseif
statements that are syntactically valid can also break the function’s fold:
function main()
if true then
elseif false then
end
end
This, meanwhile, though syntactically invalid, will fold correctly:
function main()
if true then
elseif false
end
end