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,24 +74,23 @@
|
||||||
: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 [num (o.number:get)
|
(let [relnum-opt (o.relativenumber:get)
|
||||||
relnum (o.relativenumber:get)]
|
relnum v.relnum
|
||||||
(if (and num (not relnum)) "%l"
|
virtnum v.virtnum]
|
||||||
(and relnum (not num)) "%r"
|
(if (not= virtnum 0) ""
|
||||||
"%{v:relnum?v:relnum:v:lnum}")))}})
|
(and relnum-opt (= relnum 0)) "%l"
|
||||||
|
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)
|
||||||
lnum vim.v.lnum
|
sign (cached-sign bufnr :gitsigns v.lnum)]
|
||||||
sign (cached-sign bufnr :gitsigns lnum)]
|
|
||||||
(set self.sign sign)
|
(set self.sign sign)
|
||||||
(set self.has_sign (not= sign nil))))
|
(set self.has_sign (not= sign nil))))
|
||||||
:provider " ▏"
|
:provider " ▏"
|
||||||
|
@ -101,8 +103,7 @@
|
||||||
cursor-pos)
|
cursor-pos)
|
||||||
(vim.defer_fn #(gitsigns.blame_line {:full true})
|
(vim.defer_fn #(gitsigns.blame_line {:full true})
|
||||||
100)))}})
|
100)))}})
|
||||||
(set mod.gitsigns-or-bar [{:condition #(and (not= vim.b.nifoc_gitsigns_enabled
|
(set mod.gitsigns-or-bar [{:condition #(and (not= b.nifoc_gitsigns_enabled 1)
|
||||||
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
|
||||||
|
@ -142,5 +142,7 @@
|
||||||
:pos line
|
:pos line
|
||||||
:scope :line})
|
:scope :line})
|
||||||
100)))}})
|
100)))}})
|
||||||
|
;; Debug
|
||||||
|
(set mod._debug_cache #cache)
|
||||||
mod)
|
mod)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue