nvim: Optimize statuscolumn
This commit is contained in:
parent
b607a80dc2
commit
308ffea3ad
1 changed files with 45 additions and 43 deletions
|
@ -2,6 +2,8 @@
|
||||||
cache {}
|
cache {}
|
||||||
api vim.api
|
api vim.api
|
||||||
o vim.opt
|
o vim.opt
|
||||||
|
b vim.b
|
||||||
|
v vim.v
|
||||||
statusline (require :nifoc.statusline)
|
statusline (require :nifoc.statusline)
|
||||||
diagnostic vim.diagnostic
|
diagnostic vim.diagnostic
|
||||||
gitsigns (require :gitsigns)
|
gitsigns (require :gitsigns)
|
||||||
|
@ -18,17 +20,18 @@
|
||||||
(fn clear-cache! [bufnr key]
|
(fn clear-cache! [bufnr key]
|
||||||
(tset cache bufnr key {}))
|
(tset cache bufnr key {}))
|
||||||
|
|
||||||
|
(fn cache-filter [func t]
|
||||||
|
(let [ret-tab {}]
|
||||||
|
(each [k v (pairs t)] (when (func v k) (tset ret-tab k v)))
|
||||||
|
ret-tab))
|
||||||
|
|
||||||
(fn clear-diagnostics-cache! [bufnr diagnostics]
|
(fn clear-diagnostics-cache! [bufnr diagnostics]
|
||||||
(let [key :diagnostics
|
(let [key :diagnostics
|
||||||
namespaces (vim.tbl_map (fn [d]
|
namespaces (vim.tbl_map #$1.namespace diagnostics)
|
||||||
d.namespace)
|
current-cache (. cache bufnr key)
|
||||||
diagnostics)
|
new-cache (cache-filter #(not (vim.tbl_contains namespaces $1.ns))
|
||||||
cleared-namespaces {}]
|
current-cache)]
|
||||||
(each [_ ns (pairs namespaces)]
|
(tset cache bufnr key new-cache)))
|
||||||
(when (= (. cleared-namespaces ns) nil)
|
|
||||||
(local current-cache (. cache bufnr key))
|
|
||||||
(tset cache bufnr key (vim.tbl_filter #(not= $1.ns ns) current-cache))
|
|
||||||
(tset cleared-namespaces ns true)))))
|
|
||||||
|
|
||||||
(fn update-cache-diagnostics [bufnr diagnostics]
|
(fn update-cache-diagnostics [bufnr diagnostics]
|
||||||
(maybe-setup-buffer-cache! bufnr :diagnostics)
|
(maybe-setup-buffer-cache! bufnr :diagnostics)
|
||||||
|
@ -36,7 +39,7 @@
|
||||||
(each [_ diagnostic (pairs diagnostics)]
|
(each [_ diagnostic (pairs diagnostics)]
|
||||||
(let [lnum (+ diagnostic.lnum 1)
|
(let [lnum (+ diagnostic.lnum 1)
|
||||||
current (. cache bufnr :diagnostics lnum)]
|
current (. cache bufnr :diagnostics lnum)]
|
||||||
(when (or (= current nil) (< diagnostic.severity current.severity))
|
(when (or (= current nil) (> diagnostic.severity current.severity))
|
||||||
(tset cache bufnr :diagnostics lnum
|
(tset cache bufnr :diagnostics lnum
|
||||||
{:severity diagnostic.severity
|
{:severity diagnostic.severity
|
||||||
:col diagnostic.col
|
:col diagnostic.col
|
||||||
|
@ -71,38 +74,36 @@
|
||||||
:group augroup
|
:group augroup
|
||||||
:desc "Clear sign cache for current buffer"})
|
:desc "Clear sign cache for current buffer"})
|
||||||
;; Line Number
|
;; Line Number
|
||||||
(set mod.line-number
|
(set mod.line-number {:condition #(or (o.number:get) (o.relativenumber:get))
|
||||||
{:condition #(or (o.number:get) (o.relativenumber:get))
|
1 statusline.push-right
|
||||||
1 statusline.push-right
|
2 {:provider (fn []
|
||||||
2 {:provider (fn []
|
(let [relnum-opt (o.relativenumber:get)
|
||||||
(let [num (o.number:get)
|
relnum v.relnum
|
||||||
relnum (o.relativenumber:get)]
|
virtnum v.virtnum]
|
||||||
(if (and num (not relnum)) "%l"
|
(if (not= virtnum 0) ""
|
||||||
(and relnum (not num)) "%r"
|
(and relnum-opt (= relnum 0)) "%l"
|
||||||
"%{v:relnum?v:relnum:v:lnum}")))}})
|
relnum-opt (tostring relnum)
|
||||||
|
"%l")))}})
|
||||||
;; Signs
|
;; Signs
|
||||||
(set mod.signs {:provider "%s" :hl {:bold true}})
|
(set mod.signs {:provider "%s" :hl {:bold true}})
|
||||||
;; gitsigns
|
;; gitsigns
|
||||||
(set mod.gitsigns
|
(set mod.gitsigns {:condition #(= b.nifoc_gitsigns_enabled 1)
|
||||||
{:condition #(= vim.b.nifoc_gitsigns_enabled 1)
|
:init (fn [self]
|
||||||
:init (fn [self]
|
(let [bufnr (api.nvim_get_current_buf)
|
||||||
(let [bufnr (api.nvim_get_current_buf)
|
sign (cached-sign bufnr :gitsigns v.lnum)]
|
||||||
lnum vim.v.lnum
|
(set self.sign sign)
|
||||||
sign (cached-sign bufnr :gitsigns lnum)]
|
(set self.has_sign (not= sign nil))))
|
||||||
(set self.sign sign)
|
:provider " ▏"
|
||||||
(set self.has_sign (not= sign nil))))
|
:hl #(if $1.has_sign $1.sign.name :StatusLineNC)
|
||||||
:provider " ▏"
|
:on_click {:name :heirline_statuscolumn_gitsigns
|
||||||
:hl #(if $1.has_sign $1.sign.name :StatusLineNC)
|
:callback (fn [self]
|
||||||
:on_click {:name :heirline_statuscolumn_gitsigns
|
(let [mouse (vim.fn.getmousepos)
|
||||||
:callback (fn [self]
|
cursor-pos [mouse.line 0]]
|
||||||
(let [mouse (vim.fn.getmousepos)
|
(api.nvim_win_set_cursor mouse.winid
|
||||||
cursor-pos [mouse.line 0]]
|
cursor-pos)
|
||||||
(api.nvim_win_set_cursor mouse.winid
|
(vim.defer_fn #(gitsigns.blame_line {:full true})
|
||||||
cursor-pos)
|
100)))}})
|
||||||
(vim.defer_fn #(gitsigns.blame_line {:full true})
|
(set mod.gitsigns-or-bar [{:condition #(and (not= b.nifoc_gitsigns_enabled 1)
|
||||||
100)))}})
|
|
||||||
(set mod.gitsigns-or-bar [{:condition #(and (not= vim.b.nifoc_gitsigns_enabled
|
|
||||||
1)
|
|
||||||
(or (o.number:get)
|
(or (o.number:get)
|
||||||
(o.relativenumber:get)))
|
(o.relativenumber:get)))
|
||||||
:provider " ▏"
|
:provider " ▏"
|
||||||
|
@ -110,7 +111,7 @@
|
||||||
mod.gitsigns])
|
mod.gitsigns])
|
||||||
;; Diagnostic signs
|
;; Diagnostic signs
|
||||||
(set mod.diagnostic-signs
|
(set mod.diagnostic-signs
|
||||||
{:condition #(and (= vim.b.nifoc_diagnostics_enabled 1)
|
{:condition #(and (= b.nifoc_diagnostics_enabled 1)
|
||||||
(> (length (vim.diagnostic.get 0)) 0))
|
(> (length (vim.diagnostic.get 0)) 0))
|
||||||
:static {:sign-text {diagnostic.severity.ERROR " "
|
:static {:sign-text {diagnostic.severity.ERROR " "
|
||||||
diagnostic.severity.WARN " "
|
diagnostic.severity.WARN " "
|
||||||
|
@ -122,8 +123,7 @@
|
||||||
diagnostic.severity.HINT :DiagnosticSignHint}}
|
diagnostic.severity.HINT :DiagnosticSignHint}}
|
||||||
:init (fn [self]
|
:init (fn [self]
|
||||||
(let [bufnr (api.nvim_get_current_buf)
|
(let [bufnr (api.nvim_get_current_buf)
|
||||||
lnum vim.v.lnum
|
sign (cached-sign bufnr :diagnostics v.lnum)]
|
||||||
sign (cached-sign bufnr :diagnostics lnum)]
|
|
||||||
(set self.sign sign)
|
(set self.sign sign)
|
||||||
(set self.has_sign (not= sign nil))))
|
(set self.has_sign (not= sign nil))))
|
||||||
:provider #(if $1.has_sign
|
:provider #(if $1.has_sign
|
||||||
|
@ -141,6 +141,8 @@
|
||||||
(vim.defer_fn #(vim.diagnostic.open_float {:bufnr self.bufnr
|
(vim.defer_fn #(vim.diagnostic.open_float {:bufnr self.bufnr
|
||||||
:pos line
|
:pos line
|
||||||
:scope :line})
|
:scope :line})
|
||||||
100)))}})
|
100)))}})
|
||||||
|
;; Debug
|
||||||
|
(set mod._debug_cache #cache)
|
||||||
mod)
|
mod)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue