-
Notifications
You must be signed in to change notification settings - Fork 69
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
Comments
It looks like this "only" seems to happen on non- |
It looks like in sqls/internal/formatter/formatter.go Line 135 in c95deb1
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) |
Disable the lsp formatting for this language server as there's a bug currently that removes all whitespaces. See sqls-server/sqls#149
Is the problem solved? |
As per the unclosed issue / unmerged PRs, no, it's still present |
It's also removing white spaces for insert statements for me, not sure if this is expected UnformattedINSERT INTO users (
username,
password
) VALUES ($1, $2); FormattedINSERT INTO users(
username,
password
)VALUES($1,$2); |
If anybody wants to stop sqls from formatting the buffer, you can add this in the on_attach = function(client, _)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
end Here it is in context. As a bonus, here's my solution for formatting my -- This is part of a bigger function containing all of my formatters.
-- Pick what you need :)
if filetype == filetypes.sql then
if vim.fn.executable("sleek") ~= 1 then
vim.notify("sleek is not installed, skipping formatting", vim.log.levels.ERROR)
return
end
local bufnr = vim.api.nvim_get_current_buf()
local temp_file_name = vim.fn.tempname()
vim.api.nvim_buf_call(bufnr, function()
vim.cmd("silent noa write " .. vim.fn.fnameescape(temp_file_name))
end)
vim.cmd("silent !sleek " .. vim.fn.fnameescape(temp_file_name))
local temp_file = io.open(temp_file_name, "r")
if temp_file == nil then
vim.notify_once("Failed to read formatted file", vim.log.levels.ERROR)
return
end
local temp_content = temp_file:read("*all")
local formatted = vim.split(temp_content, " ")
formatted = vim.split(temp_content, "\n")
temp_file:close()
os.remove(temp_file_name)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, formatted)
return
end Here it is in context. Basically it's copying the current buffer's content to a temporary buffer, formats it, reads it, replaces the current buffer's content with the formatted output. |
it' broken, see sqls-server/sqls#149
still exist |
Expected Behavior
Actual Behavior
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: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
The text was updated successfully, but these errors were encountered: