From 4dfc8758a1deab45e37b7f3661e0fd3759d85788 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 9 Jun 2025 14:04:09 +0300 Subject: [PATCH] make `cache_ttl` configurable --- lua/direnv.lua | 6 ++++-- stylua.toml | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/direnv.lua b/lua/direnv.lua index fa6fbb1..b3448c7 100644 --- a/lua/direnv.lua +++ b/lua/direnv.lua @@ -3,6 +3,7 @@ local M = {} --- @class DirenvConfig --- @field bin string Path to direnv executable --- @field autoload_direnv boolean Automatically load direnv when opening files +--- @field cache_ttl integer Cache TTL in milliseconds for direnv status checks --- @field statusline table Configuration for statusline integration --- @field statusline.enabled boolean Enable statusline integration --- @field statusline.icon string Icon to show in statusline @@ -19,7 +20,6 @@ local cache = { status = nil, path = nil, last_check = 0, - ttl = 5000, -- milliseconds before cache invalidation, then we can think about naming things pending_request = false, } @@ -118,8 +118,9 @@ end M._get_rc_status = function(callback) local loop = vim.uv or vim.loop local now = math.floor(loop.hrtime() / 1000000) -- ns -> ms + local ttl = (M.config and M.config.cache_ttl) or 5000 - if cache.status ~= nil and (now - cache.last_check) < cache.ttl then + if cache.status ~= nil and (now - cache.last_check) < ttl then return callback(cache.status, cache.path) end @@ -447,6 +448,7 @@ M.setup = function(user_config) M.config = vim.tbl_deep_extend("force", { bin = "direnv", autoload_direnv = false, + cache_ttl = 5000, statusline = { enabled = false, icon = "󱚟", diff --git a/stylua.toml b/stylua.toml index 457eb4f..5562342 100644 --- a/stylua.toml +++ b/stylua.toml @@ -1,3 +1,6 @@ indent_type = "Spaces" indent_width = 3 column_width = 80 + +[sort_requires] +enabled = true