8 Commits
Author SHA1 Message Date
DarthMooMancer 72951f7327 chore: fixed create_file to take filetype over asking for language each
time as 97% of the time people (I) will want to make the same filetype
instead
2026-10-28 10:30:06 -04:00
DarthMooMancer 4765da0539 chore: cleaning deprecated code 2026-10-27 17:03:32 -04:00
DarthMooMancer 9f4649b5d2 chore: combined (actions/utils.lua).create with (actions/init.lua).create_project 2026-10-27 16:53:43 -04:00
DarthMooMancer e8c55ec18f feat: added java and refactored how context is utilized 2026-10-27 14:35:19 -04:00
DarthMooMancer fcde51bc05 chore: redundancy removing and pushing before local changes 2026-10-27 00:14:09 -04:00
DarthMooMancer 9eefdb6166 refactor: fully moved attach to configs for compression
Removed the entire folder of attach because there was mostly boilerplate
instead of language specific code. It was redundant and just for testing
to have concept of what I wanted
2026-10-26 23:45:04 -04:00
DarthMooMancer 3046a3ce36 refactor: continuation of compressing languages to be agnostic 2026-10-26 21:11:55 -04:00
DarthMooMancer 5eaa7d10a7 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.
2026-10-26 14:13:33 -04:00
30 changed files with 492 additions and 645 deletions
+2 -2
View File
@@ -30,8 +30,8 @@ Vern.nvim currently supports the following languages:
* Python
* C / C++
<!-- * Java -->
<!-- * Lua -->
* Lua
* Java
<!-- * Rust -->
<!-- * HTML -->
+29 -52
View File
@@ -1,71 +1,48 @@
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 VernCConfig
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.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)
---@param root string
M.create_project = function(root)
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")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end
function M.create_file(opts)
---@param opts VernCConfig
M.create_file = function(opts)
opts = opts or {}
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
ft = ft and vim.trim(ft)
if not ft or ft == "" then
return
end
local configs = require("vern-nvim.configs.c")
---@type VernCConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
local mod = {}
if ft == "c" then
mod = opts.c.templates.file.source or {}
end
if ft == "h" then
mod = opts.c.templates.file.header or {}
end
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, utils.proj_name())
local input_txt = fname
ft = ft and vim.trim(ft)
if not ft or ft == "" then
fname = fname and vim.trim(fname)
if not fname or fname == "" then
return
end
local mod
if ft == "c" then
mod = cfg.c.templates.file.source or {}
end
if ft == "h" then
mod = cfg.c.templates.file.header or {}
input_txt = fname:upper()
end
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.c.dirs or {}, context)
local abs_file_path = vim.fs.normalize(join(root, path))
if ft == "h" then
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
end
utils.dump(abs_file_path, templates.fetch(mod.kind_path, mod.kind, input_txt))
vim.cmd.edit(vim.fn.expand(abs_file_path))
local raw_path = vim.fs.joinpath(mod.path, mod.name)
local context = {
project_name = utils.proj_name(),
company_name = opts.env.author,
file_name = fname,
}
local path = utils.resolve_path(raw_path, opts.c.dirs or {}, context)
local root = utils.proj_root()
utils.dump(
vim.fs.joinpath(root, path),
require("vern-nvim.templates").fetch(mod.kind_path, mod.kind, context)
)
vim.cmd.edit(vim.fn.expand(path))
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
end)
end)
end
+28 -52
View File
@@ -1,72 +1,48 @@
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 VernCPPConfig
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.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)
---@param root string
M.create_project = function(root)
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")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
end
---@param opts VernCPPConfig
function M.create_file(opts)
M.create_file = function(opts)
opts = opts or {}
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
ft = ft and vim.trim(ft)
if not ft or ft == "" then
return
end
local configs = require("vern-nvim.configs.cpp")
---@type VernCPPConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
local mod = {}
if ft == "c" then
mod = opts.cpp.templates.file.source or {}
end
if ft == "h" then
mod = opts.cpp.templates.file.header or {}
end
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
local root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, utils.proj_name())
local input_txt = fname
ft = ft and vim.trim(ft)
if not ft or ft == "" then
fname = fname and vim.trim(fname)
if not fname or fname == "" then
return
end
local mod
if ft == "c" then
mod = cfg.cpp.templates.file.source or {}
end
if ft == "h" then
mod = cfg.cpp.templates.file.header or {}
input_txt = fname:upper()
end
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.cpp.dirs or {}, context)
local abs_file_path = vim.fs.normalize(join(root, path))
if ft == "h" then
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
end
utils.dump(abs_file_path, templates.fetch(mod.kind_path, mod.kind, input_txt))
vim.cmd.edit(vim.fn.expand(abs_file_path))
local raw_path = vim.fs.joinpath(mod.path, mod.name)
local context = {
project_name = utils.proj_name(),
company_name = opts.env.author,
file_name = fname,
}
local path = utils.resolve_path(raw_path, opts.cpp.dirs or {}, context)
local root = utils.proj_root()
utils.dump(
vim.fs.joinpath(root, path),
require("vern-nvim.templates").fetch(mod.kind_path, mod.kind, context)
)
vim.cmd.edit(vim.fn.expand(path))
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
end)
end)
end
+117 -19
View File
@@ -1,5 +1,11 @@
local M = {}
---TODO
---Split filetype only and just change a filetype variable and vairables both share and then run the duplicate code
local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
M.create_project = function(opts)
opts = opts or {}
vim.ui.input(
@@ -7,24 +13,125 @@ M.create_project = function(opts)
function(ft)
ft = ft and vim.trim(ft)
if not ft or vim.trim(ft) == "" then
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
title = "Vern Project",
})
return
end
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)
else
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
title = "Vern Project",
})
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
pname = pname and vim.trim(pname)
if not pname or pname == "" then
return
end
local root =
vim.fs.joinpath(vim.fn.expand(args.workspace_root), args[ft].root, pname)
local ctx = {
project_name = pname,
company_name = args.env.author,
file_name = "",
}
vim.fn.mkdir(root, "p")
for _, dir in pairs(args[ft].dirs) do
local path = vim.fs.normalize(vim.fs.joinpath(root, utils.fmt(dir, ctx)))
vim.fn.mkdir(path, "p")
end
local bin
for tbl_name, tbl in pairs(args[ft].templates.project) do
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
local path = utils.resolve_path(raw_path, args[ft].dirs, ctx)
if tbl_name == "primary" then
bin = vim.fs.joinpath(root, path)
end
local abs_file_path = vim.fs.normalize(vim.fs.joinpath(root, path))
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, ctx))
end
for _, tbl in pairs(args[ft].templates.extras) do
if tbl.enabled then
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
local path = utils.resolve_path(raw_path, args[ft].dirs, ctx)
local abs_file_path = vim.fs.normalize(vim.fs.joinpath(root, path))
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, ctx))
end
end
utils.init_git(root, ft)
utils.init_readme(root)
if ok and actions and type(actions.create_project) == "function" then
actions.create_project(root)
end
vim.cmd.edit(vim.fn.fnameescape(bin))
vim.notify(
"Project: " .. pname .. " has been created!",
vim.log.levels.INFO,
{ title = "Vern Project" }
)
end)
end
)
end
M.create_file = function(opts)
opts = opts or {}
local filetype = vim.bo.filetype
local function continue_filetype(ft)
filetype = ft
local ok, actions = pcall(require, "vern-nvim.actions." .. filetype)
if not ok then
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
title = "Vern File",
})
return
end
local configs = require("vern-nvim.configs." .. filetype)
local args = vim.tbl_deep_extend("force", {}, configs, 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 mod
if ok and actions and type(actions.create_file) == "function" then
mod = actions.create_file(args[filetype])
or args[filetype].templates.file.source
or {}
end
local raw_path = vim.fs.joinpath(mod.path, mod.name)
local context = {
project_name = utils.proj_name(),
company_name = opts.env.author,
file_name = fname,
}
local path = utils.resolve_path(raw_path, args[filetype].dirs or {}, context)
local root = utils.proj_root()
utils.dump(
vim.fs.joinpath(root, path),
templates.fetch(mod.kind_path, mod.kind, context)
)
vim.cmd.edit(vim.fn.fnameescape(path))
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
end)
end
local ft_ok, ft_config = pcall(require, "vern-nvim.configs." .. filetype)
if not filetype or filetype == "" or not ft_ok or type(ft_config) ~= "table" then
vim.ui.input({
prompt = "File language (e.g. python): ",
completion = "filetype",
@@ -33,20 +140,11 @@ M.create_file = function(opts)
if not ft or vim.trim(ft) == "" then
return
end
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)
else
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
title = "Vern File",
})
vim.notify("Error: " .. actions, vim.log.levels.ERROR, {
title = "Vern File",
})
end
continue_filetype(ft)
end)
else
continue_filetype(filetype)
end
end
return M
+58
View File
@@ -0,0 +1,58 @@
local M = {}
local utils = require("vern-nvim.utils")
M.create_project = function() end
M.create_file = function() end
---@param opts VernJavaConfig Takes a table for the runtime
function M.run(opts)
opts = opts or {}
local root = utils.proj_root() or "."
local context = {
project_name = utils.proj_name(),
company_name = opts.env.author,
file_name = "",
}
local src_root =
vim.fs.joinpath(root, utils.resolve_path(opts.java.dirs.src, opts.java.dirs, context))
local build_dir = root .. "/bin"
local build_cmd = string.format(
"javac -d %s -sourcepath %s $(find %s -name '*java')",
build_dir,
src_root,
src_root
)
vim.system({ "sh", "-c", build_cmd }, { text = true }, function(obj)
if obj.code ~= 0 then
vim.schedule(function()
local error_obj = (obj.stderr ~= "" and obj.stderr) or obj.stdout or ""
local error_lines = vim.list_extend(
{ "Error During compilation" },
vim.split(error_obj, "\n", { trimempty = true })
)
local buf, _ = utils.term({ "echo 'compilation failed'" }, opts.terminal, true)
if buf and vim.api.nvim_buf_is_valid(buf) then
vim.api.nvim_set_option_value("modifiable", true, { buf = buf })
vim.api.nvim_buf_set_lines(buf, 0, -1, false, error_lines)
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
end
end)
else
vim.schedule(function()
local run_cmd = string.format(
"java -cp %s com.%s.%s.Main",
build_dir,
context.company_name,
context.project_name
)
utils.term({ run_cmd }, opts.terminal, false)
end)
end
end)
end
return M
+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)
+12 -53
View File
@@ -1,69 +1,28 @@
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 VernPythonConfig
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.python")
---@type VernPythonConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
local root = join(vim.fn.expand(cfg.workspace_root), cfg.python.root, pname)
local bin = action_utils.create(cfg.python, pname, root)
utils.init_git(root, "python")
local venv_path = root .. "/venv"
vim.fn.system("python3 -m venv " .. venv_path)
vim.notify("Project: " .. pname .. " has been created!")
vim.cmd.edit(vim.fn.fnameescape(bin))
end)
---@param root string
M.create_project = function(root)
vim.fn.system("python3 -m venv " .. root .. "/venv")
end
---@param opts VernPythonConfig
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.python")
---@type VernPythonConfig
local cfg = vim.tbl_deep_extend("force", {}, configs, opts 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 }
local path = utils.resolve_path(raw_path, cfg.python.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 VernPythonConfig 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 context = {
project_name = utils.proj_name(),
company_name = opts.env.author,
file_name = "",
}
local bin = opts.python.templates.project.primary
local exe = join(bin.path, bin.name) or "src/{project_name}/main.py"
local exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname })
local full_path = join(vim.fn.expand(root), exe_path)
local exe = vim.fs.joinpath(bin.path, bin.name) or "src/{project_name}/main.py"
local exe_path = utils.resolve_path(exe, opts.python.dirs, context)
local full_path = vim.fs.joinpath(vim.fn.expand(root), exe_path)
utils.term({ "python3 " .. full_path }, opts.terminal or {}, false)
end
-52
View File
@@ -1,52 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
local templates = require("vern-nvim.templates")
local join = vim.fs.joinpath
---@param cfg table Language config
---@param pname string Name of project
---@param root string Project location
---@return string bin Location of executable
function M.create(cfg, pname, root)
local ctx = { project_name = pname }
vim.fn.mkdir(root, "p")
local bin
for _, dir in pairs(cfg.dirs) do
local path = vim.fs.normalize(join(root, utils.fmt(dir, ctx)))
vim.fn.mkdir(path, "p")
end
for tbl_name, tbl in pairs(cfg.templates.project) do
local raw_path = join(tbl.path, tbl.name)
local path = utils.resolve_path(raw_path, cfg.dirs, ctx)
if tbl_name == "primary" then
bin = join(root, path)
end
local abs_file_path = vim.fs.normalize(join(root, path))
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
end
for _, tbl in pairs(cfg.templates.extras) do
if tbl.enabled then
local raw_path = join(tbl.path, tbl.name)
local path = utils.resolve_path(raw_path, cfg.dirs, ctx)
local abs_file_path = vim.fs.normalize(join(root, path))
local abs_dir_path = vim.fs.dirname(abs_file_path)
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
vim.fn.mkdir(abs_dir_path, "p")
end
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
end
end
return bin
end
return M
-26
View File
@@ -1,26 +0,0 @@
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
return function(bufnr, user_opts)
---@type VernCConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "CRun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run c project" })
for key, def in pairs(opts.c.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
-26
View File
@@ -1,26 +0,0 @@
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
return function(bufnr, user_opts)
---@type VernCPPConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "CPPRun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run cpp project" })
for key, def in pairs(opts.cpp.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
-26
View File
@@ -1,26 +0,0 @@
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
-47
View File
@@ -1,47 +0,0 @@
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
return function(bufnr, user_opts)
---@type VernPythonConfig
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run python project" })
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function()
if actions.pip_install then
actions.pip_install()
end
end, { nargs = "*", desc = "Install python packages" })
for key, def in pairs(opts.python.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
local root = require("vern-nvim.utils").proj_root()
if not root then
return
end
local venv_dir = nil
if vim.uv.fs_stat(root .. "/venv/bin/python") then
venv_dir = root .. "/venv"
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
venv_dir = root .. "/.venv"
end
if venv_dir then
vim.env.VIRTUAL_ENV = venv_dir
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
end
end
+6 -2
View File
@@ -1,5 +1,7 @@
local M = {}
M.attach = function() end
---@type VernLanguageConfig
M.c = {
root = "C",
@@ -9,10 +11,12 @@ M.c = {
},
keybinds = {
["<leader>pr"] = {
user_command = "CRun",
desc = "Executes c code",
action = require("vern-nvim.actions.c").run,
},
["<leader>pf"] = {
user_command = "CCreateFile",
desc = "Creates source/header files",
action = require("vern-nvim.actions.c").create_file,
},
@@ -41,13 +45,13 @@ M.c = {
file = {
header = {
path = "{dirs.include}",
name = "{name}.h",
name = "{file_name}.h",
kind = "header",
kind_path = "vern-nvim.templates.c",
},
source = {
path = "{dirs.src}",
name = "{name}.c",
name = "{file_name}.c",
kind = "source",
kind_path = "vern-nvim.templates.c",
},
+7 -3
View File
@@ -1,5 +1,7 @@
local M = {}
M.attach = function() end
---@type VernLanguageConfig
M.cpp = {
root = "CPP",
@@ -9,10 +11,12 @@ M.cpp = {
},
keybinds = {
["<leader>pr"] = {
user_command = "CPPRun",
desc = "Executes cpp code",
action = require("vern-nvim.actions.cpp").run,
},
["<leader>pf"] = {
user_command = "CPPCreateFile",
desc = "Creates source/header files",
action = require("vern-nvim.actions.cpp").create_file,
},
@@ -41,13 +45,13 @@ M.cpp = {
file = {
header = {
path = "{dirs.include}",
name = "{name}.hpp",
name = "{file_name}.hpp",
kind = "header",
kind_path = "vern-nvim.templates.cpp",
},
source = {
path = "{dirs.src}",
name = "{name}.c",
name = "{file_name}.cpp",
kind = "source",
kind_path = "vern-nvim.templates.cpp",
},
@@ -57,7 +61,7 @@ M.cpp = {
path = ".",
name = ".clang-tidy",
kind = "linter",
kind_path = "vern-nvim.templates.c",
kind_path = "vern-nvim.templates.cpp",
enabled = false,
},
},
+6
View File
@@ -3,12 +3,18 @@ local actions = require("vern-nvim.actions")
---@type VernCoreConfig
return {
workspace_root = "~/personal/Projects",
env = {
--- In documentation, make recommendation to change to username or name instead of company
author = "company",
},
keybinds = {
["<leader>pc"] = {
user_command = "VernCreateProject",
desc = "Creates a new project",
action = actions.create_project,
},
["<leader>pf"] = {
user_command = "VernCreateFile",
desc = "Creates a new project file",
action = actions.create_file,
},
+45
View File
@@ -0,0 +1,45 @@
local M = {}
M.attach = function() end
---@type VernLanguageConfig
M.java = {
root = "Java",
dirs = {
src = "src/com/{company_name}/{project_name}",
bin = "bin",
},
keybinds = {
["<leader>pr"] = {
user_command = "JavaRun",
desc = "Executes java code",
action = require("vern-nvim.actions.java").run,
},
},
templates = {
project = {
primary = {
path = "{dirs.src}",
name = "Main.java",
kind = "main",
kind_path = "vern-nvim.templates.java",
},
style = {
path = ".",
name = ".clang-format",
kind = "format",
kind_path = "vern-nvim.templates.java",
},
},
file = {
source = {
path = "{dirs.src}",
name = "{file_name}.java",
kind = "source",
kind_path = "vern-nvim.templates.java",
},
},
extras = {},
},
}
return M
+4 -1
View File
@@ -1,5 +1,7 @@
local M = {}
M.attach = function() end
---@type VernLanguageConfig
M.lua = {
root = "Lua",
@@ -8,6 +10,7 @@ M.lua = {
},
keybinds = {
["<leader>pr"] = {
user_command = "LuaRun",
desc = "Executes lua code",
action = require("vern-nvim.actions.lua").run,
},
@@ -30,7 +33,7 @@ M.lua = {
file = {
source = {
path = "{dirs.src}",
name = "{name}.lua",
name = "{file_name}.lua",
kind = "source",
kind_path = "vern-nvim.templates.lua",
},
+21 -2
View File
@@ -1,5 +1,22 @@
local M = {}
M.attach = function()
local root = require("vern-nvim.utils").proj_root()
if not root then
return
end
local venv_dir = nil
if vim.uv.fs_stat(root .. "/venv/bin/python") then
venv_dir = root .. "/venv"
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
venv_dir = root .. "/.venv"
end
if venv_dir then
vim.env.VIRTUAL_ENV = venv_dir
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
end
end
---@type VernLanguageConfig
M.python = {
root = "Python",
@@ -8,11 +25,13 @@ M.python = {
},
keybinds = {
["<leader>pr"] = {
user_command = "Pythonrun",
desc = "Executes python code",
action = require("vern-nvim.actions.python").run,
},
["<leader>pi"] = {
desc = "Asks for what python package to install",
user_command = "Pythonpip",
desc = "Install python packages for environment",
action = require("vern-nvim.actions.python").pip_install,
},
},
@@ -40,7 +59,7 @@ M.python = {
file = {
source = {
path = "{dirs.src}",
name = "{name}.py",
name = "{file_name}.py",
kind = "module",
kind_path = "vern-nvim.templates.python",
},
+31 -16
View File
@@ -1,7 +1,6 @@
local M = {}
local configs = require("vern-nvim.configs")
local actions = require("vern-nvim.actions")
---@type VernCoreConfig
M.opts = vim.deepcopy(configs)
@@ -18,6 +17,9 @@ function M.setup(user_opts)
for key, def in pairs(M.opts.keybinds or {}) do
if type(def.action) == "function" then
vim.api.nvim_create_user_command(def.user_command, function()
def.action(M.opts)
end, { nargs = "*", desc = def.desc })
vim.keymap.set("n", key, function()
def.action(M.opts)
end, {
@@ -27,27 +29,40 @@ function M.setup(user_opts)
end
end
vim.api.nvim_create_user_command("VernCreateProject", function()
if actions.create_project then
actions.create_project(M.opts)
end
end, { nargs = "*", desc = "Create a new project" })
vim.api.nvim_create_user_command("VernCreateFile", function()
if type(actions.create_file) == "function" then
actions.create_file(M.opts)
end
end, { nargs = "*", desc = "Creates a new file for project" })
local group = vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = "*",
callback = function(args)
local ft = vim.bo[args.buf].filetype
local ok, attach = pcall(require, "vern-nvim.attach." .. ft)
if ok and type(attach) == "function" then
attach(args.buf, M.opts)
if not ft or ft == "" then
return
end
local has_config, mod = pcall(require, "vern-nvim.configs." .. ft)
if not has_config then
return
end
local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {})
if opts[ft] and opts[ft].keybinds then
for key, def in pairs(opts[ft].keybinds or {}) do
if type(def.action) == "function" then
vim.api.nvim_buf_create_user_command(args.buf, def.user_command, function()
def.action(opts)
end, { nargs = "*", desc = def.desc })
vim.keymap.set("n", key, function()
def.action(opts)
end, {
buffer = args.buf,
silent = true,
desc = def.desc,
})
end
end
end
local ok, attach_mod = pcall(require, "vern-nvim.configs." .. ft)
if ok and type(attach_mod.attach) == "function" then
attach_mod.attach(args.buf, opts)
end
end,
desc = "Attach languages to buffer",
-55
View File
@@ -39,41 +39,6 @@ M.languages = {
end
end,
},
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<CR>", { 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)
if not vim.v.shell_error == 0 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 })
else
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
end
end,
},
html = {
setup = function(user_opts)
vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {})
@@ -117,26 +82,6 @@ M.languages = {
end
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<CR>", { 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,
},
}
return M
-26
View File
@@ -1,26 +0,0 @@
local M = {}
local presets = {
right = {
left = 100,
right = 0,
top = 0,
bottom = 0,
},
corner = {
left = 100,
right = 0,
top = 25,
bottom = 0,
}
}
---@param preset string
---@return table|nil
function M.getPresets(preset)
if presets[preset] then
return presets[preset]
end
end
return M
-113
View File
@@ -18,89 +18,6 @@ console.log("Hello World!");
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
@@ -134,36 +51,6 @@ setup(
}
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" }, "")
+3 -3
View File
@@ -87,12 +87,12 @@ endif()
Target: include/{project_name}/{name}.h
===================================================================== --]]
header = vim.trim([=[
#ifndef __PROJECT_NAME___H
#define __PROJECT_NAME___H
#ifndef __FILE_NAME___H
#define __FILE_NAME___H
// Code
#endif /* __PROJECT_NAME___H */
#endif /* __FILE_NAME___H */
]=]) .. "\n",
--[[ =====================================================================
+3 -3
View File
@@ -87,12 +87,12 @@ endif()
Target: include/{project_name}/{name}.hpp
===================================================================== --]]
header = vim.trim([=[
#ifndef __PROJECT_NAME___HPP
#define __PROJECT_NAME___HPP
#ifndef __FILE_NAME___HPP
#define __FILE_NAME___HPP
// Code
#endif /* __PROJECT_NAME___HPP */
#endif /* __FILE_NAME___HPP */
]=]) .. "\n",
--[[ =====================================================================
@@ -36,6 +36,12 @@ build/
lua = vim.trim([=[
luac.out
]=]),
java = vim.trim([=[
bin/
*.class
*.jar
]=]),
}
local extra = (lang and lang_block[lang]) or ""
@@ -0,0 +1 @@
return "# Hello from your fellow README.md"
+25 -7
View File
@@ -1,19 +1,37 @@
local M = {}
local registers = {
project_name = "__PROJECT_NAME__",
company_name = "__COMPANY_NAME__",
file_name = "__FILE_NAME__",
}
---@param kind_path string Filetype of template
---@param kind string Template in language table
---@param name string A string to replace temp values in template
---@param context table<string, string> A string to replace temp values in template
---@return string Content Formatted string
function M.fetch(kind_path, kind, name)
kind, name = kind or "", name or ""
if (kind == "" or nil) or (name == "" or nil) then
function M.fetch(kind_path, kind, context)
kind, context = kind or "", context or {}
if not kind or kind == "" then
return ""
end
local ok, mod = pcall(require, kind_path)
if ok and type(mod) == "table" then
return (string.gsub(mod[kind], "__PROJECT_NAME__", name))
end
if not ok or type(mod) ~= "table" or not mod[kind] then
return ""
end
local template = mod[kind] or ""
context = context or {}
if ok and type(mod) == "table" then
for key, placeholder in pairs(registers) do
local value = context[key]
if value then
template = string.gsub(template, placeholder, value)
end
end
end
return template
end
return M
+65
View File
@@ -0,0 +1,65 @@
return {
--[[ =====================================================================
TEMPLATE: MAIN (Entrypoint)
File: Main.java
Target: src/com/company/app/Main.java
===================================================================== --]]
main = vim.trim([=[
package com.__COMPANY_NAME__.__PROJECT_NAME__;
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: CLANG-FORMAT (Code formatter)
File: .clang-format
Target: .clang-format
===================================================================== --]]
format = vim.trim([=[
---
Language: Java
BasedOnStyle: Google
Standard: Latest
UseTab: Always
TabWidth: 8
IndentWidth: 8
BreakBeforeBraces: Allman
SeparateDefinitionBlocks: Always
BreakAfterReturnType: TopLevel
ReflowComments: Always
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
SortIncludes: CaseSensitive
IncludeBlocks: Preserve
]=]) .. "\n",
--[[ =====================================================================
TEMPLATE: SOURCE (Standalone File)
File: {name}.java
Target: src/com/company/app/{name}.java
===================================================================== --]]
source = vim.trim([=[
package com.__COMPANY_NAME__.__PROJECT_NAME__;
public class __FILE_NAME__ {
// Fields / Attributes
private String data;
// Constructor
public __FILE_NAME__() {
}
// Methods
public void doSomething() {
}
}
]=]) .. "\n",
}
+1 -1
View File
@@ -53,7 +53,7 @@ __PROJECT_NAME__ = "__PROJECT_NAME__.main:main"
===================================================================== --]]
module = vim.trim([=[
"""
Module: __PROJECT_NAME__
Module: __FILE_NAME__
"""
]=]) .. "\n",
}
+8
View File
@@ -3,6 +3,7 @@
---@alias SplitAnchorType "right" | "bottom"
---@class VernKeybindItem
---@field user_command string
---@field desc string
---@field action function
@@ -26,8 +27,12 @@
---@class VernTerminalConfig
---@field mode VernModeConfig
---@class VernEnvItem
---@field author string
---@class VernCoreConfig
---@field workspace_root string
---@field env VernEnvItem
---@field keybinds table<string, VernKeybindItem>
---@field terminal VernTerminalConfig
@@ -62,3 +67,6 @@
---@class VernLuaConfig : VernCoreConfig
---@field lua? VernLanguageConfig
---
---@class VernJavaConfig : VernCoreConfig
---@field java? VernLanguageConfig