Skip to content

Commit

Permalink
fix(operations): don't use parse_user_rocks in sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 10, 2023
1 parent 098efcd commit 7f99ef7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lua/rocks/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local operations = {}

---Decode the user rocks from rocks.toml, creating a default config file if it does not exist
---@return { rocks?: rock_table, plugins?: rock_table }
local function get_user_rocks()
local function parse_user_rocks()
local config_file = fs.read_or_create(config.config_path, constants.DEFAULT_CONFIG)
return require("toml_edit").parse(config_file)
end
Expand Down Expand Up @@ -175,7 +175,9 @@ operations.sync = function(user_rocks)

if user_rocks == nil then
-- Read or create a new config file and decode it
local user_config = get_user_rocks()
-- NOTE: This does not use parse_user_rocks because we decode with toml, not toml-edit
local config_file = fs.read_or_create(config.config_path, constants.DEFAULT_CONFIG)
local user_config = require("toml").decode(config_file)

-- Merge `rocks` and `plugins` fields as they are just an eye-candy separator for clarity purposes
user_rocks = vim.tbl_deep_extend("force", user_config.rocks or {}, user_config.plugins or {})
Expand Down Expand Up @@ -353,7 +355,7 @@ operations.update = function()

nio.scheduler()

local user_rocks = get_user_rocks()
local user_rocks = parse_user_rocks()

local progress_handle = progress.handle.create({
title = "Updating",
Expand Down Expand Up @@ -437,7 +439,7 @@ operations.add = function(rock_name, version)
message = ("%s -> %s"):format(installed_rock.name, installed_rock.version),
percentage = 100,
})
local user_rocks = get_user_rocks()
local user_rocks = parse_user_rocks()
-- FIXME(vhyrro): This currently works in a half-baked way.
-- The `toml-edit` libary will create a new empty table here, but if you were to try
-- and populate the table upfront then none of the values will be registered by `toml-edit`.
Expand Down Expand Up @@ -471,7 +473,7 @@ operations.prune = function(rock_name)
lsp_client = { name = constants.ROCKS_NVIM },
})
nio.run(function()
local user_config = get_user_rocks()
local user_config = parse_user_rocks()
if user_config.plugins then
user_config.plugins[rock_name] = nil
end
Expand Down

0 comments on commit 7f99ef7

Please sign in to comment.