aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/home/.config/nvim/lua/cfg/utils.lua
diff options
context:
space:
mode:
authorLibravatar Arnold Sommerfeld <sommerfeld@strisemarx.com>2023-05-17 18:44:48 +0100
committerLibravatar Arnold Sommerfeld <sommerfeld@strisemarx.com>2023-10-18 11:16:43 +0100
commitb487984ecc61c6229cf92550030745c192fd3d0b (patch)
tree937e598c941fc1172467aeeed8ef51cbfceaca62 /home/.config/nvim/lua/cfg/utils.lua
downloaddotfiles-b487984ecc61c6229cf92550030745c192fd3d0b.tar.gz
dotfiles-b487984ecc61c6229cf92550030745c192fd3d0b.tar.bz2
dotfiles-b487984ecc61c6229cf92550030745c192fd3d0b.zip
first commit
Diffstat (limited to 'home/.config/nvim/lua/cfg/utils.lua')
-rw-r--r--home/.config/nvim/lua/cfg/utils.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/home/.config/nvim/lua/cfg/utils.lua b/home/.config/nvim/lua/cfg/utils.lua
new file mode 100644
index 0000000..abda35d
--- /dev/null
+++ b/home/.config/nvim/lua/cfg/utils.lua
@@ -0,0 +1,24 @@
+local M = {}
+local gitsigns = require("gitsigns")
+
+function M.format_hunks(options)
+ local hunks = require("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
+ end
+ end
+end
+
+return M