From 7bdd18d983645ac94a943209d9fec9575d2b022f Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Mon, 14 Apr 2025 09:18:31 -0400 Subject: [PATCH] update to python to see if opts works --- lua/Polydev/python.lua | 3 ++- lua/Polydev/utils.lua | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/Polydev/python.lua b/lua/Polydev/python.lua index 35f8be4..47109de 100644 --- a/lua/Polydev/python.lua +++ b/lua/Polydev/python.lua @@ -15,7 +15,8 @@ M.config = { } function M.setup(opts) - M.config = vim.tbl_deep_extend("force", M.config, opts or {}) + M.config = utils.deep_merge_with_defaults(opts, M.config) + for key, command in pairs(M.config.keybinds) do if command == "PythonRun" then M.c_run = key end if command == "PythonPip" then M.new_pip_module = key end diff --git a/lua/Polydev/utils.lua b/lua/Polydev/utils.lua index 2b50f64..70a1455 100644 --- a/lua/Polydev/utils.lua +++ b/lua/Polydev/utils.lua @@ -1,6 +1,23 @@ local M = {} local term_cfg = require("Polydev.globals").config.terminal +function M.deep_merge_with_defaults(user_opts, default_opts) + local result = vim.deepcopy(default_opts or {}) + + local function merge(user, default) + for k, v in pairs(default) do + if type(v) == "table" and type(user[k]) == "table" then + merge(user[k], v) + elseif user[k] == nil then + user[k] = v + end + end + end + + merge(user_opts or {}, result) + return user_opts or result +end + function M.write_file(path, content) local file = assert(io.open(path, "w"), "Error creating file: " .. path) file:write(content)