From 0cc437486555401a0ebcfffe3b3a17a2d0cbc8cc Mon Sep 17 00:00:00 2001 From: DarthMooMancer Date: Fri, 22 Aug 2025 19:30:24 -0400 Subject: [PATCH 1/3] wip --- lua/Polydev/languages.lua | 301 +++++++++++++++++++------------------- lua/Polydev/utils.lua | 7 +- 2 files changed, 158 insertions(+), 150 deletions(-) diff --git a/lua/Polydev/languages.lua b/lua/Polydev/languages.lua index 12e5168..7e09b52 100644 --- a/lua/Polydev/languages.lua +++ b/lua/Polydev/languages.lua @@ -8,187 +8,190 @@ local loaded_languages = {} ---@param opts? table ---@return boolean function M.load_language_module(lang, opts) - if loaded_languages[lang] then return true end + 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 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 + 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 + lang_mod:setup(opts and opts[lang] or {}) + loaded_languages[lang] = lang_mod + return true end M.languages = { - java = { - setup = function (self, user_opts) - local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {}) - vim.api.nvim_create_user_command("JavaRun", function() self:run() end, {}) - for key, _ in pairs(opts.keybinds) do - vim.keymap.set("n", key, ":JavaRun", { silent = true }) - end - end, - run = function () - local root = utils.get_project_root() + java = { + setup = function (self, user_opts) + local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {}) + vim.api.nvim_create_user_command("JavaRun", function() self:run() end, {}) + for key, _ in pairs(opts.keybinds) do + vim.keymap.set("n", key, ":JavaRun", { silent = true }) + end + end, + run = function () + local root = utils.get_project_root() - local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java") - local output = vim.fn.system(cmd) + local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java") + local output = vim.fn.system(cmd) - if not vim.v.shell_error == 0 then - local term_buf = utils.terminal({ cmd }) - 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_set_option_value("modifiable", false, { win = term_buf }) - else - utils.terminal({ "java -cp " .. root, "build" .. " Main" }) - end + if not vim.v.shell_error == 0 then + local term_buf = utils.terminal({ cmd }) + 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_set_option_value("modifiable", false, { win = term_buf }) + else + utils.terminal({ "java -cp " .. root, "build" .. " Main" }) + end end - }, - c = { - setup = function (self, user_opts) - local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {}) - vim.api.nvim_create_user_command("CRun", function () self:run() end, {}) - for key, _ in pairs(opts.keybinds) do - vim.keymap.set("n", key, ":CRun", { silent = true }) - end - end, - run = function () - local root = utils.get_project_root() - local build_dir = root .. "/build" + }, + c = { + setup = function (self, user_opts) + local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {}) + vim.api.nvim_create_user_command("CRun", function () self:run() end, {}) + for key, _ in pairs(opts.keybinds) do + vim.keymap.set("n", key, ":CRun", { silent = true }) + end + end, + run = function () + local root = utils.get_project_root() + local build_dir = root .. "/build" - local cmd = "cd '" .. build_dir .. "' && cmake --build ." - local output = vim.fn.system(cmd) - local success = vim.v.shell_error == 0 + local cmd = "cd '" .. build_dir .. "' && cmake --build ." + local output = vim.fn.system(cmd) + local success = vim.v.shell_error == 0 - if not success then - local term_buf = utils.terminal({ cmd }) - 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_set_option_value("modifiable", false, { win = term_buf }) - end - if success then - local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name() - utils.terminal({ run_cmd }) - end + if not success then + local term_buf = utils.terminal({ cmd }) + 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_set_option_value("modifiable", false, { win = term_buf }) + end + if success then + local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name() + utils.terminal({ run_cmd }) + end end }, cpp = { - setup = function (self, user_opts) - local opts = vim.tbl_deep_extend("force", {}, configs.get("cpp"), user_opts or {}) - vim.api.nvim_create_user_command("CppRun", function () self:run() end, {}) - for key, _ in pairs(opts.keybinds) do - vim.keymap.set("n", key, ":CppRun", { silent = true }) - end - end, - run = function () - local root = utils.get_project_root() - local build_dir = root .. "/build" + setup = function (self, user_opts) + local opts = vim.tbl_deep_extend("force", {}, configs.get("cpp"), user_opts or {}) + vim.api.nvim_create_user_command("CppRun", function () self:run() end, {}) + for key, _ in pairs(opts.keybinds) do + vim.keymap.set("n", key, ":CppRun", { silent = true }) + end + end, + run = function () + local root = utils.get_project_root() + local build_dir = root .. "/build" + if utils.exists(build_dir) == nil then + vim.fn.mkdir(build_dir, "p") + vim.fn.system(string.format("cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. && ln -sf compile_commands.json ../compile_commands.json", root)) + end - local cmd = "cd '" .. build_dir .. "' && cmake --build ." - local output = vim.fn.system(cmd) - local success = vim.v.shell_error == 0 + local cmd = "cd '" .. build_dir .. "' && cmake --build ." + local output = vim.fn.system(cmd) + local success = vim.v.shell_error == 0 - if not success then - local term_buf = utils.terminal({ cmd }) + if not success then + local term_buf = utils.terminal({ cmd }) - vim.api.nvim_set_option_value("modifiable", true, { buf = 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_set_option_value("modifiable", false, { buf = term_buf }) - - end - if success then - local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name() - utils.terminal({ run_cmd }) - end - end + vim.api.nvim_set_option_value("modifiable", true, { buf = 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_set_option_value("modifiable", false, { buf = term_buf }) + end + if success then + local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name() + utils.terminal({ run_cmd }) + end + end }, html = { - setup = function (user_opts) - vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {}) - end + setup = function (user_opts) + vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {}) + end }, rust = { - setup = function (self, user_opts) - local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {}) - vim.api.nvim_create_user_command("RustRun", function () self:run() end, {}) - for key, _ in pairs(opts.keybinds) do - vim.keymap.set("n", key, ":RustRun", { silent = true }) - end - end, - run = function () - local root = utils.get_project_root() - if not root then return print("Error: Project root not found.") end + setup = function (self, user_opts) + local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {}) + vim.api.nvim_create_user_command("RustRun", function () self:run() end, {}) + for key, _ in pairs(opts.keybinds) do + vim.keymap.set("n", key, ":RustRun", { silent = true }) + end + end, + run = function () + local root = utils.get_project_root() + if not root then return print("Error: Project root not found.") end - local cmd = { "cargo build" } - local output = vim.fn.system(table.concat(cmd)) + local cmd = { "cargo build" } + local output = vim.fn.system(table.concat(cmd)) - if not vim.v.shell_error == 0 then - local term_buf = utils.terminal(cmd) - 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_set_option_value("modifiable", false, { win = term_buf }) + if not vim.v.shell_error == 0 then + local term_buf = utils.terminal(cmd) + 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_set_option_value("modifiable", false, { win = term_buf }) else - utils.terminal({ "cargo run" }) + utils.terminal({ "cargo run" }) end - end + end }, python = { - setup = function(self, user_opts) - local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {}) - vim.api.nvim_create_user_command("PythonPip", function () self:install_dependency() end, {}) - vim.api.nvim_create_user_command("PythonRun", function () self:run() end, {}) - for key, command in pairs(opts.keybinds) do - if command == "PythonRun" then - vim.keymap.set("n", key, ":PythonRun", { silent = true }) - end - if command == "PythonPip" then - vim.keymap.set("n", key, ":PythonPip", { silent = true }) - end - end + setup = function(self, user_opts) + local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {}) + vim.api.nvim_create_user_command("PythonPip", function () self:install_dependency() end, {}) + vim.api.nvim_create_user_command("PythonRun", function () self:run() end, {}) + for key, command in pairs(opts.keybinds) do + if command == "PythonRun" then + vim.keymap.set("n", key, ":PythonRun", { silent = true }) + end + if command == "PythonPip" then + vim.keymap.set("n", key, ":PythonPip", { silent = true }) + end + end - local root = utils.get_project_root() - if root then - local venv_path = root .. "/venv/bin/activate" - if vim.fn.filereadable(venv_path) == 1 then - vim.env.VIRTUAL_ENV = venv_path - vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH - end + local root = utils.get_project_root() + if root then + local venv_path = root .. "/venv/bin/activate" + if vim.fn.filereadable(venv_path) == 1 then + vim.env.VIRTUAL_ENV = venv_path + vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH + end + end + end, + install_dependency = function () + vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module) + if not pip_module or pip_module == "" then return print("Pip canceled") end + utils.terminal({ "pip install " .. pip_module }) + end) + end, + run = function () + utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" }) end - end, - install_dependency = function () - vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module) - if not pip_module or pip_module == "" then return print("Pip canceled") end - utils.terminal({ "pip install " .. pip_module }) - end) - end, - run = function () - utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" }) - end }, lua = { - setup = function (self, user_opts) - local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {}) - vim.api.nvim_create_user_command("LuaRun", function () self:run() end, {}) - for key, _ in pairs(opts.keybinds) do - vim.keymap.set("n", key, ":LuaRun", { silent = true }) + setup = function (self, user_opts) + local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {}) + vim.api.nvim_create_user_command("LuaRun", function () self:run() end, {}) + for key, _ in pairs(opts.keybinds) do + vim.keymap.set("n", key, ":LuaRun", { silent = true }) + end + end, + run = function () + local init_lua_path = utils.get_project_root() .. "/lua/" .. utils.get_project_name() .. "/init.lua" + if vim.fn.filereadable(init_lua_path) == 1 then + utils.terminal({ "lua " .. init_lua_path }) + end end - end, - run = function () - local init_lua_path = utils.get_project_root() .. "/lua/" .. utils.get_project_name() .. "/init.lua" - if vim.fn.filereadable(init_lua_path) == 1 then - utils.terminal({ "lua " .. init_lua_path }) - end - end }, } diff --git a/lua/Polydev/utils.lua b/lua/Polydev/utils.lua index b72a89b..f17168e 100644 --- a/lua/Polydev/utils.lua +++ b/lua/Polydev/utils.lua @@ -1,10 +1,15 @@ -local M = {} + M.opts = {} function M.setup(opts) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {}) end +function exists(path) + return (io.open(path,"r") ~= nil) +end + + ---@return string function M.get_project_root() local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h") From bc825895ac52220bd2fba77056090f4c5b34b418 Mon Sep 17 00:00:00 2001 From: DarthMooMancer Date: Mon, 1 Sep 2025 00:36:35 -0400 Subject: [PATCH 2/3] fix: changed formatting and defaults for c/c++ --- lua/Polydev/templates.lua | 56 ++++++++++++++++++++++++--------------- lua/Polydev/utils.lua | 5 ++-- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/lua/Polydev/templates.lua b/lua/Polydev/templates.lua index f078454..35d64e7 100644 --- a/lua/Polydev/templates.lua +++ b/lua/Polydev/templates.lua @@ -94,24 +94,30 @@ setup( #include int main() { - printf("%s", "Hello World"); - return 0; + printf("%s", "Hello World"); + return 0; } ]]) utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(%s) -include_directories(include) -set(SOURCES src/main.c) -add_executable(%s ${SOURCES}) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) +include_directories(include) -# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg -# target_link_libraries(Game PRIVATE SDL3::SDL3) -]], project_name, project_name)) - local gitignore = { "build/" } +set(SOURCES + src/main.c +) + +add_executable(%s ${SOURCES}) + +# find_package(Curses REQUIRED) +# 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 .. && ln -sf compile_commands.json ../compile_commands.json", full_project_root)) vim.cmd("edit " .. full_project_root .. "/src/main.c") @@ -127,25 +133,31 @@ set(CMAKE_C_STANDARD_REQUIRED ON) #include int main() { - std::cout << "Hello World" << std::endl; - return 0; + std::cout << "Hello World" << std::endl; + return 0; } ]]) utils.write_file({ full_project_root, "CMakeLists.txt" }, string.format([[ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.16) project(%s) -include_directories(include) -set(SOURCES src/main.cpp) -add_executable(%s ${SOURCES}) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) +include_directories(include) -# find_package(SDL3 CONFIG REQUIRED) # An example of how to import libraries from vcpkg -# target_link_libraries(Game PRIVATE SDL3::SDL3) -]], project_name, project_name)) +set(SOURCES + src/main.cpp +) - local gitignore = { "build/" } +add_executable(%s ${SOURCES}) + +# find_package(Curses REQUIRED) +# 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 .. && ln -sf compile_commands.json ../compile_commands.json", full_project_root)) vim.cmd("edit " .. full_project_root .. "/src/main.cpp") diff --git a/lua/Polydev/utils.lua b/lua/Polydev/utils.lua index f17168e..763642c 100644 --- a/lua/Polydev/utils.lua +++ b/lua/Polydev/utils.lua @@ -1,15 +1,14 @@ - +local M = {} M.opts = {} function M.setup(opts) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {}) end -function exists(path) +function M.exists(path) return (io.open(path,"r") ~= nil) end - ---@return string function M.get_project_root() local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h") From e701aa1feb5258e2af2e0cf890611a517b496ad7 Mon Sep 17 00:00:00 2001 From: dmm <107283522+DarthMooMancer@users.noreply.github.com> Date: Thu, 4 Sep 2025 20:52:09 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bb4961e..1c3fea7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

Polydev

-

A multi-language project managing plugin for file creation, building, and running code—all within neovim. Whether you're coding in Java, Python, Lua, Rust, or more, Polydev provides seamless integration to boost your productivity inside Neovim.

+

A multi-language project managing plugin for file creation, building, and running code—all within neovim. Whether you're coding in C/C++ Java, Python, Lua, Rust, and more, Polydev provides seamless integration to boost your productivity inside Neovim.

@@ -10,9 +10,8 @@

-

- Polydev Preview -

+ +https://github.com/user-attachments/assets/39d406e7-19cc-4040-823f-0a5c30dec714 ## Features @@ -26,7 +25,6 @@ > 📚 [View the full documentation](https://darthmoomancer.github.io/Polydev/) for setup, configuration, and usage details. - ## Supported Languages Polydev currently supports the following languages: