refactor: realized I was heavily unoptimized.

Each language had the same boilerplate code to create new projects and
new files with minor differences between each language making them
difficult to edit and navigate.
This commit is contained in:
DarthMooMancer committed 2026-10-26 14:13:33 -04:00
1 parent 774f14809d
commit 5eaa7d10a7
7 files changed
+95 -215

No files matched your search

+3 -47
View File
@@ -1,54 +1,10 @@
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
M.create_project = function() end
---@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
M.create_file = function() end
---@param opts VernCPPConfig Takes a table for the runtime
function M.run(opts)
@@ -56,7 +12,7 @@ function M.run(opts)
local root = utils.proj_root() or "."
local pname = vim.fs.basename(root)
local full_path = join(root, pname, "lua", pname)
local full_path = vim.fs.joinpath(root, "lua", pname)
print(full_path .. "/init.lua")
utils.term({ "lua " .. full_path .. "/init.lua" }, opts.terminal or {}, false)