diff --git a/README.md b/README.md index da8268f..20f07b9 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ NOTE: The plugin may not work well with lazy or any other package manager other * Integrated terminal for flexible command execution * Minimal configuration with extensibility in mind -> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern.nvim/wiki/Home$0) for setup, configuration, and usage details. +> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern-nvim.nvim/wiki/Home$0) for setup, configuration, and usage details. ## Supported Languages diff --git a/lua/vern/actions/c.lua b/lua/vern-nvim/actions/c.lua similarity index 92% rename from lua/vern/actions/c.lua rename to lua/vern-nvim/actions/c.lua index 1753950..d398293 100644 --- a/lua/vern/actions/c.lua +++ b/lua/vern-nvim/actions/c.lua @@ -1,8 +1,8 @@ local M = {} -local utils = require("vern.utils") -local templates = require("vern.templates") -local action_utils = require("vern.actions.utils") +local utils = require("vern-nvim.utils") +local templates = require("vern-nvim.templates") +local action_utils = require("vern-nvim.actions.utils") local join = vim.fs.joinpath @@ -14,14 +14,14 @@ function M.create_project(opts) return end - local configs = require("vern.configs.c") + local configs = require("vern-nvim.configs.c") ---@type VernCConfig local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname) local bin = action_utils.create(cfg.c, pname, root) - local build_cmd = "cd " .. root .. " && cmake -S . -B build" + local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build" local _ = vim.system({ "sh", "-c", build_cmd }):wait() utils.init_git(root, "c") @@ -36,7 +36,7 @@ function M.create_file(opts) if not ft or ft == "" then return end - local configs = require("vern.configs.c") + local configs = require("vern-nvim.configs.c") ---@type VernCConfig local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) vim.ui.input({ prompt = "Enter file name: " }, function(fname) diff --git a/lua/vern/actions/cpp.lua b/lua/vern-nvim/actions/cpp.lua similarity index 92% rename from lua/vern/actions/cpp.lua rename to lua/vern-nvim/actions/cpp.lua index e356aef..66cd636 100644 --- a/lua/vern/actions/cpp.lua +++ b/lua/vern-nvim/actions/cpp.lua @@ -1,8 +1,8 @@ local M = {} -local utils = require("vern.utils") -local templates = require("vern.templates") -local action_utils = require("vern.actions.utils") +local utils = require("vern-nvim.utils") +local templates = require("vern-nvim.templates") +local action_utils = require("vern-nvim.actions.utils") local join = vim.fs.joinpath @@ -14,14 +14,14 @@ function M.create_project(opts) return end - local configs = require("vern.configs.cpp") + local configs = require("vern-nvim.configs.cpp") ---@type VernCPPConfig local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) local root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, pname) local bin = action_utils.create(cfg.cpp, pname, root) - local build_cmd = "cd " .. root .. " && cmake -S . -B build" + local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build" local _ = vim.system({ "sh", "-c", build_cmd }):wait() utils.init_git(root, "cpp") @@ -37,7 +37,7 @@ function M.create_file(opts) if not ft or ft == "" then return end - local configs = require("vern.configs.cpp") + local configs = require("vern-nvim.configs.cpp") ---@type VernCPPConfig local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) vim.ui.input({ prompt = "Enter file name: " }, function(fname) diff --git a/lua/vern/actions/init.lua b/lua/vern-nvim/actions/init.lua similarity index 84% rename from lua/vern/actions/init.lua rename to lua/vern-nvim/actions/init.lua index 0bc95be..a02143c 100644 --- a/lua/vern/actions/init.lua +++ b/lua/vern-nvim/actions/init.lua @@ -9,8 +9,8 @@ M.create_project = function(opts) if not ft or vim.trim(ft) == "" then return end - local ok, actions = pcall(require, "vern.actions." .. ft) - local configs = require("vern.configs." .. ft) + local ok, actions = pcall(require, "vern-nvim.actions." .. ft) + local configs = require("vern-nvim.configs." .. ft) local args = vim.tbl_deep_extend("force", {}, configs, opts or {}) if ok and actions and type(actions.create_project) == "function" then actions.create_project(args) @@ -33,8 +33,8 @@ M.create_file = function(opts) if not ft or vim.trim(ft) == "" then return end - local ok, actions = pcall(require, "vern.actions." .. ft) - local configs = require("vern.configs." .. ft) + local ok, actions = pcall(require, "vern-nvim.actions." .. ft) + local configs = require("vern-nvim.configs." .. ft) local args = vim.tbl_deep_extend("force", {}, configs, opts or {}) if ok and actions and type(actions.create_file) == "function" then actions.create_file(args) diff --git a/lua/vern-nvim/actions/lua.lua b/lua/vern-nvim/actions/lua.lua new file mode 100644 index 0000000..2ff5a14 --- /dev/null +++ b/lua/vern-nvim/actions/lua.lua @@ -0,0 +1,65 @@ +local M = {} + +local utils = require("vern-nvim.utils") +local templates = require("vern-nvim.templates") +local action_utils = require("vern-nvim.actions.utils") + +local join = vim.fs.joinpath + +---@param opts VernLuaConfig +function M.create_project(opts) + vim.ui.input({ prompt = "Enter project name: " }, function(pname) + pname = pname and vim.trim(pname) + if not pname or pname == "" then + return + end + + local configs = require("vern-nvim.configs.lua") + + ---@type VernLuaConfig + local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {}) + local root = join(vim.fn.expand(cfg.workspace_root), cfg.lua.root, pname) + local bin = action_utils.create(cfg.lua, pname, root) + + utils.init_git(root, "lua") + + vim.cmd.edit(vim.fn.fnameescape(bin)) + end) +end + +---@param opts VernLuaConfig +function M.create_file(opts) + opts = opts or {} + vim.ui.input({ prompt = "Enter file name: " }, function(fname) + fname = fname and vim.trim(fname) + if not fname or fname == "" then + return + end + local configs = require("vern-nvim.configs.lua") + ---@type VernLuaConfig + local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) + local mod = cfg.lua.templates.file.source or {} + + local raw_path = join(mod.path, mod.name) + local context = { project_name = utils.proj_name(), name = fname } + local path = utils.resolve_path(raw_path, cfg.lua.dirs or {}, context) + + utils.dump(path, templates.fetch(mod.kind_path, mod.kind, fname)) + vim.notify("File: " .. fname .. " has been created!") + vim.cmd.edit(vim.fn.expand(path)) + end) +end + +---@param opts VernCPPConfig Takes a table for the runtime +function M.run(opts) + opts = opts or {} + local root = utils.proj_root() or "." + local pname = vim.fs.basename(root) + + local full_path = join(root, pname, "lua", pname) + print(full_path .. "/init.lua") + + utils.term({ "lua " .. full_path .. "/init.lua" }, opts.terminal or {}, false) +end + +return M diff --git a/lua/vern/actions/python.lua b/lua/vern-nvim/actions/python.lua similarity index 89% rename from lua/vern/actions/python.lua rename to lua/vern-nvim/actions/python.lua index 197960a..e0fd9e0 100644 --- a/lua/vern/actions/python.lua +++ b/lua/vern-nvim/actions/python.lua @@ -1,8 +1,8 @@ local M = {} -local utils = require("vern.utils") -local templates = require("vern.templates") -local action_utils = require("vern.actions.utils") +local utils = require("vern-nvim.utils") +local templates = require("vern-nvim.templates") +local action_utils = require("vern-nvim.actions.utils") local join = vim.fs.joinpath @@ -14,7 +14,7 @@ function M.create_project(opts) return end - local configs = require("vern.configs.python") + local configs = require("vern-nvim.configs.python") ---@type VernPythonConfig local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) @@ -39,10 +39,10 @@ function M.create_file(opts) if not fname or fname == "" then return end - local configs = require("vern.configs.python") + local configs = require("vern-nvim.configs.python") ---@type VernPythonConfig local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {}) - local mod = cfg.python.templates.file.mod or {} + local mod = cfg.python.templates.file.source or {} local raw_path = join(mod.path, mod.name) local context = { project_name = utils.proj_name(), name = fname } diff --git a/lua/vern/actions/utils.lua b/lua/vern-nvim/actions/utils.lua similarity index 94% rename from lua/vern/actions/utils.lua rename to lua/vern-nvim/actions/utils.lua index 663dbd9..0cc0f77 100644 --- a/lua/vern/actions/utils.lua +++ b/lua/vern-nvim/actions/utils.lua @@ -1,7 +1,7 @@ local M = {} -local utils = require("vern.utils") -local templates = require("vern.templates") +local utils = require("vern-nvim.utils") +local templates = require("vern-nvim.templates") local join = vim.fs.joinpath diff --git a/lua/vern/attach/c.lua b/lua/vern-nvim/attach/c.lua similarity index 89% rename from lua/vern/attach/c.lua rename to lua/vern-nvim/attach/c.lua index 9e57b38..29adfd5 100644 --- a/lua/vern/attach/c.lua +++ b/lua/vern-nvim/attach/c.lua @@ -1,5 +1,5 @@ -local actions = require("vern.actions.c") -local config = require("vern.configs.c") +local actions = require("vern-nvim.actions.c") +local config = require("vern-nvim.configs.c") ---@param bufnr integer Buffer to activate on : defaults to 0 ---@param user_opts? VernCConfig diff --git a/lua/vern/attach/cpp.lua b/lua/vern-nvim/attach/cpp.lua similarity index 88% rename from lua/vern/attach/cpp.lua rename to lua/vern-nvim/attach/cpp.lua index 37453eb..115de7a 100644 --- a/lua/vern/attach/cpp.lua +++ b/lua/vern-nvim/attach/cpp.lua @@ -1,5 +1,5 @@ -local actions = require("vern.actions.cpp") -local config = require("vern.configs.cpp") +local actions = require("vern-nvim.actions.cpp") +local config = require("vern-nvim.configs.cpp") ---@param bufnr integer Buffer to activate on : defaults to 0 ---@param user_opts? VernCPPConfig diff --git a/lua/vern-nvim/attach/lua.lua b/lua/vern-nvim/attach/lua.lua new file mode 100644 index 0000000..a33abd5 --- /dev/null +++ b/lua/vern-nvim/attach/lua.lua @@ -0,0 +1,26 @@ +local actions = require("vern-nvim.actions.lua") +local config = require("vern-nvim.configs.lua") + +---@param bufnr integer Buffer to activate on : defaults to 0 +---@param user_opts? VernLuaConfig +return function(bufnr, user_opts) + ---@type VernLuaConfig + local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) + vim.api.nvim_buf_create_user_command(bufnr, "LuaRun", function() + if type(actions.run) == "function" then + actions.run(opts) + end + end, { desc = "Run lua project" }) + + for key, def in pairs(opts.lua.keybinds or {}) do + if type(def.action) == "function" then + vim.keymap.set("n", key, function() + def.action(opts) + end, { + buffer = bufnr, + silent = true, + desc = def.desc, + }) + end + end +end diff --git a/lua/vern/attach/python.lua b/lua/vern-nvim/attach/python.lua similarity index 89% rename from lua/vern/attach/python.lua rename to lua/vern-nvim/attach/python.lua index 40aee86..60a4cb3 100644 --- a/lua/vern/attach/python.lua +++ b/lua/vern-nvim/attach/python.lua @@ -1,5 +1,5 @@ -local actions = require("vern.actions.python") -local config = require("vern.configs.python") +local actions = require("vern-nvim.actions.python") +local config = require("vern-nvim.configs.python") ---@param bufnr integer Buffer to activate on : defaults to 0 ---@param user_opts? VernPythonConfig @@ -30,7 +30,7 @@ return function(bufnr, user_opts) end end - local root = require("vern.utils").proj_root() + local root = require("vern-nvim.utils").proj_root() if not root then return end diff --git a/lua/vern/configs/c.lua b/lua/vern-nvim/configs/c.lua similarity index 75% rename from lua/vern/configs/c.lua rename to lua/vern-nvim/configs/c.lua index 7ed75bc..9191ab3 100644 --- a/lua/vern/configs/c.lua +++ b/lua/vern-nvim/configs/c.lua @@ -10,11 +10,11 @@ M.c = { keybinds = { ["pr"] = { desc = "Executes c code", - action = require("vern.actions.c").run, + action = require("vern-nvim.actions.c").run, }, ["pf"] = { desc = "Creates source/header files", - action = require("vern.actions.c").create_file, + action = require("vern-nvim.actions.c").create_file, }, }, templates = { @@ -23,19 +23,19 @@ M.c = { path = "{dirs.src}", name = "main.c", kind = "main", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", }, manifest = { path = ".", name = "CMakeLists.txt", kind = "CmakeLists", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", }, style = { path = ".", name = ".clang-format", kind = "format", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", }, }, file = { @@ -43,13 +43,13 @@ M.c = { path = "{dirs.include}", name = "{name}.h", kind = "header", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", }, source = { path = "{dirs.src}", name = "{name}.c", kind = "source", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", }, }, extras = { @@ -57,7 +57,7 @@ M.c = { path = ".", name = ".clang-tidy", kind = "linter", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", enabled = false, }, }, diff --git a/lua/vern/configs/cpp.lua b/lua/vern-nvim/configs/cpp.lua similarity index 74% rename from lua/vern/configs/cpp.lua rename to lua/vern-nvim/configs/cpp.lua index ede23fd..36f56c0 100644 --- a/lua/vern/configs/cpp.lua +++ b/lua/vern-nvim/configs/cpp.lua @@ -10,11 +10,11 @@ M.cpp = { keybinds = { ["pr"] = { desc = "Executes cpp code", - action = require("vern.actions.cpp").run, + action = require("vern-nvim.actions.cpp").run, }, ["pf"] = { desc = "Creates source/header files", - action = require("vern.actions.cpp").create_file, + action = require("vern-nvim.actions.cpp").create_file, }, }, templates = { @@ -23,19 +23,19 @@ M.cpp = { path = "{dirs.src}", name = "main.cpp", kind = "main", - kind_path = "vern.templates.cpp", + kind_path = "vern-nvim.templates.cpp", }, manifest = { path = ".", name = "CMakeLists.txt", kind = "CmakeLists", - kind_path = "vern.templates.cpp", + kind_path = "vern-nvim.templates.cpp", }, style = { path = ".", name = ".clang-format", kind = "format", - kind_path = "vern.templates.cpp", + kind_path = "vern-nvim.templates.cpp", }, }, file = { @@ -43,13 +43,13 @@ M.cpp = { path = "{dirs.include}", name = "{name}.hpp", kind = "header", - kind_path = "vern.templates.cpp", + kind_path = "vern-nvim.templates.cpp", }, source = { path = "{dirs.src}", name = "{name}.c", kind = "source", - kind_path = "vern.templates.cpp", + kind_path = "vern-nvim.templates.cpp", }, }, extras = { @@ -57,7 +57,7 @@ M.cpp = { path = ".", name = ".clang-tidy", kind = "linter", - kind_path = "vern.templates.c", + kind_path = "vern-nvim.templates.c", enabled = false, }, }, diff --git a/lua/vern/configs/init.lua b/lua/vern-nvim/configs/init.lua similarity index 95% rename from lua/vern/configs/init.lua rename to lua/vern-nvim/configs/init.lua index f2e6f05..88487ec 100644 --- a/lua/vern/configs/init.lua +++ b/lua/vern-nvim/configs/init.lua @@ -1,4 +1,4 @@ -local actions = require("vern.actions") +local actions = require("vern-nvim.actions") ---@type VernCoreConfig return { diff --git a/lua/vern-nvim/configs/lua.lua b/lua/vern-nvim/configs/lua.lua new file mode 100644 index 0000000..6d08786 --- /dev/null +++ b/lua/vern-nvim/configs/lua.lua @@ -0,0 +1,42 @@ +local M = {} + +---@type VernLanguageConfig +M.lua = { + root = "Lua", + dirs = { + src = "lua/{project_name}", + }, + keybinds = { + ["pr"] = { + desc = "Executes lua code", + action = require("vern-nvim.actions.lua").run, + }, + }, + templates = { + project = { + primary = { + path = "{dirs.src}", + name = "init.lua", + kind = "init", + kind_path = "vern-nvim.templates.lua", + }, + style = { + path = ".", + name = "stylua.toml", + kind = "format", + kind_path = "vern-nvim.templates.lua", + }, + }, + file = { + source = { + path = "{dirs.src}", + name = "{name}.lua", + kind = "source", + kind_path = "vern-nvim.templates.lua", + }, + }, + extras = {}, + }, +} + +return M diff --git a/lua/vern/configs/python.lua b/lua/vern-nvim/configs/python.lua similarity index 72% rename from lua/vern/configs/python.lua rename to lua/vern-nvim/configs/python.lua index 507da0b..a8122ba 100644 --- a/lua/vern/configs/python.lua +++ b/lua/vern-nvim/configs/python.lua @@ -9,11 +9,11 @@ M.python = { keybinds = { ["pr"] = { desc = "Executes python code", - action = require("vern.actions.python").run, + action = require("vern-nvim.actions.python").run, }, ["pi"] = { desc = "Asks for what python package to install", - action = require("vern.actions.python").pip_install, + action = require("vern-nvim.actions.python").pip_install, }, }, templates = { @@ -22,27 +22,27 @@ M.python = { path = "{dirs.src}", name = "main.py", kind = "main", - kind_path = "vern.templates.python", + kind_path = "vern-nvim.templates.python", }, manifest = { path = ".", name = "pyproject.toml", kind = "pyproject", - kind_path = "vern.templates.python", + kind_path = "vern-nvim.templates.python", }, pkg_init = { path = "{dirs.src}", name = "__init__.py", kind = "__init__", - kind_path = "vern.templates.python", + kind_path = "vern-nvim.templates.python", }, }, file = { - mod = { + source = { path = "{dirs.src}", name = "{name}.py", kind = "module", - kind_path = "vern.templates.python", + kind_path = "vern-nvim.templates.python", }, }, extras = {}, diff --git a/lua/vern/health-deprecated.lua b/lua/vern-nvim/health-deprecated.lua similarity index 100% rename from lua/vern/health-deprecated.lua rename to lua/vern-nvim/health-deprecated.lua diff --git a/lua/vern/init.lua b/lua/vern-nvim/init.lua similarity index 90% rename from lua/vern/init.lua rename to lua/vern-nvim/init.lua index 52c7747..6182e2b 100644 --- a/lua/vern/init.lua +++ b/lua/vern-nvim/init.lua @@ -1,7 +1,7 @@ local M = {} -local configs = require("vern.configs") -local actions = require("vern.actions") +local configs = require("vern-nvim.configs") +local actions = require("vern-nvim.actions") ---@type VernCoreConfig M.opts = vim.deepcopy(configs) @@ -45,7 +45,7 @@ function M.setup(user_opts) pattern = "*", callback = function(args) local ft = vim.bo[args.buf].filetype - local ok, attach = pcall(require, "vern.attach." .. ft) + local ok, attach = pcall(require, "vern-nvim.attach." .. ft) if ok and type(attach) == "function" then attach(args.buf, M.opts) end diff --git a/lua/vern/languages-deprecated.lua b/lua/vern-nvim/languages-deprecated.lua similarity index 58% rename from lua/vern/languages-deprecated.lua rename to lua/vern-nvim/languages-deprecated.lua index 755a49d..deee8db 100644 --- a/lua/vern/languages-deprecated.lua +++ b/lua/vern-nvim/languages-deprecated.lua @@ -2,31 +2,6 @@ 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 = { javascript = { setup = function(self, user_opts) @@ -99,85 +74,6 @@ M.languages = { 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" - - 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, { 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, - }, - 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" - - 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, { 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 {}) diff --git a/lua/vern/presets-deprecated.lua b/lua/vern-nvim/presets-deprecated.lua similarity index 100% rename from lua/vern/presets-deprecated.lua rename to lua/vern-nvim/presets-deprecated.lua diff --git a/lua/vern/providers/python/uv.lua b/lua/vern-nvim/providers/python/uv.lua similarity index 100% rename from lua/vern/providers/python/uv.lua rename to lua/vern-nvim/providers/python/uv.lua diff --git a/lua/vern-nvim/templates-deprecated.lua b/lua/vern-nvim/templates-deprecated.lua new file mode 100644 index 0000000..968955c --- /dev/null +++ b/lua/vern-nvim/templates-deprecated.lua @@ -0,0 +1,195 @@ +local utils = require("Polydev.utils") + +local M = {} + +M.projects = { + javascript = { + run = function(project_name, project_root) + local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name + vim.fn.mkdir(full_project_root, "p") + utils.write_file( + { full_project_root, "main.js" }, + [[ +console.log("Hello World!"); +]] + ) + local gitignore = { "" } + utils.init_git(full_project_root, gitignore) + vim.cmd("edit " .. full_project_root .. "/main.js") + end, + }, + 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 = [[ +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" }, + [[ +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( + [[ +from setuptools import setup, find_packages + +setup( + name="%s", + version="0.1.0", + packages=find_packages(), + install_requires=[], + 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, + }, + 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 = [[ + + + + Page Title + + + +

