diff --git a/lua/rocks/health.lua b/lua/rocks/health.lua index a69436e8..1395357b 100644 --- a/lua/rocks/health.lua +++ b/lua/rocks/health.lua @@ -119,7 +119,7 @@ local function check_external_dependency(dep) end local function check_config() - start("Checking config") + start("Checking rocks.nvim config") if vim.g.rocks_nvim and not config.debug_info.was_g_rocks_nvim_sourced then warn("unrecognized configs in vim.g.rocks_nvim: " .. vim.inspect(config.debug_info.unrecognized_configs)) end @@ -131,12 +131,29 @@ local function check_config() end end +local function check_rocks_toml() + start("Checking rocks.toml") + local success, user_rocks_or_err = xpcall(require("rocks.config.internal").get_user_rocks, function(err) + error(err) + end) + if not success then + return + end + for rock_name, _ in pairs(user_rocks_or_err) do + if rock_name:lower() ~= rock_name then + error(("Plugin name is not lowercase: %s"):format(rock_name)) + end + ok("No errors found in rocks.toml.") + end +end + function health.check() start("Checking external dependencies") for _, dep in ipairs(external_dependencies) do check_external_dependency(dep) end check_config() + check_rocks_toml() end return health diff --git a/lua/rocks/operations/init.lua b/lua/rocks/operations/init.lua index b6688096..52ed4836 100644 --- a/lua/rocks/operations/init.lua +++ b/lua/rocks/operations/init.lua @@ -113,7 +113,8 @@ operations.sync = function(user_rocks, on_complete) end if user_rocks == nil then -- Read or create a new config file and decode it - -- NOTE: This does not use parse_user_rocks because we decode with toml, not toml-edit + -- NOTE: This does not use parse_user_rocks + -- because we decode with toml-edit.parse_as_tbl, not toml-edit.parse user_rocks = config.get_user_rocks() end @@ -174,16 +175,29 @@ operations.sync = function(user_rocks, on_complete) return get_percentage(ct, action_count) end - ---@type RockSpec[] + ---@class SyncSkippedRock + ---@field spec RockSpec + ---@field reason string + + ---@type SyncSkippedRock[] local skipped_rocks = {} for _, key in ipairs(to_install) do - nio.scheduler() + -- Save skipped rocks for later, when an external handler may have been bootstrapped if not user_rocks[key].version then - -- Save it for later, when an external handler may have been bootstrapped - table.insert(skipped_rocks, user_rocks[key]) + table.insert(skipped_rocks, { + spec = user_rocks[key], + reason = "No version specified", + }) + goto skip_install + elseif key:lower() ~= key then + table.insert(skipped_rocks, { + spec = user_rocks[key], + reason = "Name is not lowercase", + }) goto skip_install end + nio.scheduler() progress_handle:report({ message = ("Installing: %s"):format(key), }) @@ -218,13 +232,14 @@ operations.sync = function(user_rocks, on_complete) -- rocks.nvim sync handlers should be installed now. -- try installing any rocks that rocks.nvim could not handle itself - for _, spec in ipairs(skipped_rocks) do + for _, skipped_rock in ipairs(skipped_rocks) do + local spec = skipped_rock.spec ct = ct + 1 local callback = handlers.get_sync_handler_callback(spec) if callback then callback(report_progress, report_error) else - report_error(("Failed to install %s."):format(spec.name)) + report_error(("Failed to install %s: %s"):format(spec.name, skipped_rock.reason)) end end @@ -529,7 +544,7 @@ operations.add = function(arg_list, callback) return end ---@type rock_name - local rock_name = arg_list[1] + local rock_name = arg_list[1]:lower() -- We can't mutate the arg_list, because we may need it for a recursive add ---@type string[] local args = #arg_list == 1 and {} or { unpack(arg_list, 2, #arg_list) } diff --git a/spec/operations/install_update_spec.lua b/spec/operations/install_update_spec.lua index 19e95b00..7b0a28e7 100644 --- a/spec/operations/install_update_spec.lua +++ b/spec/operations/install_update_spec.lua @@ -12,7 +12,7 @@ describe("install/update", function() local state = require("rocks.state") nio.tests.it("install and update rocks", function() local future = nio.control.future() - operations.add({ "neorg", "7.0.0" }, function() + operations.add({ "Neorg", "7.0.0" }, function() -- ensure lower case future.set(true) end) future.wait() @@ -21,6 +21,12 @@ describe("install/update", function() name = "neorg", version = "7.0.0", }, installed_rocks.neorg) + nio.sleep(1000) -- Time to write to rocks.toml + local user_rocks = require("rocks.config.internal").get_user_rocks() + assert.same({ + name = "neorg", + version = "7.0.0", + }, user_rocks.neorg) future = nio.control.future() operations.update(function() future.set(true)