Skip to content

Commit

Permalink
feat(update): reinstall dev rocks by default (#210)
Browse files Browse the repository at this point in the history
* feat(update): reinstall `dev` rocks by default

This also fixes some type annotations

* docs(generated): update doc/rocks.txt
skip-checks: true

---------

Co-authored-by: Github Actions <actions@github>
  • Loading branch information
mrcjkb and Github Actions authored Mar 19, 2024
1 parent ebaf92e commit de1c86c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
17 changes: 9 additions & 8 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ rocks.nvim configuration *rocks.config*
RocksOpts *RocksOpts*

Fields: ~
{rocks_path?} (string) Local path in your filesystem to install rocks. Defaults to a `rocks` directory in `vim.fn.stdpath("data")`.
{config_path?} (string) Rocks declaration file path. Defaults to `rocks.toml` in `vim.fn.stdpath("config")`.
{luarocks_binary?} (string) Luarocks binary path. Defaults to `luarocks`.
{lazy?} (boolean) Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially.
{dynamic_rtp?} (boolean) Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience.
{generate_help_pages?} (boolean) Whether to re-generate plugins help pages after installation/upgrade.
{rocks_path?} (string) Local path in your filesystem to install rocks. Defaults to a `rocks` directory in `vim.fn.stdpath("data")`.
{config_path?} (string) Rocks declaration file path. Defaults to `rocks.toml` in `vim.fn.stdpath("config")`.
{luarocks_binary?} (string) Luarocks binary path. Defaults to `luarocks`.
{lazy?} (boolean) Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially.
{dynamic_rtp?} (boolean) Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience.
{generate_help_pages?} (boolean) Whether to re-generate plugins help pages after installation/upgrade.
{reinstall_dev_rocks_on_update} (boolean) Whether to reinstall 'dev' rocks on update (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).


==============================================================================
Expand Down Expand Up @@ -152,7 +153,7 @@ Specification for a rock in rocks.toml. May be extended by external modules.
RocksToml *RocksToml*


{ rocks?: RockSpec[], plugins?: RockSpec[], [string]: V }
{ rocks?: table<string, RockSpec[]>, plugins?: table<string,RockSpec[]>, [string]: V }

Content of rocks.toml

Expand All @@ -169,7 +170,7 @@ api.get_user_rocks() *api.get_user_rocks*
If the file doesn't exist a file with the default configuration will be created.

Returns: ~
(RockSpec[])
(table<rock_name,RockSpec>)


RocksCmd *RocksCmd*
Expand Down
6 changes: 3 additions & 3 deletions lua/rocks/api/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ end
---Specification for a rock in rocks.toml. May be extended by external modules.
---@brief ]]

---@class RocksToml: { rocks?: RockSpec[], plugins?: RockSpec[], [string]: unknown }
---@class RocksToml: { rocks?: table<string, RockSpec[]>, plugins?: table<string, RockSpec[]>, [string]: unknown }
---@brief [[
--- { rocks?: RockSpec[], plugins?: RockSpec[], [string]: V }
--- { rocks?: table<string, RockSpec[]>, plugins?: table<string,RockSpec[]>, [string]: V }
---
---Content of rocks.toml
---@brief ]]
Expand All @@ -121,7 +121,7 @@ end

---Returns a table with the rock specifications parsed from the rocks.toml file.
---If the file doesn't exist a file with the default configuration will be created.
---@return RockSpec[]
---@return table<rock_name, RockSpec>
function api.get_user_rocks()
return config.get_user_rocks()
end
Expand Down
1 change: 1 addition & 0 deletions lua/rocks/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local config = {}
---@field lazy? boolean Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially.
---@field dynamic_rtp? boolean Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience.
---@field generate_help_pages? boolean Whether to re-generate plugins help pages after installation/upgrade.
---@field reinstall_dev_rocks_on_update boolean Whether to reinstall 'dev' rocks on update (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).

---@type RocksOpts | fun():RocksOpts
vim.g.rocks_nvim = vim.g.rocks_nvim
Expand Down
4 changes: 3 additions & 1 deletion lua/rocks/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ local default_config = {
dynamic_rtp = true,
---@type boolean Whether to re-generate plugins help pages after installation/upgrade
generate_help_pages = true,
---@type boolean Whether to reinstall 'dev' rocks on update
reinstall_dev_rocks_on_update = true,
---@class RocksConfigDebugInfo
debug_info = {
---@type boolean
Expand Down Expand Up @@ -66,7 +68,7 @@ local default_config = {
end
return rocks_toml
end,
---@type fun():RockSpec[]
---@type fun():table<rock_name, RockSpec>
get_user_rocks = function()
local rocks_toml = config.get_rocks_toml()
return vim.tbl_deep_extend("force", rocks_toml.rocks or {}, rocks_toml.plugins or {})
Expand Down
25 changes: 24 additions & 1 deletion lua/rocks/operations/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ local function get_percentage(counter, total)
return counter > 0 and math.min(100, math.floor((counter / total) * 100)) or 0
end

---@param outdated_rocks table<rock_name, OutdatedRock>
---@return table<rock_name, OutdatedRock>
local function add_dev_rocks_for_update(outdated_rocks)
return vim.iter(config.get_user_rocks()):fold(outdated_rocks, function(acc, name, spec)
---@cast acc table<rock_name, OutdatedRock>
---@cast name rock_name
---@cast spec RockSpec
if spec.version == "scm" then
acc[name] = {
name = spec.name,
version = spec.version,
target_version = spec.version,
}
end
return acc
end)
end

--- Synchronizes the user rocks with the physical state on the current machine.
--- - Installs missing rocks
--- - Ensures that the correct versions are installed
Expand Down Expand Up @@ -335,6 +353,9 @@ operations.update = function()
local user_rocks = parse_rocks_toml()

local outdated_rocks = state.outdated_rocks()
if config.reinstall_dev_rocks_on_update then
outdated_rocks = add_dev_rocks_for_update(outdated_rocks)
end
local external_update_handlers = handlers.get_update_handler_callbacks(user_rocks)

local total_update_count = #outdated_rocks + #external_update_handlers
Expand Down Expand Up @@ -365,7 +386,9 @@ operations.update = function()
user_rocks.plugins[rock_name] = ret.version
end
progress_handle:report({
message = ("Updated %s: %s -> %s"):format(rock.name, rock.version, rock.target_version),
message = rock.version == rock.target_version
and ("Updated rock %s: %s"):format(rock.name, rock.version)
or ("Updated %s: %s -> %s"):format(rock.name, rock.version, rock.target_version),
percentage = get_percentage(ct, total_update_count),
})
else
Expand Down

0 comments on commit de1c86c

Please sign in to comment.