diff --git a/lua/sense/autocmds.lua b/lua/sense/autocmds.lua index a8fa449..d6b0b0d 100644 --- a/lua/sense/autocmds.lua +++ b/lua/sense/autocmds.lua @@ -1,7 +1,8 @@ --- TODO: lazy-load these -local state = require("sense.state") -local ui = require("sense.ui") -local log = require("sense.log") +-- stylua: ignore start +local function state() return require("sense.state") end +local function ui() return require("sense.ui") end +local function log() return require("sense.log") end +-- stylua: ignore end local M = {} @@ -11,24 +12,24 @@ function M.setup() vim.api.nvim_create_autocmd("DiagnosticChanged", { group = group, callback = function(ev) - log.debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) + log().debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) local diagnostics = ev.data.diagnostics -- cache the diagnostics to be used from WinScrolled event - state.diag_cache[ev.buf] = diagnostics + state().diag_cache[ev.buf] = diagnostics -- update all windows with that buffer local infos = vim.fn.getwininfo() vim.iter(infos) :filter(function(info) return info.bufnr == ev.buf end) - :map(ui.update) + :map(ui().update) end, }) vim.api.nvim_create_autocmd({ "VimResized" }, { group = group, callback = function() local infos = vim.fn.getwininfo() - vim.iter(infos):map(ui.update) + vim.iter(infos):map(ui().update) end, }) -- WinEnter: when user do `:split` @@ -36,10 +37,10 @@ function M.setup() vim.api.nvim_create_autocmd({ "WinEnter", "WinScrolled", "CursorMoved" }, { group = group, callback = function(ev) - log.debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) + log().debug("Event:", ev.event, "Buf:", ev.buf, "Match:", ev.match) -- Ignore buffers that haven't been cached yet - if not state.diag_cache[ev.buf] then - log.debug("buffer", ev.buf, "haven't been cached yet. aborting UI updates") + if not state().diag_cache[ev.buf] then + log().debug("buffer", ev.buf, "haven't been cached yet. aborting UI updates") return end local winid @@ -49,7 +50,7 @@ function M.setup() winid = vim.api.nvim_get_current_win() end local info = vim.fn.getwininfo(winid)[1] - ui.update(info) + ui().update(info) end, }) end