Skip to content

Script generator - preserve leading newline ahead of multi-line comment #194

@arvindshmicrosoft

Description

@arvindshmicrosoft

Thanks for the wonderful enhancement in #187 - did find one possible gap which users may want addressed. Consider the following example:

-- single line comment
select c1
/*
multi line comment
, c2
*/
, c3
from t1

After formatting (with [1]), the output looks like this:

-- single line comment
SELECT c1 /*
multi line comment
, c2
*/,
       c3
FROM   t1;

As you can see, the leading token for the multi-line comment was moved "up" to the previous line. Most cases where multi-line comments are used, stylistically require that the comment start token be the first column.

It would be great to have control over this behavior, with the default to have any preceding newline preserved prior to emitting the multi-line comment in the output.

[1] C# code reference

            using (var rdr = new StringReader(textBox1.Text))
            {
                IList<ParseError> errors = null;
                var parser = new TSql170Parser(true, SqlEngineType.All);
                var tree = parser.Parse(rdr, out errors);

                foreach (ParseError err in errors)
                {
                    Console.WriteLine(err.Message);
                }

                var scrGenOpts = new SqlScriptGeneratorOptions()
                {
                    PreserveComments = true
                };

                var scrGen = new Sql170ScriptGenerator(scrGenOpts);
                string formattedSQL = null;
                scrGen.GenerateScript(tree, out formattedSQL);

                textBox2.Text = formattedSQL;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions