-
Notifications
You must be signed in to change notification settings - Fork 399
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
Formatting comments, new lines are not kept #50
Comments
I'm also noticing one more case that ends up eating my statement terminator semicolon: Query:
Expected:
Actual:
@mtxr I'm happy to help fix, have you worked on this at all? |
Digging into the code on this, I do not think that my issue is related to this. My issue happens because sql-formatter removes whitespace, including newlines, when adding the semicolon at the end of the line. For what it's worth, I don't see evidence to support that sql-formatter while preserve multiple line breaks between any token that it parses. Your desired output may require sql-formatter to be more flexible with preserving existing whitespace in some cases. |
Formatting of comments is a tricky thing in general. At the moment sql-formatter tries to place all line-comments at the end of the preceding code. An alternative would be to always put the comment on a line of its own, but of course that would then break those comments that were meant to be on the same line as code. I think to properly solve it, we'll need to distinguish at parse time between comments between code and on the same line as code, and then format them accordingly in output. Then you could get the following: SELECT
*
FROM
user;
-- RESET ALL PASSWORD REQUESTS
UPDATE
user
SET
password_requested_at = NULL,
confirmation_token = NULL; Another problem (exemplified above) is that sql-formatter doesn't really understand multiple SQL queries. Originally it was built to solve the task of formatting just a single query. We'll need to teach it, that SELECT
*
FROM
user;
-- RESET ALL PASSWORD REQUESTS
UPDATE
user
SET
password_requested_at = NULL,
confirmation_token = NULL; So yeah. I'd consider it definitely a bug. But it requires quite a bit of work. |
The simpler approach is to first implement the understanding of multiple queries. Perhaps it can be as simple as just whenever we see That could solve the concrete issue brought up in this ticket. Though issues with comments inside queries would still remain. But I'd suspect comments between queries to be more common use case. |
Tested on 2.3.2: -- This is the first statement
select * from foo where color = "purple";
-- This is the second statement
select * from foo join bar on foo.id = bar.foo_id where bar.count > 100; -- This is the first statement
select
*
from
foo
where
color = "purple";-- This is the second statement
select
*
from
foo
join bar on foo.id = bar.foo_id
where
bar.count > 100; |
@zeroturnaround any updates on this? |
select col1, col2 expected output actual output there's a space btn the dash lines in my output, making the comments to be invalid sql comments |
Would love more than one newline between statements in general. |
This should be fixed now with the 3.1.0 release. |
Here: mtxr/vscode-sqltools#97
The text was updated successfully, but these errors were encountered: