fix(deprecated): replacing deprecated code throughout project

rework: moved load_language_module to languages as it makes more sense
This commit is contained in:
DarthMooMancer
2025-05-16 10:53:34 -04:00
parent 9eb38ba06e
commit 7e047478d5
5 changed files with 60 additions and 64 deletions
+19 -16
View File
@@ -1,21 +1,8 @@
local M = {}
M.defaults = {
globals = {
project_root = "~/Projects",
keybinds = {
["<leader>po"] = "PolydevManager",
},
},
terminal = {
preset = nil,
border = {
enabled = true,
type = "rounded",
},
},
}
---@param project_root string
---@return table
local function default_languages(project_root)
return {
rust = {
@@ -58,8 +45,24 @@ M.user_config = {}
---@param user_opts table
function M.setup(user_opts)
local defaults = {
globals = {
project_root = "~/Projects",
keybinds = {
["<leader>po"] = "PolydevManager",
},
},
terminal = {
preset = nil,
border = {
enabled = true,
type = "rounded",
},
},
}
-- First merge global and terminal
M.user_config = vim.tbl_deep_extend("force", {}, M.defaults, user_opts or {})
M.user_config = vim.tbl_deep_extend("force", {}, defaults, user_opts or {})
-- Now use the final resolved project_root from user_config
local root = M.user_config.globals.project_root
+2 -6
View File
@@ -2,14 +2,10 @@ local M = {}
function M.setup(opts)
local config = require("Polydev.configs")
local ui = require("Polydev.ui")
config.setup(opts)
require("Polydev.utils").setup(opts)
for lang, user_opts in pairs(opts) do
config.user_config[lang] = vim.tbl_deep_extend("force", config.defaults[lang] or {}, user_opts)
end
vim.api.nvim_create_user_command("PolydevOpen", function() ui.manager(config.get("globals").project_root) end, {})
vim.api.nvim_create_user_command("PolydevOpen", function() require("Polydev.ui").manager(config.get("globals").project_root) end, {})
-- require("Polydev.styles").setup_highlights()
local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {})
@@ -21,7 +17,7 @@ function M.setup(opts)
pattern = "*",
callback = function()
local filetype = vim.bo.filetype
ui.load_language_module(filetype, opts)
require("Polydev.languages").load_language_module(filetype, opts)
end,
})
end
+27 -8
View File
@@ -2,6 +2,25 @@ local utils = require("Polydev.utils")
local configs = require("Polydev.configs")
local M = {}
local loaded_languages = {}
---@param lang string
---@param opts? table
---@return boolean
function M.load_language_module(lang, opts)
if loaded_languages[lang] then return true end
local ok, mod = pcall(require, "Polydev.languages")
if not ok or type(mod.languages) ~= "table" then return false end
local lang_mod = mod.languages[lang]
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then return false end
lang_mod:setup(opts and opts[lang] or {})
loaded_languages[lang] = lang_mod
return true
end
M.languages = {
java = {
setup = function (self, user_opts)
@@ -19,11 +38,11 @@ M.languages = {
if not vim.v.shell_error == 0 then
local term_buf = utils.terminal({ cmd })
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
else
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
end
@@ -47,11 +66,11 @@ M.languages = {
if not success then
local term_buf = utils.terminal({ cmd })
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
end
if success then
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
@@ -77,11 +96,11 @@ M.languages = {
if not success then
local term_buf = utils.terminal({ cmd })
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
end
if success then
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
@@ -111,11 +130,11 @@ M.languages = {
if not vim.v.shell_error == 0 then
local term_buf = utils.terminal(cmd)
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_buf_set_option(term_buf, "modifiable", false)
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
else
utils.terminal({ "cargo run" })
end
+11 -33
View File
@@ -55,32 +55,10 @@ local function fuzzy_filter(list, query)
return result
end
local loaded_languages = {}
---@param lang string
---@param opts? table
---@return boolean
function M.load_language_module(lang, opts)
if loaded_languages[lang] then return true end
local ok, mod = pcall(require, "Polydev.languages")
if not ok or type(mod.languages) ~= "table" then
return false
end
local lang_mod = mod.languages[lang]
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then
return false
end
lang_mod:setup(opts and opts[lang] or {})
loaded_languages[lang] = lang_mod
return true
end
---@param project_root string
function M.manager(project_root)
local templates = require("Polydev.templates")
local languages = require("Polydev.languages")
local Popup = require("nui.popup")
local Layout = require("nui.layout")
local event = require("nui.utils.autocmd").event
@@ -89,9 +67,9 @@ function M.manager(project_root)
local current_view = vim.deepcopy(entries)
-- Create a new custom highlight group with Normal background and NormalFloat foreground
vim.api.nvim_set_hl(0, "CustomFloatText", {
fg = vim.api.nvim_get_hl_by_name("NormalFloat", true).foreground,
bg = vim.api.nvim_get_hl_by_name("Normal", true).background,
vim.api.nvim_set_hl(0, "PolydevNormal", {
fg = vim.api.nvim_get_hl(0, { name = "NormalFloat", link = true }).fg,
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
})
local popup, search, preview = Popup({
@@ -104,7 +82,7 @@ function M.manager(project_root)
position = "50%",
buf_options = { modifiable = true, readonly = false },
win_options = {
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
winhighlight = "Normal:PolydevNormal,FloatBorder:Function",
}
}), Popup({
enter = false,
@@ -115,7 +93,7 @@ function M.manager(project_root)
},
buf_options = { modifiable = true, readonly = false },
win_options = {
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
winhighlight = "Normal:PolydevNormal,FloatBorder:Function",
}
}), Popup({
enter = false,
@@ -127,7 +105,7 @@ function M.manager(project_root)
position = "50%",
buf_options = { modifiable = true, readonly = false },
win_options = {
winhighlight = "Normal:CustomFloatText,FloatBorder:Function",
winhighlight = "Normal:PolydevNormal,FloatBorder:Function",
}
})
local layout = Layout({
@@ -233,7 +211,7 @@ function M.manager(project_root)
local function prompt_filter()
vim.api.nvim_buf_set_lines(search.bufnr, 0, -1, false, { "" })
vim.api.nvim_buf_set_option(search.bufnr, "modifiable", true)
vim.api.nvim_set_option_value("modifiable", true, { win = search.bufnr })
if vim.api.nvim_win_is_valid(search.winid) then
vim.api.nvim_set_current_win(search.winid)
end
@@ -265,7 +243,7 @@ function M.manager(project_root)
popup:map("n", "%", function()
vim.ui.input({ prompt = "Enter language for new file: " }, function(lang)
if not lang or lang == "" then return print("File creation canceled") end
if M.load_language_module(lang) and templates.files[lang] and templates.files[lang].run then
if languages.load_language_module(lang) and templates.files[lang] and templates.files[lang].run then
popup:unmount()
vim.schedule(function()
vim.ui.input({ prompt = "Enter file name: " }, function(file_name)
@@ -283,7 +261,7 @@ function M.manager(project_root)
popup:map("n", "x", function()
vim.ui.input({ prompt = "Enter language for new auxilary file: "}, function(lang)
if not lang or lang == "" then return print("File create canceled") end
if M.load_language_module(lang) and templates.extras.run then
if languages.load_language_module(lang) and templates.extras.run then
popup:unmount()
vim.schedule(function()
vim.ui.input({ prompt = "Enter file name: "}, function(file_name)
@@ -314,7 +292,7 @@ function M.manager(project_root)
vim.ui.input({ prompt = "Enter language for project: " }, function(lang)
if not lang or lang == "" then return print("Project creation canceled") end
opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get(lang), opts or {})
if M.load_language_module(lang) and templates.projects[lang] and templates.projects[lang].run then
if languages.load_language_module(lang) and templates.projects[lang] and templates.projects[lang].run then
-- if templates.projects[lang] and templates.projects[lang].run then
popup:unmount()
vim.schedule(function()
+1 -1
View File
@@ -87,7 +87,7 @@ function M.terminal(cmd)
vim.api.nvim_set_option_value("cursorline", true, { win = win })
vim.api.nvim_set_option_value("scrolloff", 5, { win = win })
vim.fn.termopen(table.concat(cmd, "/"))
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
return buf, win
end