Skip to content

Commit

Permalink
Fix formatting using trimwhitespace plugin config
Browse files Browse the repository at this point in the history
  • Loading branch information
Guldoman committed Feb 25, 2024
1 parent 5f350cb commit 35880ac
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1915,17 +1915,32 @@ function lsp.request_document_format(doc)
servers_found = true
local server = lsp.servers_running[name]
if server.capabilities.documentFormattingProvider then
local trim_trailing_whitespace = false
local trim_newlines = false
if type(config.plugins.trimwhitespace) == "table"
and config.plugins.trimwhitespace.enabled
then
trim_trailing_whitespace = true
trim_newlines = config.plugins.trimwhitespace.trim_empty_end_lines
elseif config.plugins.trimwhitespace then -- Plugin enabled with true
trim_trailing_whitespace = true
trim_newlines = true
end
local indent_type, indent_size, indent_confirmed = doc:get_indent_info()
if not indent_confirmed then
indent_type, indent_size = config.tab_type, config.indent_size
end
server:push_request('textDocument/formatting', {
params = {
textDocument = {
uri = util.touri(core.project_absolute_path(doc.filename)),
},
options = {
tabSize = config.indent_size,
insertSpaces = config.tab_type == "soft",
trimTrailingWhitespace = config.plugins.trimwhitespace or true,
tabSize = indent_size,
insertSpaces = indent_type == "soft",
trimTrailingWhitespace = trim_trailing_whitespace,
insertFinalNewline = false,
trimFinalNewlines = true
trimFinalNewlines = trim_newlines
}
},
callback = function(server, response)
Expand Down

0 comments on commit 35880ac

Please sign in to comment.