Script Editor: Folding does not work properly when keywords in comments or elseif is involved


#1

Hey there,

Using the word ‘then’ in a comment will always cause the editor to create a fold. When you close said fold you may have some trouble opening it back up again. This shouldn’t be the case - regular single line comments do not require folds; they’re a single line.

There are other issues with the editor regarding folding, such as ‘elseifs’ folding away more script than it needs to or not folding anything at all, I think it stems from the fact that the word ‘then’ automatically creates a fold regardless of if it’s needed.

It’s been a few months now and this is still an issue.
I think what is happening is that the last ‘then’ will fold everything up until the first end is found (even if it’s in a comment), and if there are multiple 'then’s between the first and the ‘end’ operator, the latter will just override all of them making them completely obsolete, rather than folding the script between the two 'then’s if that makes sense.

It would be expected that a script like:

Script Example
if (i == 1) then
    print("1")
elseif (i == 2) then
    print("2")
elseif (i == 3) then
    print("3");
else
    print("4 or 5");
end;

would fold like this:

Expected Fold Behaviour
if (i == 1) then
elseif (i == 2) then
elseif (i == 3) then
else

not like this.

Current Fold Behaviour
if (i == 1) then
    print("1")
elseif (i == 2) then
    print("2");
elseif (i == 3) then

Many thanks,
Richard.

**Edit. The word do does this too even if it’s part of a string.


[100%] Scope declaration words are opening new tabs in Script Editor, regardless of placement
Code folding not ignoring strings
Code folding not ignoring strings
[100%] Scope declaration words are opening new tabs in Script Editor, regardless of placement
#2

This is not just related to then, all scope creating keywords will do this. This is a problem for any comments which have do, then, function, and more. It’d be nice if this could be fixed by adjusting the regular expressions to account for valid Lua syntax.

This code won’t fold:

local function name()
	-- do
end

This also effects the scope ending keywords end and until, by folding the scope early:

function main()
	repeat
		--until 
                -- this isn't folded
	until
end

This scope is ended early too:

function main()
	-- end
end

#3

I just noticed this today. I don’t know if it’s existed in previous versions.

Code folding is supposed to occur when blocks of code exist. Such blocks are indicated by things like the “do” keyword, or parentheses spanning multiple lines. However, the system does not seem to ignore strings. Therefore, if you use keywords such as “do” or “then” in a string, it will trigger code folding for the given line.

See the example below:


#4

Function spelled incorrectly:
image

Function spelled correctly:
image

Notice that the word function is contained within a string. Spelling function wholly opens a new tab, while spelling it incorrectly disables the tab. Each instance of the word function is recognised as the opening of a new scope. Obviously, this is not intended behaviour, because there is no actual scope being opened.

I can currently silence the error by adding end for each instance of function, regardless of how it appears. Right now, I’ve done it in comments.

image

The commented end statements remove the new tabs.

This issue is observable with other words and circumstances as well. Encapsulate statements that open scopes with quotes or begin the line with a comment and observe the problem occur.

image

This problem has an 100% occurrence rate on Script Editor. I am quite unsure of when this started occurring, however I only took notice to its presence today.

Potentially related threads:
https://devforum.roblox.com/t/script-editor-incorrectly-auto-indents-some-if-statements/218701
https://devforum.roblox.com/t/pressing-enter-on-an-end-statement-causes-a-tab-to-be-added/163962

(cc @IcyTides)


#5

Thank god someone actually figured out why this is happening. Debugging the root cause is the hardest part of fixing an obscure bug like this. Which is probably why we’ve been forced to endure this annoying bug for almost a year.

Hopefully it can be fixed now!

edit: looks like a staff member already ninja’d this?


#6

Looks more like they’re referencing if/else statements, quotations and strange indentation behaviour. That’s improper indentation though, no new scopes are actually being visually opened. The post I made doesn’t happen with just “]]”, it happens with standard " quotes and comments as well.


#7

Hey Everyone,
Though the elseif/else indentation issue was solved recently, the “do/function/then” keyword in comments or quotes indentation bug does still exist. An issue has been filed and we will be fixing this bug as soon as we can.