Skip to content

Commit

Permalink
fix: handle windows line endings (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 21, 2024
1 parent cbc5745 commit 9a785eb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/conform/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ M.show_window = function()
f:seek("end", context)
local text = f:read("*a")
f:close()
local log_lines = vim.split(text, "\n", { plain = true, trimempty = true })
local log_lines = vim.split(text, "\r?\n", { trimempty = true })
for i = 2, #log_lines do
table.insert(lines, string.rep(" ", 10) .. log_lines[i])
end
Expand Down
2 changes: 1 addition & 1 deletion lua/conform/lsp_format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function apply_text_edits(text_edits, bufnr, offset_encoding, dry_run)
and text_edits[1].range["end"].character == 0
then
local original_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
local new_lines = vim.split(text_edits[1].newText, "\n", { plain = true })
local new_lines = vim.split(text_edits[1].newText, "\r?\n", {})
-- If it had a trailing newline, remove it to make the lines match the expected vim format
if #new_lines > 1 and new_lines[#new_lines] == "" then
table.remove(new_lines)
Expand Down
2 changes: 1 addition & 1 deletion lua/conform/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ local function run_formatter(bufnr, formatter, config, ctx, input_lines, opts, c
local stat = assert(uv.fs_fstat(fd))
local content = assert(uv.fs_read(fd, stat.size))
uv.fs_close(fd)
output = vim.split(content, "\n", { plain = true })
output = vim.split(content, "\r?\n", {})
else
output = stdout
end
Expand Down

0 comments on commit 9a785eb

Please sign in to comment.