First release. Polydev is finally in stable condition to be more of a

release than a base commit
This commit is contained in:
DarthMooMancer
2025-04-16 02:06:14 -04:00
parent 7e7ac2f072
commit 8aa730a66d
10 changed files with 142 additions and 133 deletions
+2 -2
View File
@@ -13,13 +13,13 @@ The ability to -
* Build those files * Build those files
* Run those files * Run those files
* Builtin terminal for running code * Builtin terminal for running code
* And More!
### Currently Supported (And working) Languages ### Currently Supported (And working) Languages
* Java * Java
* Python * Python
* C * C/C++
* Lua * Lua
* C++
## Questions and Contributing ## Questions and Contributing
+62 -1
View File
@@ -1,6 +1,50 @@
local M = {} local M = {}
---@class Keybinds
---@field [string] string
---
---@class Language
---@field project_root string
---@field keybinds? Keybinds -- ? makes fields optional
---@field build_attributes? string
---
---@class Terminal
---@field right_padding integer
---@field left_padding integer
---@field bottom_padding integer
---@field top_padding integer
---@field border boolean
---@field number boolean
---@field relativenumber boolean
---
---@class Defaults
---@field html Language
---@field rust Language
---@field java Language
---@field python Language
---@field lua Language
---@field c Language
---@field cpp Language
---@field terminal Terminal
---@type Defaults
M.defaults = { M.defaults = {
html = {
project_root = "~/Projects/Html",
},
rust = {
project_root = "~/Projects/Rust",
keybinds = {
["<leader>pb"] = "RustBuild",
["<leader>pr"] = "RustRun",
},
},
java = {
project_root = "~/Projects/Java",
keybinds = {
["<leader>pb"] = "JavaBuild",
["<leader>pr"] = "JavaRun",
},
},
python = { python = {
project_root = "~/Projects/Python", project_root = "~/Projects/Python",
keybinds = { keybinds = {
@@ -14,6 +58,24 @@ M.defaults = {
["<leader>pr"] = "LuaRun", ["<leader>pr"] = "LuaRun",
}, },
}, },
c = {
project_root = "~/Projects/C",
keybinds = {
["<leader>pb"] = "CBuild",
["<leader>pr"] = "CRun",
["<leader>nh"] = "NewCHeaderFile",
},
build_attributes = ""
},
cpp = {
project_root = "~/Projects/Cpp",
keybinds = {
["<leader>pb"] = "CppBuild",
["<leader>pr"] = "CppRun",
["<leader>nh"] = "NewCppHeaderFile",
},
build_attributes = "",
},
terminal = { terminal = {
right_padding = 0, right_padding = 0,
bottom_padding = 0, bottom_padding = 0,
@@ -22,7 +84,6 @@ M.defaults = {
border = true, border = true,
number = true, number = true,
relativenumber = true, relativenumber = true,
scroll = true,
} }
} }
+1
View File
@@ -51,6 +51,7 @@ end
function M.setup(opts) function M.setup(opts)
opts = opts or {} opts = opts or {}
M.config.setup(opts) M.config.setup(opts)
M.utils.setup(opts)
for lang, user_opts in pairs(opts) do for lang, user_opts in pairs(opts) do
local default = M.config.defaults[lang] or {} local default = M.config.defaults[lang] or {}
M.config.user_config[lang] = vim.tbl_deep_extend("force", default, user_opts) M.config.user_config[lang] = vim.tbl_deep_extend("force", default, user_opts)
+17 -24
View File
@@ -1,38 +1,30 @@
local M = {}
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
local M = {}
M.c_build = nil M.keybinds = {}
M.c_run = nil M.opts = nil
M.new_c_header_file = nil
M.config = {
project_root = "~/Projects/C",
keybinds = {
["<leader>pb"] = "CBuild",
["<leader>pr"] = "CRun",
["<leader>nh"] = "NewCHeaderFile",
},
build_attributes = ""
}
function M.setup(opts) function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("c"), opts or {})
for key, command in pairs(M.config.keybinds) do for key, command in pairs(M.opts.keybinds) do
if command == "CBuild" then M.c_build = key end M.keybinds[command] = key
if command == "CRun" then M.c_run = key end
if command == "NewCHeaderFile" then M.new_c_header_file = key end
end end
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {}) vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {})
vim.api.nvim_create_user_command("CBuild", M.build, {}) vim.api.nvim_create_user_command("CBuild", M.build, {})
vim.api.nvim_create_user_command("CRun", M.run, {}) vim.api.nvim_create_user_command("CRun", M.run, {})
vim.keymap.set("n", M.c_build, ":CBuild<CR>", { silent = true }) if M.keybinds.CBuild then
vim.keymap.set("n", M.c_run, ":CRun<CR>", { silent = true }) vim.keymap.set("n", M.keybinds.CBuild, ":CBuild<CR>", { silent = true })
vim.keymap.set("n", M.new_c_header_file, ":NewCHeaderFile<CR>", { silent = true }) end
if M.keybinds.CRun then
vim.keymap.set("n", M.keybinds.CRun, ":CRun<CR>", { silent = true })
end
if M.keybinds.NewCHeaderFile then
vim.keymap.set("n", M.keybinds.NewCHeaderFile, ":NewCHeaderFile<CR>", { silent = true })
end
end end
function M.create_project() function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name) vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then if not project_name or project_name == "" then
@@ -40,7 +32,7 @@ function M.create_project()
return return
end end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build", "/include" }) do for _, path in ipairs({ "/src", "/build", "/include" }) do
vim.fn.mkdir(project_root .. path, "p") vim.fn.mkdir(project_root .. path, "p")
end end
@@ -108,6 +100,7 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
]])) ]]))
vim.cmd("edit " .. project_root .. "/src/main.c") vim.cmd("edit " .. project_root .. "/src/main.c")
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", project_root))
end) end)
end end
+22 -27
View File
@@ -1,35 +1,28 @@
local M = {}
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
local M = {}
M.c_build = nil M.keybinds = {}
M.c_run = nil M.opts = nil
M.new_c_header_file = nil
M.config = {
project_root = "~/Projects/C",
keybinds = {
["<leader>pb"] = "CBuild",
["<leader>pr"] = "CRun",
["<leader>nh"] = "NewCHeaderFile",
},
build_attributes = ""
}
function M.setup(opts) function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("cpp"), opts or {})
for key, command in pairs(M.config.keybinds) do for key, command in pairs(M.opts.keybinds) do
if command == "CBuild" then M.c_build = key end M.keybinds[command] = key
if command == "CRun" then M.c_run = key end
if command == "NewCHeaderFile" then M.new_c_header_file = key end
end end
vim.api.nvim_create_user_command("NewCHeaderFile", M.create_new_header_file, {}) vim.api.nvim_create_user_command("NewCppHeaderFile", M.create_new_header_file, {})
vim.api.nvim_create_user_command("CBuild", M.build, {}) vim.api.nvim_create_user_command("CppBuild", M.build, {})
vim.api.nvim_create_user_command("CRun", M.run, {}) vim.api.nvim_create_user_command("CppRun", M.run, {})
vim.keymap.set("n", M.c_build, ":CBuild<CR>", { silent = true }) if M.keybinds.CppBuild then
vim.keymap.set("n", M.c_run, ":CRun<CR>", { silent = true }) vim.keymap.set("n", M.keybinds.CppBuild, ":CppBuild<CR>", { silent = true })
vim.keymap.set("n", M.new_c_header_file, ":NewCHeaderFile<CR>", { silent = true }) end
if M.keybinds.CppRun then
vim.keymap.set("n", M.keybinds.CppRun, ":CppRun<CR>", { silent = true })
end
if M.keybinds.NewCppHeaderFile then
vim.keymap.set("n", M.keybinds.NewCppHeaderFile, ":NewCppHeaderFile<CR>", { silent = true })
end
end end
function M.create_project() function M.create_project()
@@ -39,7 +32,7 @@ function M.create_project()
return return
end end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build", "/include" }) do for _, path in ipairs({ "/src", "/build", "/include" }) do
vim.fn.mkdir(project_root .. path, "p") vim.fn.mkdir(project_root .. path, "p")
end end
@@ -63,7 +56,7 @@ int main() {
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(%s) project(%s)
include_directories(include) include_directories(include)
set(SOURCES src/main.c) set(SOURCES src/main.cpp)
add_executable(%s ${SOURCES}) add_executable(%s ${SOURCES})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_C_STANDARD 23) set(CMAKE_C_STANDARD 23)
@@ -106,6 +99,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
} }
]])) ]]))
vim.fn.system(string.format("cd %s/build/ && cmake .. && cmake --build .", project_root))
vim.cmd("edit " .. project_root .. "/src/main.cpp") vim.cmd("edit " .. project_root .. "/src/main.cpp")
end) end)
end end
+4 -10
View File
@@ -1,21 +1,16 @@
local M = {}
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
local M = {}
M.html_build = nil M.opts = nil
M.html_run = nil
M.config = {
project_root = "~/Projects/Html",
}
function M.setup(opts) function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("html"), opts or {})
end end
function M.create_project() function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name) vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
local main_html_content = [[ local main_html_content = [[
<!DOCTYPE html> <!DOCTYPE html>
@@ -31,7 +26,6 @@ function M.create_project()
</body> </body>
</html> </html>
]] ]]
utils.write_file(project_root .. "index.html", main_html_content) utils.write_file(project_root .. "index.html", main_html_content)
end) end)
end end
+14 -21
View File
@@ -1,36 +1,30 @@
local M = {}
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
local M = {}
M.java_build = nil M.keybinds = {}
M.java_run = nil M.opts = nil
M.config = {
project_root = "~/Projects/Java",
keybinds = {
["<leader>pb"] = "JavaBuild",
["<leader>pr"] = "JavaRun",
},
}
function M.setup(opts) function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("java"), opts or {})
for key, command in pairs(M.opts.keybinds) do
for key, command in pairs(M.config.keybinds) do M.keybinds[command] = key
if command == "JavaBuild" then M.java_build = key end
if command == "JavaRun" then M.java_run = key end
end end
vim.keymap.set("n", M.java_build, ":JavaBuild<CR>", { silent = true })
vim.keymap.set("n", M.java_run, ":JavaRun<CR>", { silent = true })
vim.api.nvim_create_user_command("JavaBuild", M.build, {}) vim.api.nvim_create_user_command("JavaBuild", M.build, {})
vim.api.nvim_create_user_command("JavaRun", M.run, {}) vim.api.nvim_create_user_command("JavaRun", M.run, {})
if M.keybinds.JavaRun then
vim.keymap.set("n", M.keybinds.JavaRun, ":JavaRun<CR>", { silent = true })
end
if M.keybinds.JavaBuild then
vim.keymap.set("n", M.keybinds.JavaBuild, ":JavaBuild<CR>", { silent = true })
end
end end
function M.create_project() function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name) vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(project_root .. path, "p") end for _, path in ipairs({ "/src", "/build" }) do vim.fn.mkdir(project_root .. path, "p") end
local main_java_content = [[ local main_java_content = [[
@@ -40,7 +34,6 @@ public class Main {
} }
} }
]] ]]
utils.write_file(project_root .. "/src/Main.java", main_java_content) utils.write_file(project_root .. "/src/Main.java", main_java_content)
end) end)
end end
+4 -7
View File
@@ -1,12 +1,11 @@
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
local config = require("Polydev.configs")
local M = {} local M = {}
M.keybinds = {} M.keybinds = {}
M.opts = nil M.opts = nil
function M.setup(opts) function M.setup(opts)
M.opts = vim.tbl_deep_extend("force", {}, config.get("lua"), opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("lua"), opts or {})
for key, command in pairs(M.opts.keybinds) do for key, command in pairs(M.opts.keybinds) do
M.keybinds[command] = key M.keybinds[command] = key
end end
@@ -29,14 +28,13 @@ function M.get_project_root()
end end
function M.get_project_name() function M.get_project_name()
local root = M.get_project_root() local polydev_file = vim.fn.glob((M.get_project_root() or "") .. "/*.polydev")
if not root then return nil end
local polydev_file = vim.fn.glob(root .. "/*.polydev")
return polydev_file:match("([^/]+)%.polydev$") return polydev_file:match("([^/]+)%.polydev$")
end end
function M.create_project() function M.create_project()
vim.ui.input({ prompt = "Enter project name: " }, function(project_name) vim.ui.input({ prompt = "Enter project name: " },
function(project_name)
if not project_name or project_name == "" then return print("Project creation canceled.") end if not project_name or project_name == "" then return print("Project creation canceled.") end
local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name local project_root = vim.fn.expand(M.opts.project_root) .. "/" .. project_name
for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(project_root .. path, "p") end for _, path in ipairs({ "/lua/" .. project_name }) do vim.fn.mkdir(project_root .. path, "p") end
@@ -75,4 +73,3 @@ function M.run()
end end
return M return M
+12 -17
View File
@@ -1,29 +1,24 @@
local M = {}
local utils = require("Polydev.utils") local utils = require("Polydev.utils")
local M = {}
M.rust_build = nil M.keybinds = {}
M.rust_run = nil M.opts = nil
M.config = {
project_root = "~/Projects/Rust",
keybinds = {
["<leader>pb"] = "RustBuild",
["<leader>pr"] = "RustRun",
},
}
function M.setup(opts) function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {}) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("rust"), opts or {})
for key, command in pairs(M.config.keybinds) do for key, command in pairs(M.opts.keybinds) do
if command == "RustBuild" then M.rust_build = key end M.keybinds[command] = key
if command == "RustRun" then M.rust_run = key end
end end
vim.api.nvim_create_user_command("RustBuild", M.build, {}) vim.api.nvim_create_user_command("RustBuild", M.build, {})
vim.api.nvim_create_user_command("RustRun", M.run, {}) vim.api.nvim_create_user_command("RustRun", M.run, {})
vim.keymap.set("n", M.rust_build, ":RustBuild<CR>", { silent = true }) if M.keybinds.RustRun then
vim.keymap.set("n", M.rust_run, ":RustRun<CR>", { silent = true }) vim.keymap.set("n", M.keybinds.RustRun, ":RustRun<CR>", { silent = true })
end
if M.keybinds.RustBuild then
vim.keymap.set("n", M.keybinds.RustBuild, ":RustBuild<CR>", { silent = true })
end
end end
function M.create_project() function M.create_project()
+2 -22
View File
@@ -1,14 +1,9 @@
local config = require("Polydev.configs")
local M = {} local M = {}
M.opts = {} M.opts = {}
function M.setup(opts) function M.setup(opts)
-- Get the terminal options from the config (either user-config or defaults) M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
local terminal_opts = config.get("terminal")
-- If no user options are passed in, merge them with the defaults from config
M.opts = vim.tbl_deep_extend("force", {}, terminal_opts, opts or {})
end end
function M.write_file(path, content) function M.write_file(path, content)
@@ -20,19 +15,6 @@ function M.write_file(path, content)
end end
function M.open_float_terminal(cmd) function M.open_float_terminal(cmd)
if not M.opts.number then
print("Number is false")
end
if M.opts.number then
print("Number is true")
end
-- Ensure M.opts is correctly set before accessing
if not M.opts.left_padding then
print("Error: Terminal padding options are missing.")
return
end
local ui = vim.api.nvim_list_uis()[1] local ui = vim.api.nvim_list_uis()[1]
local width = math.max(1, math.floor(ui.width * 0.9) - M.opts.left_padding or 0 - M.opts.right_padding or 0) local width = math.max(1, math.floor(ui.width * 0.9) - M.opts.left_padding or 0 - M.opts.right_padding or 0)
@@ -54,15 +36,13 @@ function M.open_float_terminal(cmd)
vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend) vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend)
vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu") vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu")
vim.api.nvim_win_set_option(win, "cursorline", true) vim.api.nvim_win_set_option(win, "cursorline", true)
vim.api.nvim_win_set_option(win, "scrolloff", 5)
if(M.opts.number == true) then if(M.opts.number == true) then
vim.api.nvim_win_set_option(win, "number", true) vim.api.nvim_win_set_option(win, "number", true)
if(M.opts.relativenumber == true) then if(M.opts.relativenumber == true) then
vim.api.nvim_win_set_option(win, "relativenumber", true) vim.api.nvim_win_set_option(win, "relativenumber", true)
end end
end end
if(M.opts.scroll == true) then
vim.api.nvim_win_set_option(win, "scrolloff", 5)
end
vim.fn.termopen(cmd) vim.fn.termopen(cmd)
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true }) vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })