microsoft / vscode-mssql

Visual Studio Code SQL Server extension.
Other
1.52k stars 455 forks source link

Inconsistent with snippets #17453

Open moritztim opened 1 year ago

moritztim commented 1 year ago

Problem Summary

MSSQL Extension Version: v1.16.0
VSCode Version: `1.71.2 74b1f979648cc44d385a2286793c226e611f59e7 x64`

The snippets provided by the extension are formatted differently than the formatter formats. I also think the formatting in this case makes no sense.

demonstration

Formatter Settings

default

Input Text - place unformatted SQL below sqlCreateDataBase

-- Create a new database called 'DatabaseName'
-- Connect to the 'master' database to run this snippet
USE master
GO
-- Create the new database if it does not exist already
IF NOT EXISTS (
    SELECT name
        FROM sys.databases
        WHERE name = N'DatabaseName'
)
CREATE DATABASE DatabaseName
GO

Actual Output - place formatted SQL (that doesn't work as expected) below

-- Create a new database called 'DatabaseName'
-- Connect to the 'master' database to run this snippet
USE master
GO
-- Create the new database if it does not exist already
IF NOT EXISTS (
    SELECT name
FROM sys.databases
WHERE name = N'DatabaseName'
)
CREATE DATABASE DatabaseName
GO

Expected Output - place formatted SQL as you'd expect it to look below

-- Create a new database called 'DatabaseName'
-- Connect to the 'master' database to run this snippet
USE master
GO
-- Create the new database if it does not exist already
IF NOT EXISTS (
    SELECT name
        FROM sys.databases
        WHERE name = N'DatabaseName'
)
CREATE DATABASE DatabaseName
GO
moritztim commented 1 year ago

This is also described in #1800 but here you can see that the formatting in the snippet is actually sensible therefore there really is a mistake with subqueries and not an indentation preference