Expand your neovim sense with small UI components
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: lazy loading!

+13 -12
+13 -12
lua/sense/autocmds.lua
··· 1 - -- TODO: lazy-load these 2 - local state = require("sense.state") 3 - local ui = require("sense.ui") 4 - local log = require("sense.log") 1 + -- stylua: ignore start 2 + local function state() return require("sense.state") end 3 + local function ui() return require("sense.ui") end 4 + local function log() return require("sense.log") end 5 + -- stylua: ignore end 5 6 6 7 local M = {} 7 8 ··· 11 12 vim.api.nvim_create_autocmd("DiagnosticChanged", { 12 13 group = group, 13 14 callback = function(ev) 14 - log.debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) 15 + log().debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) 15 16 local diagnostics = ev.data.diagnostics 16 17 -- cache the diagnostics to be used from WinScrolled event 17 - state.diag_cache[ev.buf] = diagnostics 18 + state().diag_cache[ev.buf] = diagnostics 18 19 -- update all windows with that buffer 19 20 local infos = vim.fn.getwininfo() 20 21 vim.iter(infos) 21 22 :filter(function(info) 22 23 return info.bufnr == ev.buf 23 24 end) 24 - :map(ui.update) 25 + :map(ui().update) 25 26 end, 26 27 }) 27 28 vim.api.nvim_create_autocmd({ "VimResized" }, { 28 29 group = group, 29 30 callback = function() 30 31 local infos = vim.fn.getwininfo() 31 - vim.iter(infos):map(ui.update) 32 + vim.iter(infos):map(ui().update) 32 33 end, 33 34 }) 34 35 -- WinEnter: when user do `:split` ··· 36 37 vim.api.nvim_create_autocmd({ "WinEnter", "WinScrolled", "CursorMoved" }, { 37 38 group = group, 38 39 callback = function(ev) 39 - log.debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) 40 + log().debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) 40 41 -- Ignore buffers that haven't been cached yet 41 - if not state.diag_cache[ev.buf] then 42 - log.debug("buffer", ev.buf, "haven't been cached yet. aborting UI updates") 42 + if not state().diag_cache[ev.buf] then 43 + log().debug("buffer", ev.buf, "haven't been cached yet. aborting UI updates") 43 44 return 44 45 end 45 46 local winid ··· 49 50 winid = vim.api.nvim_get_current_win() 50 51 end 51 52 local info = vim.fn.getwininfo(winid)[1] 52 - ui.update(info) 53 + ui().update(info) 53 54 end, 54 55 }) 55 56 end