diff --git a/docs/languages/c.md b/docs/languages/c.md index 54ee516..4b305bd 100644 --- a/docs/languages/c.md +++ b/docs/languages/c.md @@ -1,10 +1,5 @@ ### C Setup for Polydev 🛠️ -#### Key Notes ⚠️ -> **Important**: The first time you build a project, it might throw an error. This is expected behavior. Simply rerun the build, and if errors persist, it may be an issue with your project setup rather than the plugin. - ---- - #### Keybinds 🎮 You can customize keybinds for your C projects with Polydev. diff --git a/docs/languages/cpp.md b/docs/languages/cpp.md index 2d9ab6d..e427131 100644 --- a/docs/languages/cpp.md +++ b/docs/languages/cpp.md @@ -1,10 +1,5 @@ ### C Setup for Polydev 🛠️ -#### Key Notes ⚠️ -> **Important**: The first time you build a project, it might throw an error. This is expected behavior. Simply rerun the build, and if errors persist, it may be an issue with your project setup rather than the plugin. - ---- - #### Keybinds 🎮 You can customize keybinds for your C projects with Polydev. diff --git a/lua/Polydev/init.lua b/lua/Polydev/init.lua index 4607c55..610889c 100644 --- a/lua/Polydev/init.lua +++ b/lua/Polydev/init.lua @@ -6,26 +6,23 @@ local Layout = require("nui.layout") local event = require("nui.utils.autocmd").event local Path = require("plenary.path") ----@type table local M = {} ----@type table M.loaded_languages = {} ----@param lang string ----@param opts table? ----@return boolean +---@type table +M.keybinds = {} + +-- Load language opts based on filetype function M.load_language_module(lang, opts) if M.loaded_languages[lang] then return true end - local ok, lang_module = pcall(require, "Polydev.languages." .. lang) - if ok and lang_module.setup then - local lang_opts = opts and opts[lang] or {} - lang_module.setup(lang_opts) - M.loaded_languages[lang] = lang_module - return true - end - return false + local ok, mod = pcall(require, "Polydev.languages." .. lang) + if not ok or type(mod.setup) ~= "function" then return false end + + mod.setup(opts and opts[lang] or {}) + M.loaded_languages[lang] = mod + return true end -- Get entries in a given path @@ -392,9 +389,6 @@ local function open_filtered_table() render() end ----@type table -M.keybinds = {} - local function setupKeybinds(opts) M.opts = {} diff --git a/lua/Polydev/utils.lua b/lua/Polydev/utils.lua index 1653694..7bd917c 100644 --- a/lua/Polydev/utils.lua +++ b/lua/Polydev/utils.lua @@ -7,9 +7,6 @@ local M = {} ---@type table M.opts = {} ----@type table -local presets_opts = {} - ---@param opts table function M.setup(opts) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {}) @@ -29,15 +26,14 @@ function M.write_file(path, content) file:write(content) file:close() vim.cmd("edit " .. path) - print(path .. " created successfully!") end ---@param cmd string ----@return boolean, table +---@return boolean?, table?, nil? function M.open_float_terminal(cmd) - if presets.getPresets(M.opts.presets) ~= nil then - presets_opts = presets.getPresets(M.opts.presets) - end + local presets_opts = {} + if presets.getPresets(M.opts.presets) == nil then return nil end + presets_opts = presets.getPresets(M.opts.presets) local ui = vim.api.nvim_list_uis()[1] local width = math.max(1, math.floor(ui.width * 0.9) - presets_opts.left_padding - presets_opts.right_padding) @@ -59,9 +55,9 @@ function M.open_float_terminal(cmd) vim.api.nvim_set_option_value("winhighlight", "Normal:Pmenu,FloatBorder:Pmenu", { win = win }) vim.api.nvim_set_option_value("cursorline", true, { win = win }) vim.api.nvim_set_option_value("scrolloff", 5, { win = win }) - if(M.opts.number == true) then + if(M.opts.number) then vim.api.nvim_set_option_value("number", true, { win = win }) - if(M.opts.relativenumber == true) then + if(M.opts.relativenumber) then vim.api.nvim_set_option_value("relativenumber", true, { win = win }) end end