From 13d16ae329b71419e1a90917cba521198b1ae864 Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:54:23 -0400 Subject: [PATCH] Changing files to use opts and simplify config --- lua/Polydev/configs.lua | 17 ++++++++------ lua/Polydev/init.lua | 6 ++++- lua/Polydev/languages/python.lua | 39 +++++++++++++++++--------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/lua/Polydev/configs.lua b/lua/Polydev/configs.lua index 86455e7..79d4902 100644 --- a/lua/Polydev/configs.lua +++ b/lua/Polydev/configs.lua @@ -1,6 +1,6 @@ local M = {} -M.config = { +M.defaults = { terminal = { right_padding = 0, bottom_padding = 0, @@ -11,13 +11,16 @@ M.config = { relativenumber = true, scroll = true, } + -- java = { indent = 4 }, + -- python = { formatter = "black", linting = true }, + -- lua = { diagnostics = true }, + -- c = { compiler = "gcc" }, + -- cpp = { compiler = "g++" }, + -- rust = { edition = "2021" }, + -- html = { use_tailwind = false }, } -function M.setup(opts) - opts = opts or {} - - -- Make sure nested tables are deep-merged - M.config.terminal = vim.tbl_deep_extend("force", M.config.terminal, opts.terminal or {}) -end +-- This will be updated by setup() +M.user_config = vim.deepcopy(M.defaults) return M diff --git a/lua/Polydev/init.lua b/lua/Polydev/init.lua index 6e8c2b2..474bb57 100644 --- a/lua/Polydev/init.lua +++ b/lua/Polydev/init.lua @@ -1,7 +1,7 @@ local M = {} M.loaded_languages = {} -M.configs = require("Polydev.configs") +M.config = require("Polydev.configs") M.java = require("Polydev.languages.java") M.c = require("Polydev.languages.c") M.cpp = require("Polydev.languages.cpp") @@ -49,6 +49,10 @@ end function M.setup(opts) opts = opts or {} + for lang, user_opts in pairs(opts) do + local default = M.config.defaults[lang] or {} + M.config.user_config[lang] = vim.tbl_deep_extend("force", default, user_opts) + end vim.api.nvim_create_user_command("NewProject", M.create_project, {}) vim.api.nvim_create_user_command("NewFile", M.create_new_file, {}) diff --git a/lua/Polydev/languages/python.lua b/lua/Polydev/languages/python.lua index 35f8be4..48cb3d3 100644 --- a/lua/Polydev/languages/python.lua +++ b/lua/Polydev/languages/python.lua @@ -1,5 +1,6 @@ -local M = {} +local config = require("Polydev.config") local utils = require("Polydev.utils") +local M = {} M.c_run = nil M.new_pip_module = nil @@ -98,23 +99,25 @@ setup( end function M.create_new_file() - vim.ui.input({ prompt = "Enter file name: " }, function(file_name) - if not file_name or file_name == "" then - return print("File creation canceled.") - end - - if not file_name:match("%.py$") then - file_name = file_name .. ".py" - end - - local root_dir = M.get_project_root() - if not root_dir then - return print("Error: Project root not found.") - end - - local file_path = root_dir .. "/include/" .. file_name - utils.write_file(file_path, "") - end) + local opts = config.user_config.python + print("Creating Python project with formatter: " .. opts.formatter) + -- vim.ui.input({ prompt = "Enter file name: " }, function(file_name) + -- if not file_name or file_name == "" then + -- return print("File creation canceled.") + -- end + -- + -- if not file_name:match("%.py$") then + -- file_name = file_name .. ".py" + -- end + -- + -- local root_dir = M.get_project_root() + -- if not root_dir then + -- return print("Error: Project root not found.") + -- end + -- + -- local file_path = root_dir .. "/include/" .. file_name + -- utils.write_file(file_path, "") + -- end) end function M.install_dependency()