Skip to content

Comments

fix: correctly handle user config#9

Merged
JavaHello merged 1 commit intoJavaHello:masterfrom
AbdElRahmanRMM:fix-config-handling
Sep 19, 2025
Merged

fix: correctly handle user config#9
JavaHello merged 1 commit intoJavaHello:masterfrom
AbdElRahmanRMM:fix-config-handling

Conversation

@AbdElRahmanRMM
Copy link
Contributor

Currently, the setup() function in config.lua reassigns the entire module table M to a new table returned by vim.tbl_extend. As a result, any existing references to the original M (such as the one returned when requiring the module) becomes stale. This causes inconsistent behavior where:

  • accessing keys from the table returned by require("java-deps.config") will result in the old values (ignoring any user supplied config).
  • functions within the module (like config.get_split_command() or config.has_numbers()) uses the new values (the ones from the user config).

That is because they are operating on different tables.

a minimal example that showcases the issue:

local function require_config()
    local M = {
        key = "original value"
    }
    M.setup = function (config)
        if config then
            M = vim.tbl_extend("force", M, config)
        end
    end
    M.get_key = function ()
        return M.key
    end
    return M
end

local config = require_config()
config.setup({ key = "new value"})
print(config.key)
print(config.get_key())

This will output

original value
new value

To fix this, I merged the new configuration directly into the existing M table. I also changed vim.tbl_extend to vim.tbl_deep_extend since the config has nested tables. There are other ways to fix this, but I think this approach minimize changes to the current codebase.

@JavaHello
Copy link
Owner

Thanks

@JavaHello JavaHello merged commit 5c37c95 into JavaHello:master Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants