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