My First Heading

+

My first paragraph.

+ + + +]] + 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( + [[ +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, + }, + 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([[ + + + + Page Title + + + +

My First Heading

+

My first paragraph.

+ + + +]]) + ) + end, + }, +} + +return M diff --git a/lua/vern/templates/c.lua b/lua/vern-nvim/templates/c.lua similarity index 100% rename from lua/vern/templates/c.lua rename to lua/vern-nvim/templates/c.lua diff --git a/lua/vern/templates/cpp.lua b/lua/vern-nvim/templates/cpp.lua similarity index 100% rename from lua/vern/templates/cpp.lua rename to lua/vern-nvim/templates/cpp.lua diff --git a/lua/vern/templates/extras/gitignore.lua b/lua/vern-nvim/templates/extras/gitignore.lua similarity index 71% rename from lua/vern/templates/extras/gitignore.lua rename to lua/vern-nvim/templates/extras/gitignore.lua index ae48d5f..aff373d 100644 --- a/lua/vern/templates/extras/gitignore.lua +++ b/lua/vern-nvim/templates/extras/gitignore.lua @@ -22,6 +22,20 @@ env/ venv/ .pytest_cache/ ]=]), + + c = vim.trim([=[ +build/ +.cache/ + ]=]), + + cpp = vim.trim([=[ +build/ +.cache/ + ]=]), + + lua = vim.trim([=[ +luac.out + ]=]), } local extra = (lang and lang_block[lang]) or "" diff --git a/lua/vern/templates/init.lua b/lua/vern-nvim/templates/init.lua similarity index 100% rename from lua/vern/templates/init.lua rename to lua/vern-nvim/templates/init.lua diff --git a/lua/vern-nvim/templates/lua.lua b/lua/vern-nvim/templates/lua.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/vern/templates/python.lua b/lua/vern-nvim/templates/python.lua similarity index 100% rename from lua/vern/templates/python.lua rename to lua/vern-nvim/templates/python.lua diff --git a/lua/vern/types.lua b/lua/vern-nvim/types.lua similarity index 95% rename from lua/vern/types.lua rename to lua/vern-nvim/types.lua index 9c874b8..f1549b0 100644 --- a/lua/vern/types.lua +++ b/lua/vern-nvim/types.lua @@ -56,6 +56,9 @@ ---@class VernCConfig : VernCoreConfig ---@field c? VernLanguageConfig ---- + ---@class VernCPPConfig : VernCoreConfig ---@field cpp? VernLanguageConfig + +---@class VernLuaConfig : VernCoreConfig +---@field lua? VernLanguageConfig diff --git a/lua/vern/utils.lua b/lua/vern-nvim/utils.lua similarity index 96% rename from lua/vern/utils.lua rename to lua/vern-nvim/utils.lua index 4b9c90e..02f6cbf 100644 --- a/lua/vern/utils.lua +++ b/lua/vern-nvim/utils.lua @@ -60,14 +60,14 @@ function M.init_git(path, ft) return end - local gitignore = require("vern.templates.extras.gitignore").template(ft) + local gitignore = require("vern-nvim.templates.extras.gitignore").template(ft) vim.fn.system({ "git", "-C", path, "init" }) M.dump(vim.fs.joinpath(path, ".gitignore"), gitignore) end ---@param path string function M.init_readme(path) - local readme = require("vern.templates.extras.readme") + local readme = require("vern-nvim.templates.extras.readme") M.dump(vim.fs.joinpath(path, "README.md"), readme) end diff --git a/lua/vern/templates-deprecated.lua b/lua/vern/templates-deprecated.lua deleted file mode 100644 index 1ad8d52..0000000 --- a/lua/vern/templates-deprecated.lua +++ /dev/null @@ -1,487 +0,0 @@ -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( - [[ -#ifndef %s -#define %s - -// Add code here - -#endif -]], - guard_macro, - guard_macro - ) - utils.write_file( - { utils.get_project_root(), "include", file_name .. file_type }, - content - ) -end - -M.projects = { - javascript = { - run = function(project_name, project_root) - local full_project_root = vim.fn.expand(project_root) - .. "/" - .. project_name - vim.fn.mkdir(full_project_root, "p") - utils.write_file( - { full_project_root, "main.js" }, - [[ -console.log("Hello World!"); -]] - ) - local gitignore = { "" } - utils.init_git(full_project_root, gitignore) - vim.cmd("edit " .. full_project_root .. "/main.js") - end, - }, - 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 = [[ -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" }, - [[ -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( - [[ -from setuptools import setup, find_packages - -setup( - name="%s", - version="0.1.0", - packages=find_packages(), - install_requires=[], - 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, ".clang-format" }, - [[ ---- -BasedOnStyle: Google -Standard: Latest -UseTab: Always -TabWidth: 8 -IndentWidth: 8 -BreakBeforeBraces: Allman -SpaceBeforeCpp11BracedList: true -SeparateDefinitionBlocks: Always -Cpp11BracedListStyle: false -BreakAfterReturnType: TopLevel -AlignTrailingComments: - Kind: Always -ReflowComments: Always -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: AllIfsAndElse -AllowShortLoopsOnASingleLine: true -IndentAccessModifiers: false # Indent access specifiers by one level -AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level -]] - ) - utils.write_file( - { full_project_root, "src/main.c" }, - [[ -#include - -int main() { - printf("%s", "Hello World"); - return 0; -} -]] - ) - - utils.write_file( - { full_project_root, ".clang-tidy" }, - string.format([[ ---- -Checks: > - -*, - bugprone-*, - concurrency-*, - misc-*, - modernize-*, - performance-*, - readability-*, - portability-*, - -readability-braces-around-statements, - -readability-implicit-bool-conversion - -WarningsAsErrors: "" - -CheckOptions: - - key: readability-identifier-naming.VariableCase - value: lower_case - - key: readability-identifier-naming.FunctionCase - value: lower_case ---- - ]]) - ) - utils.write_file( - { full_project_root, "CMakeLists.txt" }, - string.format( - [[ -cmake_minimum_required(VERSION 3.16) -set(CMAKE_C_STANDARD 23) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -include_directories(include) -project(%s LANGUAGES C) - -set(SOURCES - src/main.c -) - -add_executable(%s ${SOURCES}) -]], - 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, ".clang-format" }, - [[ ---- -BasedOnStyle: Google -Standard: Latest -UseTab: Always -TabWidth: 8 -IndentWidth: 8 -BreakBeforeBraces: Allman -SpaceBeforeCpp11BracedList: true -SeparateDefinitionBlocks: Always -Cpp11BracedListStyle: false -BreakAfterReturnType: TopLevel -AlignTrailingComments: - Kind: Always -ReflowComments: Always -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: AllIfsAndElse -AllowShortLoopsOnASingleLine: true -IndentAccessModifiers: false # Indent access specifiers by one level -AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level -]] - ) - - utils.write_file( - { full_project_root, "src/main.cpp" }, - [[ -#include - -int main() { - std::cout << "Hello World\n"; - return 0; -} -]] - ) - - utils.write_file( - { full_project_root, ".clang-tidy" }, - string.format([[ ---- -Checks: > - -*, - bugprone-*, - concurrency-*, - misc-*, - modernize-*, - performance-*, - readability-*, - portability-*, - -readability-braces-around-statements, - -readability-implicit-bool-conversion - -WarningsAsErrors: "" - -CheckOptions: - - key: readability-identifier-naming.VariableCase - value: lower_case - - key: readability-identifier-naming.FunctionCase - value: lower_case ---- - ]]) - ) - - utils.write_file( - { full_project_root, "CMakeLists.txt" }, - string.format( - [[ -cmake_minimum_required(VERSION 3.16) -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -project(%s LANGUAGES CXX) - - -set(SOURCES - src/main.cpp -) - -add_executable(%s ${SOURCES}) -]], - 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 = [[ - - - - Page Title - - - -

My First Heading

-

My first paragraph.

- - - -]] - 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( - [[ -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, - }, - 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([[ - - - - Page Title - - - -

My First Heading

-

My first paragraph.

- - - -]]) - ) - end, - }, -} - -M.extras = { - 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, -} - -return M