From e8cb038465e2e7ca698a3fc2c595e5e8f52a07bf Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Tue, 6 Aug 2024 00:33:28 +0200 Subject: [PATCH] perf: use cache for outdated rocks and trigger on more events --- doc/rocks-edit.txt | 36 ++++++++++++++++++++----- flake.lock | 42 +++++++++++++++--------------- lua/rocks-edit/_meta.lua | 34 ++++++++++++++++++++++++ lua/rocks-edit/api.lua | 3 --- lua/rocks-edit/config.lua | 9 ++++++- lua/rocks-edit/init.lua | 2 +- lua/rocks-edit/sources/updates.lua | 2 +- nix/ci-overlay.nix | 2 +- 8 files changed, 96 insertions(+), 34 deletions(-) mode change 100755 => 100644 flake.lock create mode 100644 lua/rocks-edit/_meta.lua diff --git a/doc/rocks-edit.txt b/doc/rocks-edit.txt index 7465070..914d92c 100644 --- a/doc/rocks-edit.txt +++ b/doc/rocks-edit.txt @@ -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) + 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* @@ -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) A list of module paths to invoke that act as sources for `rocks-edit.nvim`. - - vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/flake.lock b/flake.lock old mode 100755 new mode 100644 index 8879e67..e049c9c --- a/flake.lock +++ b/flake.lock @@ -743,11 +743,11 @@ "nixpkgs-stable": "nixpkgs-stable_2" }, "locked": { - "lastModified": 1721042469, - "narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=", + "lastModified": 1722857853, + "narHash": "sha256-3Zx53oz/MSIyevuWO/SumxABkrIvojnB7g9cimxkhiE=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "f451c19376071a90d8c58ab1a953c6e9840527fd", + "rev": "06939f6b7ec4d4f465bf3132a05367cccbbf64da", "type": "github" }, "original": { @@ -1173,11 +1173,11 @@ "nixpkgs": "nixpkgs_5" }, "locked": { - "lastModified": 1722835619, - "narHash": "sha256-byDwYcAztY2XRjqaE/G1+lzLRzUa/bz3sJF/dgxT3eE=", + "lastModified": 1722921915, + "narHash": "sha256-D/If1o1nOgnZLRi3wWlTAkt35f70AOuWd6GbKH/eeLU=", "owner": "nvim-neorocks", "repo": "neorocks", - "rev": "c30a1ed6b453b748401e9eba2c35d1c98ce6e58f", + "rev": "e0ac2375d071e4ce9c1f3b7da98ef22fcbaf1dbf", "type": "github" }, "original": { @@ -1240,11 +1240,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1722755885, - "narHash": "sha256-+q9aul2Dy77Qd/Sl/sTcWjFYAhjE41BEzW2YOoMZEgw=", + "lastModified": 1722865783, + "narHash": "sha256-a23BT63Ayt0JedCRab2vnRt0kOr7Uujh/ZGKrRWq5yA=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "da6d85c958e345129f3f85b39392e00fd78e2e46", + "rev": "9cbacea6291a0abe1c3c294a49982fcd223aca57", "type": "github" }, "original": { @@ -1302,11 +1302,11 @@ "neovim-src": { "flake": false, "locked": { - "lastModified": 1722722994, - "narHash": "sha256-UpW1FMRNS8uCM8ONSYQhVua8ESqABnsWu6nh5MCvDVg=", + "lastModified": 1722810680, + "narHash": "sha256-/83aiz7PIQny+agTySIKIrexYPV2MFHjKNLggcSZDs8=", "owner": "neovim", "repo": "neovim", - "rev": "58406ab9f0adba6f26402d47479ca061864b2584", + "rev": "0c2860d9e5ec5417a94db6e3edd237578b76d418", "type": "github" }, "original": { @@ -1766,11 +1766,11 @@ }, "nixpkgs_5": { "locked": { - "lastModified": 1722640603, - "narHash": "sha256-TcXjLVNd3VeH1qKPH335Tc4RbFDbZQX+d7rqnDUoRaY=", + "lastModified": 1722802969, + "narHash": "sha256-bPhyAXNnVerBZusxOuPMhMm0X7hSFLFKcH+7ynfgLjs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "81610abc161d4021b29199aa464d6a1a521e0cc9", + "rev": "785feb91183a50959823ff9ba9ef673105259cd5", "type": "github" }, "original": { @@ -1782,11 +1782,11 @@ }, "nixpkgs_6": { "locked": { - "lastModified": 1722730825, - "narHash": "sha256-X6U+w8qFBuGPCYrZzc9mpN34aRjQ8604MonpBUkj908=", + "lastModified": 1722926584, + "narHash": "sha256-sLA+lfCxTkXf4o3JVxcfe+w9kAzauGfEnJ9roNbNng8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f3834de3782b82bfc666abf664f946d0e7d1f116", + "rev": "d33cf80b603b3d0cddb48f9816cae707a59e2334", "type": "github" }, "original": { @@ -1902,11 +1902,11 @@ "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1722642819, - "narHash": "sha256-a+kc48pP2TTznbWDng9z/2eGIooKxJTmDvZpEomh61Y=", + "lastModified": 1722960873, + "narHash": "sha256-/hsJja9ogzk6YaWo4ReROmFzclVmbKlxmVL6IQOPAxk=", "owner": "nvim-neorocks", "repo": "rocks.nvim", - "rev": "c4b12461e41ef8fca97ed775fb2524be5776f31c", + "rev": "00a8e78ba5e995973a55992a377a4289a80de378", "type": "github" }, "original": { diff --git a/lua/rocks-edit/_meta.lua b/lua/rocks-edit/_meta.lua new file mode 100644 index 0000000..1149e56 --- /dev/null +++ b/lua/rocks-edit/_meta.lua @@ -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 +--- +---@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 diff --git a/lua/rocks-edit/api.lua b/lua/rocks-edit/api.lua index 85754b9..73a4a13 100644 --- a/lua/rocks-edit/api.lua +++ b/lua/rocks-edit/api.lua @@ -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 A list of module paths to invoke that act as sources for `rocks-edit.nvim`. - return api diff --git a/lua/rocks-edit/config.lua b/lua/rocks-edit/config.lua index 90bf61d..b7a917d 100644 --- a/lua/rocks-edit/config.lua +++ b/lua/rocks-edit/config.lua @@ -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) diff --git a/lua/rocks-edit/init.lua b/lua/rocks-edit/init.lua index 11379ae..70b2eff 100644 --- a/lua/rocks-edit/init.lua +++ b/lua/rocks-edit/init.lua @@ -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() diff --git a/lua/rocks-edit/sources/updates.lua b/lua/rocks-edit/sources/updates.lua index aff06ea..24a3250 100644 --- a/lua/rocks-edit/sources/updates.lua +++ b/lua/rocks-edit/sources/updates.lua @@ -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 diff --git a/nix/ci-overlay.nix b/nix/ci-overlay.nix index 0441df1..29b24b6 100755 --- a/nix/ci-overlay.nix +++ b/nix/ci-overlay.nix @@ -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 {