Update the Script Workspace Layout Algorithm so Indenting reflects the actual state of the code

Idea created by Malcolm on Nov 4, 2015
    Active
    Score2
    • ThomasBauer
    • Markus Schneider

    Summary: We want the indenting algorithm to recognise that disabled lines are comments and have no effect on the code structure.

     

    I'll describe the circumstances so that you can see what the use case is.

     

    I have nested if statements:

     

    if ( x = y )

         if (  complex calc )

              if ( a = b )

                   # many lines of code

                   if ( old conditions )

                        # many lines of code

                   else if ( new conditions )

                   end if

              end if

         else

              if ( old conditions )

              else if ( new conditions )

              end if

         end if

    end if

     

    The conditions affecting the complex calculation have changed and we need to adjust it. We know how it works, what results it produces and what the new conditions are that it does not address. So, we duplicate the line of code and disable one of them. We intend to test a new complex calculation. The success or failure of the new calculation will push us many lines below. We are using breakpoints to facilitate debugging. When we begin testing we notice that the structure of the code is odd. It is suggesting that there is a problem, yet the script was parsed and saved, so it should be correct. What is happening?

     

    When we duplicate the line "if  ( complex calc )" the script workspace modifies the indentation of all subsequent lines. That is expected and desirable. When we disable one of the lines, we expect the disabled line to be treated as a comment and ignored by the layout algorithm. However, the algorithm that is used to determine indentation ignores the disabled flag and lays out the code as if the line was active. That is not expected and is undesirable behaviour.

     

    The effect of the behaviour is this, when we are many lines below the disabled line the indentation of the code is wrong. It is extremely misleading and may cause the developer to make changes which are undesirable, breaking the code.

     

    We simply want the indenting algorithm to recognise that disabled lines are commented out, that they have no effect on the code structure, and the code should be laid out accordingly.