Skip to content

Commit

Permalink
perf: use cache for outdated rocks and trigger on more events
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Aug 6, 2024
1 parent d766c07 commit e8cb038
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 34 deletions.
36 changes: 30 additions & 6 deletions doc/rocks-edit.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
==============================================================================
rocks-edit.nvim configuration *rocks-edit.config*

You can configure rocks-edit.nvim using a `[edit]` table in your rocks.toml.

Example:
>toml
[edit.builtin_sources]
unsynced = true
updated = true

[edit]
events = [ "TextChanged", "BufWritePost" ]
<


rocks-edit.Config *rocks-edit.Config*

Fields: ~
{builtin_sources} (table<builtin_source,boolean>)
A list of module paths to invoke that act as sources for `rocks-edit.nvim`.


builtin_source *builtin_source*


Variants: ~



==============================================================================
rocks-edit.nvim Lua API *rocks-edit.api*

Expand Down Expand Up @@ -39,10 +69,4 @@ rocks-edit.Source *rocks-edit.Source*
fun(toml:RocksToml,set:fun(diagnostic:rocks-edit.Diagnostic))


rocks-edit.Config *rocks-edit.Config*

Fields: ~
{builtin_sources} (table<string,boolean>) A list of module paths to invoke that act as sources for `rocks-edit.nvim`.


vim:tw=78:ts=8:noet:ft=help:norl:
42 changes: 21 additions & 21 deletions flake.lock
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions lua/rocks-edit/_meta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---@mod rocks-edit.config rocks-edit.nvim configuration
---
---@brief [[
---You can configure rocks-edit.nvim using a `[edit]` table in your rocks.toml.
---
---Example:
--->toml
--- [edit.builtin_sources]
--- unsynced = true
--- updated = true
---
--- [edit]
--- events = [ "TextChanged", "BufWritePost" ]
---<
---
---@brief ]]

---@class rocks-edit.Config
---
---A list of module paths to invoke that act as sources for `rocks-edit.nvim`.
---@field builtin_sources table<builtin_source, boolean>
---
---@alias builtin_source
---| "unsynced"
---| "updates"
---
---A list of events that trigger a refresh.
---@field events string[]

error("Cannot require a meta module")

local M = {}

return M
3 changes: 0 additions & 3 deletions lua/rocks-edit/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,4 @@ end

---@alias rocks-edit.Source fun(toml: RocksToml, set: fun(diagnostic: rocks-edit.Diagnostic))

---@class rocks-edit.Config
---@field builtin_sources table<string, boolean> A list of module paths to invoke that act as sources for `rocks-edit.nvim`.

return api
9 changes: 8 additions & 1 deletion lua/rocks-edit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ local config = {}

---@type rocks-edit.Config
local default_config = {
builtin_sources = { unsynced = true, updates = true },
builtin_sources = {
unsynced = true,
updates = true,
},
events = {
"BufWritePost",
"TextChanged",
},
}

local current_config = vim.deepcopy(default_config)
Expand Down
2 changes: 1 addition & 1 deletion lua/rocks-edit/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local function attach_callbacks(buffer)
end,
})

vim.api.nvim_create_autocmd("BufWritePost", {
vim.api.nvim_create_autocmd(config.get().events, {
buffer = buffer,
group = group,
callback = function()
Expand Down
2 changes: 1 addition & 1 deletion lua/rocks-edit/sources/updates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local nio = require("nio")

require("rocks-edit.api").register(function(toml, diagnostic)
nio.run(function()
local updates = require("rocks.state").outdated_rocks()
local updates = require("rocks.api").try_get_cached_outdated_rocks()

for name, data in pairs(updates) do
if toml.plugins[name] then
Expand Down
2 changes: 1 addition & 1 deletion nix/ci-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
];
text = ''
mkdir -p doc
lemmy-help lua/rocks-edit/api.lua > doc/rocks-edit.txt
lemmy-help lua/rocks-edit/{_meta,api}.lua > doc/rocks-edit.txt
'';
};
in {
Expand Down

0 comments on commit e8cb038

Please sign in to comment.