1
0
Fork 0

nvim: Fix statuscolmn/gitsigns

This commit is contained in:
Daniel Kempkens 2023-10-22 02:00:49 +02:00
parent c0ced35d15
commit 2c96318bd1
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
3 changed files with 38 additions and 21 deletions

View file

@ -7,6 +7,7 @@
statusline (require :nifoc.statusline) statusline (require :nifoc.statusline)
diagnostic vim.diagnostic diagnostic vim.diagnostic
gitsigns (require :gitsigns) gitsigns (require :gitsigns)
gitsigns-ns (api.nvim_create_namespace :gitsigns_extmark_signs_)
augroup (vim.api.nvim_create_augroup :NifocStatuscolumn {:clear true}) augroup (vim.api.nvim_create_augroup :NifocStatuscolumn {:clear true})
aucmd vim.api.nvim_create_autocmd] aucmd vim.api.nvim_create_autocmd]
;; Cache ;; Cache
@ -27,11 +28,12 @@
ret-tab)) ret-tab))
(fn clear-diagnostics-cache! [bufnr diagnostics] (fn clear-diagnostics-cache! [bufnr diagnostics]
(if (vim.tbl_isempty diagnostics) (tset cache :diagnostics bufnr nil)
(let [namespaces (vim.tbl_map #$1.namespace diagnostics) (let [namespaces (vim.tbl_map #$1.namespace diagnostics)
current-cache (. cache :diagnostics bufnr) current-cache (. cache :diagnostics bufnr)
new-cache (cache-filter #(not (vim.tbl_contains namespaces $1.ns)) new-cache (cache-filter #(not (vim.tbl_contains namespaces $1.ns))
current-cache)] current-cache)]
(tset cache :diagnostics bufnr new-cache))) (tset cache :diagnostics bufnr new-cache))))
(fn update-cache-diagnostics [bufnr diagnostics] (fn update-cache-diagnostics [bufnr diagnostics]
(maybe-setup-buffer-cache! :diagnostics bufnr) (maybe-setup-buffer-cache! :diagnostics bufnr)
@ -48,20 +50,34 @@
(fn update-cache-gitsigns [bufnr] (fn update-cache-gitsigns [bufnr]
(maybe-setup-buffer-cache! :gitsigns bufnr) (maybe-setup-buffer-cache! :gitsigns bufnr)
(clear-cache! :gitsigns bufnr) (clear-cache! :gitsigns bufnr)
(let [signs (?. (vim.fn.sign_getplaced bufnr (let [signs (api.nvim_buf_get_extmarks bufnr gitsigns-ns 0 -1
{:group :gitsigns_vimfn_signs_}) {:details true})]
1 :signs)] (when (not (vim.tbl_isempty signs))
(when (not= signs nil) (each [_ [_id row _col details] (pairs signs)]
(each [_ sign (pairs signs)] (let [lnum (+ row 1)
(let [lnum sign.lnum
current (cached-sign :gitsigns bufnr lnum)] current (cached-sign :gitsigns bufnr lnum)]
(when (= current nil) (when (= current nil)
(tset cache :gitsigns bufnr lnum sign))))))) (tset cache :gitsigns bufnr lnum {:name details.sign_hl_group})))))))
(aucmd :DiagnosticChanged (aucmd :DiagnosticChanged
{:callback #(update-cache-diagnostics $1.buf $1.data.diagnostics) {:callback #(let [full-mode (. (api.nvim_get_mode) :mode)
mode (full-mode:sub 1 1)]
(when (not= mode :i)
(update-cache-diagnostics $1.buf $1.data.diagnostics)))
:group augroup :group augroup
:desc "Update cached diagnostic signs"}) :desc "Update cached diagnostic signs"})
(aucmd :CursorHold
{:callback #(update-cache-diagnostics $1.buf
(vim.diagnostic.get $1.buf))
:group augroup
:desc "Periodically update cached diagnostics"})
(aucmd :InsertLeave
{:callback (fn [args]
(vim.defer_fn #(update-cache-diagnostics args.buf
(vim.diagnostic.get args.buf))
1000))
:group augroup
:desc "Update diagnostics after leaving insert mode"})
(aucmd :User {:pattern :GitSignsUpdate (aucmd :User {:pattern :GitSignsUpdate
:callback #(update-cache-gitsigns $1.buf) :callback #(update-cache-gitsigns $1.buf)
:group augroup :group augroup
@ -99,7 +115,7 @@
:provider " ▏" :provider " ▏"
:hl #(if $1.has_sign $1.sign.name :StatusLineNC) :hl #(if $1.has_sign $1.sign.name :StatusLineNC)
:on_click {:name :heirline_statuscolumn_gitsigns :on_click {:name :heirline_statuscolumn_gitsigns
:callback (fn [self] :callback (fn [_self]
(let [mouse (vim.fn.getmousepos) (let [mouse (vim.fn.getmousepos)
cursor-pos [mouse.line 0]] cursor-pos [mouse.line 0]]
(api.nvim_win_set_cursor mouse.winid (api.nvim_win_set_cursor mouse.winid
@ -114,8 +130,11 @@
mod.gitsigns]) mod.gitsigns])
;; Diagnostic signs ;; Diagnostic signs
(set mod.diagnostic-signs (set mod.diagnostic-signs
{:condition #(and (= b.nifoc_diagnostics_enabled 1) {:condition #(let [bufnr (api.nvim_get_current_buf)
(> (length (vim.diagnostic.get 0)) 0)) buf-diagnostics (. cache :diagnostics bufnr)]
(and (= b.nifoc_diagnostics_enabled 1)
(not= buf-diagnostics nil)
(not (vim.tbl_isempty buf-diagnostics))))
:static {:sign-text {diagnostic.severity.ERROR " " :static {:sign-text {diagnostic.severity.ERROR " "
diagnostic.severity.WARN " " diagnostic.severity.WARN " "
diagnostic.severity.INFO " " diagnostic.severity.INFO " "
@ -146,6 +165,5 @@
:scope :line}) :scope :line})
100)))}}) 100)))}})
;; Debug ;; Debug
(set mod._debug_cache #cache) (set mod._debug_cache #{: cache})
mod) mod)

View file

@ -55,4 +55,3 @@
:callback setup-linting :callback setup-linting
:group augroup :group augroup
:desc "Setup Linter"}))) :desc "Setup Linter"})))

View file

@ -121,8 +121,8 @@ in
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "nvim-treesitter"; owner = "nvim-treesitter";
repo = "nvim-treesitter"; repo = "nvim-treesitter";
rev = "bb3f8f40b1443fb40665263e1b5b0658bc24be03"; rev = "6f2ef910c2c320f27cf988cf4e688746f16f4f75";
sha256 = "0j7cdn1i8pldfpyjz7i90hk9vkwajf8j97zdqbdf0avj3kjnbwvw"; sha256 = "1sb5q2834zaq2naxrdln9v0p1p4dmdwk7v3pblzwqsm5z52p9cnc";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };