Skip to content

Place semicolon before inline comment#197

Merged
dzsquared merged 1 commit intomicrosoft:mainfrom
rwestMSFT:semicolon-in-comment
Apr 14, 2026
Merged

Place semicolon before inline comment#197
dzsquared merged 1 commit intomicrosoft:mainfrom
rwestMSFT:semicolon-in-comment

Conversation

@rwestMSFT
Copy link
Copy Markdown
Contributor

Update the Transact-SQL script generator to ensure that semicolons are correctly placed before any trailing comments (both single-line and block comments) when generating SQL scripts with preserved comments. This prevents semicolons from being included as part of a comment, which could cause issues in SQL execution or readability.

The changes introduce a new method (GenerateStatementWithSemiColon) to handle this logic, and update all relevant code paths to use it.

  • Added a new private state (_suppressTrailingComments and _suppressTrailingCommentsAfterIndex) and logic to the SqlScriptGeneratorVisitor to allow deferring the emission of trailing comments until after the semicolon is generated, ensuring the semicolon is not included in the comment text. [1] [2] [3]
  • Introduced the GenerateStatementWithSemiColon method, which generates a statement, emits the semicolon, and then emits any trailing comments. This method is now used in place of the previous approach wherever statements and their semicolons are generated.
  • Updated all statement generation locations (IfStatement, StatementList, TSqlBatch, WhileStatement) to use GenerateStatementWithSemiColon instead of the old pattern, ensuring consistent semicolon placement before comments throughout the codebase. [1] [2] [3] [4] [5]
  • Added new unit tests to verify that semicolons are placed before trailing comments for single statements, multiple statements, and block comments, and that comments are preserved as expected. These tests ensure the new behavior works correctly and guards against regressions.

(This description was generated with the assistance of Copilot.)

In addition, go through the checklist below and check each item as you validate it is either handled or not applicable to this change.

Code Changes

@dzsquared dzsquared merged commit 265ba33 into microsoft:main Apr 14, 2026
8 of 9 checks passed
@rwestMSFT rwestMSFT deleted the semicolon-in-comment branch April 14, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants