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