diff options
author | sommerfeld <sommerfeld@sommerfeld.dev> | 2024-05-20 17:08:02 +0100 |
---|---|---|
committer | sommerfeld <sommerfeld@sommerfeld.dev> | 2024-05-20 17:08:02 +0100 |
commit | 079c385b9bd40a73ebafae6d847f62c2bed5126c (patch) | |
tree | 95d5e270ac7dab639fe7bca9b7a02041bfadfa47 /home/.config/nvim/lua/cfg/utils.lua | |
parent | 1d6fe632512eca513dab6a8868298df638e50e5e (diff) | |
download | dotfiles-079c385b9bd40a73ebafae6d847f62c2bed5126c.tar.gz dotfiles-079c385b9bd40a73ebafae6d847f62c2bed5126c.tar.bz2 dotfiles-079c385b9bd40a73ebafae6d847f62c2bed5126c.zip |
[nvim] Rewrite config motivated by nvim 0.10
Diffstat (limited to 'home/.config/nvim/lua/cfg/utils.lua')
-rw-r--r-- | home/.config/nvim/lua/cfg/utils.lua | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/home/.config/nvim/lua/cfg/utils.lua b/home/.config/nvim/lua/cfg/utils.lua index abda35d..7cd172a 100644 --- a/home/.config/nvim/lua/cfg/utils.lua +++ b/home/.config/nvim/lua/cfg/utils.lua @@ -1,22 +1,21 @@ local M = {} local gitsigns = require("gitsigns") +local conform = require("conform") function M.format_hunks(options) - local hunks = require("gitsigns").get_hunks() + local hunks = gitsigns.get_hunks() if not hunks or vim.tbl_isempty(hunks) then return end for _, hunk in ipairs(hunks) do - local added = hunk.added - if added then - local start_line = added.start - local count = added.count - if start_line and count and start_line > 0 and count > 0 then - local end_line = start_line + added.count - 1 - local range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } } - options = vim.tbl_extend("force", { range = range }, options or {}) - vim.lsp.buf.format(options) - end + if hunk and hunk.added then + local start = hunk.added.start + local last = start + hunk.added.count + -- nvim_buf_get_lines uses zero-based indexing -> subtract from last + local last_hunk_line = vim.api.nvim_buf_get_lines(0, last - 2, last - 1, true)[1] + local range = { start = { start, 0 }, ["end"] = { last - 1, last_hunk_line:len() } } + options = vim.tbl_extend("force", { range = range, lsp_fallback = true, quiet = true }, options or {}) + conform.format(options) end end end |