Add MultilineCaseExpression script generator option - #233
trg-alasdair wants to merge 1 commit into
Conversation
A CASE expression is always generated on one line, so a multi-branch CASE becomes a single long line, and a WHEN predicate joined by AND breaks under MultilineWherePredicatesList with the next WHEN appended after its continuation, producing a staircase. MultilineCaseExpression (default false) writes each WHEN clause and the ELSE on its own line, indented one level from CASE, and END on its own line aligned with CASE. It applies to simple and searched CASE. The alignment point is pushed only when the option is on, so the default output is unchanged. A trailing single-line comment on a branch now stays on that branch's line, because the deferred comment is flushed at the next line break.
|
@microsoft-github-policy-service agree [company="{TRG Arts}"] |
|
@microsoft-github-policy-service agree company="TRG Arts" |
|
trg-alasdair please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
1 similar comment
|
trg-alasdair please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Description
Fixes #226.
SqlScriptGeneratoralways writes aCASEexpression on one line. A multi-branchCASEbecomes one long line, and when aWHENpredicate containsAND,MultilineWherePredicatesListbreaks it and appends the nextWHENafter the continuation, which produces the staircase shown in the issue.This adds
MultilineCaseExpression(defaultfalse). When it istrue, eachWHENclause and theELSEare written on their own line, indented one level fromCASE, andENDis written on its own line aligned withCASE:CASE, wherever the expression appears. A nestedCASEaligns with its ownCASEkeyword.CASEstays on theCASEline.WHENpredicates keep their existing behavior underMultilineWherePredicatesList. Because eachWHENnow starts its own line, the continuations no longer compound.The setting is in
SqlScriptGeneratorOptions.xmlin a new "CASE expressions" group, and the generator change is confined toSqlScriptGeneratorVisitor.CaseExpression.cs.This change was written with the help of an AI coding assistant, and I reviewed and tested it.
Code Changes
CaseExpressionFormattingTests(12 tests), covering the default, simple and searchedCASE, noELSE, a single branch, nesting,COLLATE,IndentationSize, a trailing comment, and the example from Add a Multiline option for CASE expressions (WHEN/THEN/ELSE on their own lines) #226 with otherwise-default optionsUTSqlScriptDomon net8.0 (macOS)