Thomas Franz
  • Posts: 21
  • Joined: 6/29/2015
When I use the create region / create named feature inside a larger procedure to organize it internal (create a region for statements that belongs logical together e.g. the init, the x steps of the main part and the cleanup each with several statements), it places the -- region / -- endregion comment always in column one, even if I selected statements that starts at column 5 (or 9 or 13, if it is inside of an IF condition etc.).

It would be very nice, if you would automatical add as many spaces before the two region comments, as the first not empty / whitespace line has before it's first non-whitespace character.

Example:
currently - hardly readable without manual work

CREATE PROCEDURE dbo.test
     ( @p1         INT
     ) AS
/* just some nonsense
*/
BEGIN
--#region init
    SET NOCOUNT ON;
    DECLARE @i         INT = 1;
    DECLARE @msg       VARCHAR(100);
    CREATE TABLE #tmp (col1 INT, col2 INT, col3 INT);
    IF @p1 IS NULL SET @p1 = 1;
--#endregion init

--#region mainpart
    IF @p1 < 1 
--#region invalid parameter
        BEGIN
            SET @msg = CONCAT('@p should not be < 1')
            RAISERROR (@msg, 11, 1) WITH NOWAIT
        END
--#endregion invalid parameter
    ELSE
--#region else part
        BEGIN
            WHILE @i <= @p1
            BEGIN
                INSERT INTO #tmp (col1, col2, col3)
                VALUES (@i, @i * 2, @i * @i)

                SET @i += 1;
            END
            SELECT *
              FROM #tmp AS t
        END
--#endregion else part
--#endregion mainpart

    DROP TABLE #tmp

    RETURN 0;
END;      
GO


better:
CREATE PROCEDURE dbo.test
     ( @p1         INT
     ) AS
/* just some nonsense
*/
BEGIN
    --#region init
    SET NOCOUNT ON;
    DECLARE @i         INT = 1;
    DECLARE @msg       VARCHAR(100);
    CREATE TABLE #tmp (col1 INT, col2 INT, col3 INT);
    IF @p1 IS NULL SET @p1 = 1;
    --#endregion init

    --#region mainpart
    IF @p1 < 1 
        --#region invalid parameter
        BEGIN
            SET @msg = CONCAT('@p should not be < 1')
            RAISERROR (@msg, 11, 1) WITH NOWAIT
        END
        --#endregion invalid parameter
    ELSE
        --#region else part
        BEGIN
            WHILE @i <= @p1
            BEGIN
                INSERT INTO #tmp (col1, col2, col3)
                VALUES (@i, @i * 2, @i * @i)

                SET @i += 1;
            END
            SELECT *
              FROM #tmp AS t
        END
        --#endregion else part
    ;
    --#endregion mainpart

    DROP TABLE #tmp

    RETURN 0;
END;      
GO
SSMSBoost
  • Posts: 287
  • Joined: 6/30/2012
Thank you for proposing this. We will make it configurable in Settings.
Thomas Franz
  • Posts: 21
  • Joined: 6/29/2015
Sadly this improvement made it not into the current version (4th January 2018).

Do you have another release termin in mind for this feature?
Thomas Franz
  • Posts: 21
  • Joined: 6/29/2015
still waiting for this usefull feature...
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.