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

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.

12 Likes

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
2 Likes

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:

5 Likes

Function spelled incorrectly:

Function spelled correctly:

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.

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:

(cc @IcyTides)

8 Likes

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?

4 Likes

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.

1 Like

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.

2 Likes

Bumping this because this is extremely annoying and needs to be fixed. (Screenshot by Lightshot)

3 Likes

Is there any new information about this bug, is there a plan to fix this and/or is it being fixed?

It’s been almost 10 months and this is still occurring and it’s incredibly annoying and tedious to script games when you can’t organize your script with folds.

4 Likes

Another folding bug: https://gyazo.com/f9951b4a13daa67a5febff325e62cbd6 crashes studio
Along with the other fold bug, this should be fixed

I would like to bump this. I am still relatively new to the Roblox Studio Platform and API (2 years) My game is heavy in modules and I am trying to clean them up. So I’m combining them together. I’ve worked with other engines and this glitch (how I’ve come to deal with it) well, It’s undesirable to have scripts that collapse so strangely. I’ve tried removing all scope creating keywords and that still didn’t help. Edit: I even removed the whole comment

I would like to put my ‘vote’ in to have this fixed, please :slight_smile:

I’m going to bump this since most of these still are not fixed, and raise another issue.

Using “]]” anywhere, will cause indentation to close.

local table1 = {"a", "b", "c"}
local table2 = {1, 2}
-- This causes indention, because it found ]]
table1[table2[1]]

The code that handles indentation, seems to just search for a keyword or phrase, without consideration of the context, which is why the strings, comments and brackets (as above) will have indentation triggered. Of course I could just do

local index = table2[1]
table1[index]

but this is just a QoL.

1 Like

BUMP. this is an ancient bug. i first noticed it when trying to put “do” in a string, and it created a fold inside my table. get this done, its causing a disruption and has been forever. thanks.

1 Like

There’s currently a fix for this issue in beta. It should resolve the issue when it’s released.

If you have access (it hasn’t been announced as a beta so I assume it might be restricted to the old beta list still), it should be named something like “Script editor folding behavior changes”. If not, have patience!

1 Like