New Error with Tabs: Block after BEGIN all the way to the left
Matthew_Sontum
Posts: 26 Bronze 1
Not sure exactly which version introduced this error, but I am now seeing the following behavior:
In that the code inside the BEGIN/END block is flush with the left side of the screen, regardless of how far the IF statement is to the right. Here is another example:
It does not however, affect the statements where the formatter puts the BEGIN on the following line:
IF @Country = 'USA' BEGIN SET @FormatCode = 1; END; ELSE BEGIN SET @FormatCode = 2; END;<br>
In that the code inside the BEGIN/END block is flush with the left side of the screen, regardless of how far the IF statement is to the right. Here is another example:
IF @MatchPhysicalKey > 1 BEGIN SET @CustomerMatchKey = @MatchPhysicalKey; RETURN @@ERROR; END;
It does not however, affect the statements where the formatter puts the BEGIN on the following line:
IF @RC <> 0 BEGIN SET @ReturnMessage = 'ERROR: Unable to match on physical address'; RAISERROR(@ReturnMessage, 16, 1); RETURN @@ERROR; END;
Tagged:
Comments
Here is what is currently happening:
And here is what should be happening / what did happen in previous versions:
Before:
After:
The problem is that the SET statements have no tabs preceding them, when they should have 2 tabs each.
This is using my custom style sheet, although you can see a similar but different problem using the collapsed style sheet:
In this one it is using spaces instead of tabs, but the same problem is present on the first SET statement, in that there are no spaces or tabs.
=========
This is due to the Control Flow options they have set and the example they use in the different cases. So they have
"Place BEGIN keyword on new line" true
"Indent BEGIN END keywords" false
"Indent contents of statements" true
"Collapse statements shorter than <100> characters" true
```IF @Country = 'USA' BEGIN
SET @FormatCode = 1;
END;
ELSE BEGIN
SET @FormatCode = 2;
END;```
It's collapsing the statements because they are shorter than 100 characters - this overrides the Begin on new line and the indent contents of statements.
It does something odd though if you make "Place BEGIN keyword on new line" false but leave the others - it then indents the second SET statement which I think is probably a bug.
In their last example the content of the BEGIN/END is more than 100 chars and so it doesn't collapse it.
This also used to work as expected in a previous version of SQL Prompt, in that the statements enclosed in the BEGIN / END statements aligned with the N in the BEGIN (one tab over) Here is a sample from the last working SQL Prompt version:
Well at least it looks correct in SSMS, where a tab is equivalent to 4 spaces.
The thing I notice with your setup, if I change the Wrap after setting in Control Flow to a lower value, like 70-80, I get better behavior. I'm not sure of the interaction here, but I'll try to find an answer.
Which I think is what is looking to be done? I've attached the style and settings (extension changed to .txt so it would attach) I used where it formatted it like this.
If I'm missing something let me know (or perhaps it was fixed in the latest version?).
Kind regards,
Alex
Have you visited our Help Center?
As you can see, the SET statements have no indentation at all.
I would like to automate style checks around the style guide I posted, but until this error is addressed we cannot, since it would undo the manual fixes around this problem.
I've just updated to 9.2.9 as well and I still get it formatting correctly with my settings:
I believe this are still the settings I have attached above.
Can you try the files I have attached above to see if it works for you there? Keep a copy of your settings and style and if reverting to those settings and style then cause the issue to recur please attach them here (you may want to remove the list of servers to alias before doing so if you have any).
Kind regards,
Alex
Have you visited our Help Center?
Mathew, I think this is something with the various setting combinations you've chosen. As I mentioned above, if you play with the Control Flow, this seems to adjust things. I think the "Collapse" checkbox in this section causes issues with various other settings. Can you remove this?
Please pass this issue on to the RedGate SQL Prompt support team so that they can determine which version it started breaking in, why, and determine how to fix it.