This commit is contained in:
DarthMooMancer
2025-10-26 21:01:40 -04:00
parent 5420c54d9a
commit 45fcdf78be
4 changed files with 244 additions and 242 deletions
+66 -66
View File
@@ -3,85 +3,85 @@ local M = {}
---@param project_root string ---@param project_root string
---@return table ---@return table
local function default_languages(project_root) local function default_languages(project_root)
return { return {
rust = { rust = {
project_root = project_root .. "/Rust", project_root = project_root .. "/Rust",
keybinds = { keybinds = {
["<leader>pr"] = "RustRun", ["<leader>pr"] = "RustRun",
}, },
}, },
java = { java = {
project_root = project_root .. "/Java", project_root = project_root .. "/Java",
keybinds = { keybinds = {
["<leader>pr"] = "JavaRun", ["<leader>pr"] = "JavaRun",
}, },
}, },
lua = { lua = {
project_root = project_root .. "/Lua", project_root = project_root .. "/Lua",
keybinds = { keybinds = {
["<leader>pr"] = "LuaRun", ["<leader>pr"] = "LuaRun",
}, },
}, },
c = { c = {
project_root = project_root .. "/C", project_root = project_root .. "/C",
keybinds = { keybinds = {
["<leader>pr"] = "CRun", ["<leader>pr"] = "CRun",
}, },
}, },
cpp = { cpp = {
project_root = project_root .. "/CPP", project_root = project_root .. "/CPP",
keybinds = { keybinds = {
["<leader>pr"] = "CppRun", ["<leader>pr"] = "CppRun",
}, },
}, },
python = { python = {
project_root = project_root .. "/Python", project_root = project_root .. "/Python",
keybinds = { keybinds = {
["<leader>pr"] = "PythonRun", ["<leader>pr"] = "PythonRun",
["<leader>pb"] = "PythonPip", ["<leader>pb"] = "PythonPip",
}, },
}, },
html = { html = {
project_root = project_root .. "/Html", project_root = project_root .. "/Html",
}, },
} }
end end
M.user_config = {} M.user_config = {}
---@param user_opts table ---@param user_opts table
function M.setup(user_opts) function M.setup(user_opts)
local defaults = { local defaults = {
globals = { globals = {
project_root = "~/personal/Projects", project_root = "~/personal/Projects",
keybinds = { keybinds = {
["<leader>po"] = "PolydevManager", ["<leader>po"] = "PolydevManager",
}, },
}, },
terminal = { terminal = {
mode = "split", mode = "split",
win = { win = {
type = "horizontal", anchor = "bottom", size = "20" type = "horizontal", anchor = "bottom", size = "20"
}, },
border = { border = {
enabled = true, enabled = true,
type = "rounded", type = "rounded",
}, },
}, },
} }
M.user_config = vim.tbl_deep_extend("force", {}, defaults, user_opts or {}) M.user_config = vim.tbl_deep_extend("force", {}, defaults, user_opts or {})
local langs = default_languages(M.user_config.globals.project_root) local langs = default_languages(M.user_config.globals.project_root)
for lang, conf in pairs(langs) do for lang, conf in pairs(langs) do
M.user_config[lang] = vim.tbl_deep_extend("force", conf, M.user_config[lang] or {}) M.user_config[lang] = vim.tbl_deep_extend("force", conf, M.user_config[lang] or {})
end end
end end
---@param lang string ---@param lang string
---@return table ---@return table
function M.get(lang) function M.get(lang)
return M.user_config[lang] or {} return M.user_config[lang] or {}
end end
return M return M
+37 -38
View File
@@ -1,49 +1,48 @@
local M = {} local M = {}
function M.setup(opts) function M.setup(opts)
opts = opts or {} opts = opts or {}
local config = require("Polydev.configs") local config = require("Polydev.configs")
config.setup(opts) config.setup(opts)
require("Polydev.utils").setup(opts) require("Polydev.utils").setup(opts)
vim.api.nvim_create_user_command("PolydevOpen", function() require("Polydev.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, {})
local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {}) local keys = vim.tbl_deep_extend("force", {}, config.get("globals").keybinds, opts.keybinds or {})
for key, _ in pairs(keys) do for key, _ in pairs(keys) do
vim.keymap.set("n", key, ":PolydevOpen<CR>") vim.keymap.set("n", key, ":PolydevOpen<CR>")
end end
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
pattern = "*", pattern = "*",
callback = function() callback = function()
local filetype = vim.bo.filetype local filetype = vim.bo.filetype
require("Polydev.languages").load_language_module(filetype, opts) require("Polydev.languages").load_language_module(filetype, opts)
end, end,
}) })
vim.api.nvim_create_autocmd("ColorScheme", { vim.api.nvim_create_autocmd("ColorScheme", {
callback = function() callback = function()
local function define(name, o) local function define(name, o)
if vim.fn.hlexists(name) == 0 then if vim.fn.hlexists(name) == 0 then
vim.api.nvim_set_hl(0, name, o) vim.api.nvim_set_hl(0, name, o)
end end
end end
define("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,
})
define("PolydevNormal", { define("PolydevBorder", {
fg = vim.api.nvim_get_hl(0, { name = "NormalFloat", link = true }).fg, fg = vim.api.nvim_get_hl(0, { name = "FloatBorder", link = true }).fg,
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg, bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
}) })
define("PolydevBorder", { define("PolydevTitle", {
fg = vim.api.nvim_get_hl(0, { name = "FloatBorder", link = true }).fg, fg = vim.api.nvim_get_hl(0, { name = "FloatTitle", link = true }).fg, bold = true,
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg, bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
}) })
end,
define("PolydevTitle", { })
fg = vim.api.nvim_get_hl(0, { name = "FloatTitle", link = true }).fg, bold = true,
bg = vim.api.nvim_get_hl(0, { name = "Normal", link = true }).bg,
})
end,
})
end end
return M return M
+137 -136
View File
@@ -3,9 +3,9 @@ local utils = require("Polydev.utils")
local M = {} local M = {}
local function extras(guard, file_type, file_name) local function extras(guard, file_type, file_name)
if not file_name then return print("Header file creation canceled") end if not file_name then return print("Header file creation canceled") end
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
local content = string.format([[ local content = string.format([[
#ifndef %s #ifndef %s
#define %s #define %s
@@ -13,56 +13,56 @@ local function extras(guard, file_type, file_name)
#endif #endif
]], guard_macro, guard_macro) ]], guard_macro, guard_macro)
utils.write_file({ utils.get_project_root(), "include", file_name .. file_type }, content) utils.write_file({ utils.get_project_root(), "include", file_name .. file_type }, content)
end end
M.projects = { M.projects = {
lua = { lua = {
run = function(project_name, project_root) run = function(project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p") vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p")
utils.write_file({ full_project_root, "lua", project_name, "init.lua" }, [[ utils.write_file({ full_project_root, "lua", project_name, "init.lua" }, [[
local M = {} local M = {}
return M return M
]]) ]])
local gitignore = { "" } local gitignore = { "" }
utils.init_git(full_project_root, gitignore) utils.init_git(full_project_root, gitignore)
vim.cmd("edit " .. full_project_root .. "/lua/" .. project_name .. "/init.lua") vim.cmd("edit " .. full_project_root .. "/lua/" .. project_name .. "/init.lua")
end end
}, },
java = { java = {
run = function(project_name, project_root) run = function(project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(full_project_root .. path, "p") end for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(full_project_root .. path, "p") end
local content = [[ local content = [[
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello, World!"); System.out.println("Hello, World!");
} }
} }
]] ]]
local gitignore = { local gitignore = {
"build/" "build/"
} }
utils.init_git(full_project_root, gitignore) utils.init_git(full_project_root, gitignore)
utils.write_file({ full_project_root, "src", "Main.java" }, content) utils.write_file({ full_project_root, "src", "Main.java" }, content)
end end
}, },
python = { python = {
run = function(project_name, project_root) run = function(project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
vim.fn.mkdir(full_project_root .. "/include", "p") vim.fn.mkdir(full_project_root .. "/include", "p")
utils.write_file({ full_project_root, "main.py" }, [[ utils.write_file({ full_project_root, "main.py" }, [[
def main(): def main():
print("Hello, World!") print("Hello, World!")
if __name__ == "__main__": if __name__ == "__main__":
main() main()
]]) ]])
utils.write_file({ full_project_root, "include/__init__.py" }, "") utils.write_file({ full_project_root, "include/__init__.py" }, "")
utils.write_file({ full_project_root, "requirements.txt" }, "") utils.write_file({ full_project_root, "requirements.txt" }, "")
utils.write_file({ full_project_root, "setup.py" }, string.format([[ utils.write_file({ full_project_root, "setup.py" }, string.format([[
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup( setup(
@@ -73,24 +73,24 @@ setup(
python_requires=">=3.6", python_requires=">=3.6",
) )
]], project_name)) ]], project_name))
local gitignore = { local gitignore = {
"venv/" "venv/"
} }
utils.init_git(full_project_root, gitignore) utils.init_git(full_project_root, gitignore)
vim.cmd("edit " .. full_project_root .. "/main.py") vim.cmd("edit " .. full_project_root .. "/main.py")
local venv_path = full_project_root .. "/venv" local venv_path = full_project_root .. "/venv"
vim.fn.system("python3 -m venv " .. venv_path) vim.fn.system("python3 -m venv " .. venv_path)
vim.g.python3_host_prog = venv_path .. "/bin/python" vim.g.python3_host_prog = venv_path .. "/bin/python"
vim.fn.setenv("VIRTUAL_ENV", venv_path) vim.fn.setenv("VIRTUAL_ENV", venv_path)
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH")) vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
print("Virtual environment activated for " .. project_name) print("Virtual environment activated for " .. project_name)
end end
}, },
c = { c = {
run = function(project_name, project_root) run = function(project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build", "/include" }) do vim.fn.mkdir(full_project_root .. path, "p") end for _, path in ipairs({ "/src", "/build", "/include" }) do vim.fn.mkdir(full_project_root .. path, "p") end
utils.write_file({ full_project_root, "src/main.c" }, [[ utils.write_file({ full_project_root, "src/main.c" }, [[
#include <stdio.h> #include <stdio.h>
int main() { int main() {
@@ -98,7 +98,7 @@ int main() {
return 0; return 0;
} }
]]) ]])
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[ utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(%s) project(%s)
set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD 23)
@@ -117,19 +117,19 @@ add_executable(%s ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
]], project_name, project_name, project_name)) ]], project_name, project_name, project_name))
local gitignore = { "build/", ".cache/" } local gitignore = { "build/", ".cache/" }
utils.init_git(full_project_root, gitignore) utils.init_git(full_project_root, gitignore)
vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", full_project_root)) vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", full_project_root))
vim.cmd("edit " .. full_project_root .. "/src/main.c") vim.cmd("edit " .. full_project_root .. "/src/main.c")
end end
}, },
cpp = { cpp = {
run = function (project_name, project_root) run = function (project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build", "/include" }) do for _, path in ipairs({ "/src", "/build", "/include" }) do
vim.fn.mkdir(full_project_root .. path, "p") vim.fn.mkdir(full_project_root .. path, "p")
end end
utils.write_file({ full_project_root, "src/main.cpp" }, [[ utils.write_file({ full_project_root, "src/main.cpp" }, [[
#include <iostream> #include <iostream>
int main() { int main() {
@@ -137,11 +137,12 @@ int main() {
return 0; return 0;
} }
]]) ]])
utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[ utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(%s)
set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(%s)
include_directories(include) include_directories(include)
set(SOURCES set(SOURCES
@@ -154,29 +155,28 @@ add_executable(%s ${SOURCES})
# include_directories(${CURSES_INCLUDE_DIR}) # include_directories(${CURSES_INCLUDE_DIR})
# target_link_libraries(%s ${CURSES_LIBRARIES}) # target_link_libraries(%s ${CURSES_LIBRARIES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
]], project_name, project_name, project_name)) ]], project_name, project_name, project_name))
local gitignore = { "build/", ".cache/" } local gitignore = { "build/", ".cache/" }
utils.init_git(full_project_root, gitignore) utils.init_git(full_project_root, gitignore)
vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", full_project_root)) vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..", full_project_root))
vim.cmd("edit " .. full_project_root .. "/src/main.cpp") vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
end end
}, },
rust = { rust = {
run = function (project_name, project_root) run = function (project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
vim.fn.system("cargo new " .. full_project_root) vim.fn.system("cargo new " .. full_project_root)
vim.cmd("edit " .. full_project_root .. "/src/main.rs") vim.cmd("edit " .. full_project_root .. "/src/main.rs")
end end
}, },
html = { html = {
run = function(project_name, project_root) run = function(project_name, project_root)
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
if vim.fn.isdirectory(full_project_root) == 0 then if vim.fn.isdirectory(full_project_root) == 0 then
vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories
end end
local main_html_content = [[ local main_html_content = [[
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@@ -190,50 +190,50 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
</body> </body>
</html> </html>
]] ]]
utils.write_file({ full_project_root, "index.html" }, main_html_content) utils.write_file({ full_project_root, "index.html" }, main_html_content)
end end
}, },
} }
M.files = { M.files = {
lua = { lua = {
run = function (file_name) run = function (file_name)
utils.write_file({ utils.get_project_root(), "lua", utils.get_project_name(), file_name .. ".lua"}, "") utils.write_file({ utils.get_project_root(), "lua", utils.get_project_name(), file_name .. ".lua"}, "")
end end
}, },
java = { java = {
run = function (file_name) run = function (file_name)
utils.write_file({ utils.get_project_root(), "src", file_name .. ".java" }, string.format([[ utils.write_file({ utils.get_project_root(), "src", file_name .. ".java" }, string.format([[
public class %s { public class %s {
// New File // New File
} }
]], file_name)) ]], file_name))
end end
}, },
python = { python = {
run = function (file_name) run = function (file_name)
utils.write_file({ utils.get_project_root(), "include", file_name .. ".py" }, "") utils.write_file({ utils.get_project_root(), "include", file_name .. ".py" }, "")
end end
}, },
c = { c = {
run = function (file_name) run = function (file_name)
utils.write_file({ utils.get_project_root(), "src", file_name .. ".c" }, "") utils.write_file({ utils.get_project_root(), "src", file_name .. ".c" }, "")
end end
}, },
cpp = { cpp = {
run = function (file_name) run = function (file_name)
utils.write_file({ utils.get_project_root(), "src", file_name .. ".cpp" }, "") utils.write_file({ utils.get_project_root(), "src", file_name .. ".cpp" }, "")
end end
}, },
rust = { rust = {
run = function (file_name) run = function (file_name)
utils.write_file({ utils.get_project_root(), "src", file_name .. ".rs" }, "") utils.write_file({ utils.get_project_root(), "src", file_name .. ".rs" }, "")
end end
}, },
html = { html = {
run = function (file_name) run = function (file_name)
utils.write_file({ ".", file_name .. ".html" }, string.format([[ utils.write_file({ ".", file_name .. ".html" }, string.format([[
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@@ -247,21 +247,22 @@ public class %s {
</body> </body>
</html> </html>
]])) ]]))
end end
} }
} }
M.extras = { M.extras = {
run = function (lang, file_name) run = function (lang, file_name)
if lang == "c" then if lang == "c" then
extras("_H", ".h", file_name) extras("_H", ".h", file_name)
print("Successful creation of " .. file_name .. ".h") print("Successful creation of " .. file_name .. ".h")
elseif lang == "cpp" then
extras("_HPP", ".hpp", file_name)
print("Successful creation of " .. file_name .. ".hpp")
else
print("Extras language is not found: enter cpp or c")
end
end end
if lang == "cpp" then
extras("_HPP", ".hpp", file_name)
print("Successful creation of " .. file_name .. ".hpp")
end
end
} }
return M return M
+4 -2
View File
@@ -224,7 +224,7 @@ function M.manager(project_root)
end end
end) end)
end end
end, {buffer = buf}) end, { buffer = buf })
vim.keymap.set("n", "%", function() vim.keymap.set("n", "%", function()
local lang, name = get_inputs("file") local lang, name = get_inputs("file")
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
@@ -248,7 +248,7 @@ function M.manager(project_root)
else else
print("Error: No File creation method for " .. lang) print("Error: No File creation method for " .. lang)
end end
end, {buffer = buf}) end, { buffer = buf })
vim.keymap.set("n", "d", function () vim.keymap.set("n", "d", function ()
local lang, name = get_inputs("project") local lang, name = get_inputs("project")
local opts = {} local opts = {}
@@ -280,6 +280,8 @@ function M.manager(project_root)
cwd = entry.full_path cwd = entry.full_path
vim.cmd("cd " .. cwd) vim.cmd("cd " .. cwd)
update_screen() update_screen()
else
print("Error")
end end
end, { buffer = buf }) end, { buffer = buf })
end end