Wish Wish: Smarter collapse in IDE code editor

Troberg

Well-Known Member
Licensed User
Longtime User
As it works today, I can collapse methods and I can add regions.

That's nice, but I'd like to see it taken one step further. I'd like to be able to collapse other language structures such as loops and ifs, much like, for example, Visual Studio does.

However, I'd like to take it one more step further. When collapsed, the line representing the collapsed block of code should be shown as any comment on that line, or just the line if there is no comment. This bit is something I've not seen someone do yet, but it would be immensely useful.

Example:

B4X:
For f=0 to numfiles 'Delete all the files
    Lots of code here
    ...
Next

would collapse to:

B4X:
Delete all the files

However, this:

B4X:
For f=0 to numfiles
    Lots of code here
    ...
Next

would collapse to:

B4X:
For f=0 to numfiles

Of course, indentation levels should be preserved.

With good comments, and most of the code collapsed, the code would read like a pretty clean plaintext description of what's done, with almost no extra effort.

Example of what the end result could look like collapsed:

B4X:
Sub DeleteLotsOfFiles(path as string)
    If arguments are good
        Ask user for confirmation
        If user confirmed
            Read files in dir
            Delete all the files
        Else exit cleanly
    Else bad arguments, exit with error
End Sub

It doesn't matter if each collapsed block is long and complicated, you still get a clear, concise picture of what the code does.

(Yes, I know the example above should be broken down in sub-methods, but it's just an example. I kept it simple so that it's easy to understand. I'm sure you all could imagine some horribly complicated operation that's too cumbersome to break down.)
 

Troberg

Well-Known Member
Licensed User
Longtime User
Some further thoughts on this. Could we take this even further?

What if any line that has a comment could be collapsed to only show the comment?

Say, for example, that I have a line like this:

B4X:
bar.Progress = 100 * ((PosSelf1/PossibleSelf1.Size)+((PosOpponent1/PossibleOpponent1.Size)/PossibleSelf1.Size)) 'Update progressbar

That line is pretty inconsequential to what I'm actually doing, it's just some stuff to keep the user informed that I'm doing something. So, I don't want that long line that doesn't affect what I'm actually doing to clutter things up. So, say that the editor allows it to be collapsed, just like a region (or a construct, as described in the previous post). When collapsed, all I would need to see is:

B4X:
'Update progessbar

See it as an implicit #Region, created on every construct (if/elseif/else, for, select/case, do et cetera) and on every line that has a comment. Neat, eh?
 

LucaMs

Expert
Licensed User
Longtime User
I would not like collapsing loops or selects/if blocks. Also I try to avoid putting the comments at the end of the lines, I want to read everything without having to scroll the page.

Rather I'd like to have a list of the Regions, in the tab Modules.
 

Troberg

Well-Known Member
Licensed User
Longtime User
Well, I have a large screen (3849x2160), so long lines are not a problem for me.

Also, nothing should collapse automatically, it's up to you to collapse or expand.
 
Top