Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqls formating removes all whitespaces #149

Open
594212 opened this issue Apr 13, 2024 · 4 comments · May be fixed by #165
Open

sqls formating removes all whitespaces #149

594212 opened this issue Apr 13, 2024 · 4 comments · May be fixed by #165

Comments

@594212
Copy link

594212 commented Apr 13, 2024

Expected Behavior

CREATE TABLE accounts (
  user_id SERIAL PRIMARY KEY, 
  username VARCHAR (50) UNIQUE NOT NULL, 
  password VARCHAR (50) NOT NULL, 
  email VARCHAR (255) UNIQUE NOT NULL, 
  created_at TIMESTAMP NOT NULL, 
  last_login TIMESTAMP
);

Actual Behavior

CREATETABLEaccounts(
    user_id SERIALPRIMARYKEY,
    usernameVARCHAR(
        50
    )UNIQUENOTNULL,
    passwordVARCHAR(
        50
    )NOTNULL,
    emailVARCHAR(
        255
    )UNIQUENOTNULL,
    created_atTIMESTAMPNOTNULL,
    last_loginTIMESTAMP
);

I'm not sure how it started, I was using nvim and setting up for postgres with lsqconfig,
because I have same issue,for work around I added to ~/.config/sqls/config.yml following:

# Set to true to use lowercase keywords instead of uppercase.
lowercaseKeywords: false
connections:
  - alias: psql
    driver: postgresql
    dataSourceName: 'host=127.0.0.1 port=5432 user=postgres password=secret dbname=testdb sslmode=disable'

it's clearly not related to error, but after that in some point, formatter started going crazy. Now I removed all configs from every corner but this bug persists

@jamietanna
Copy link

It looks like this "only" seems to happen on non-insert and non-selects, which includes a lot of queries 🤔

@jamietanna
Copy link

It looks like in

func formatItem(node ast.Node, env *formatEnvironment) ast.Node {
we're not matching i.e. CREATE or VARCHAR.

I can see a diff like so:

diff --git internal/formatter/formatter.go internal/formatter/formatter.go
index 15cbf96..e17d485 100644
--- internal/formatter/formatter.go
+++ internal/formatter/formatter.go
@@ -144,6 +144,8 @@ func formatItem(node ast.Node, env *formatEnvironment) ast.Node {
                        "LIMIT",
                        "WHEN",
                        "ELSE",
+                       "CREATE",
+                       "TABLE",
                },
        }
        if whitespaceAfterMatcher.IsMatch(node) {

Will start to do this correctly, but not sure if we want to allowlist each keyword + combination? (I realise that's how it's currently already done)

@jamietanna jamietanna linked a pull request Aug 15, 2024 that will close this issue
asadmoosvi added a commit to asadmoosvi/nvim that referenced this issue Sep 9, 2024
Disable the lsp formatting for this language server as there's a bug
currently that removes all whitespaces. See sqls-server/sqls#149
@A404M
Copy link

A404M commented Oct 3, 2024

Is the problem solved?

@jamietanna
Copy link

As per the unclosed issue / unmerged PRs, no, it's still present

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 a pull request may close this issue.

3 participants