refactor(actions): deleted actions files for language types and fixed them

This commit is contained in:
DarthMooMancer committed 2026-10-31 01:34:14 -04:00
1 parent 08967f9070
commit ae0df7fe28
16 files changed
+240 -317

No files matched your search

+10 -4
View File
@@ -166,8 +166,8 @@ M.create_file = function(opts)
function_write(mod, fname)
end
if cf and type(cf.func) == "function" and cf.allowed then
cf.func(args, done)
if cf and type(cf) == "function" then
cf(args, done)
else
done(args[filetype].templates.file.source)
end
@@ -179,7 +179,7 @@ M.run = function(opts)
opts = opts or {}
local filetype = vim.bo.filetype
local ft_ok, action = pcall(require, "vern-nvim.actions." .. filetype)
local ft_ok, action = pcall(require, "vern-nvim.configs." .. filetype)
if
not filetype
or filetype == ""
@@ -191,7 +191,13 @@ M.run = function(opts)
})
return
else
action.run(opts)
local args = vim.tbl_deep_extend(
"force",
{},
opts,
require("vern-nvim.configs." .. filetype)
)
action.run(args)
end
end
-45
View File
@@ -1,45 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
---@param opts? VernCConfig Takes a table for the runtime
function M.run(opts)
opts = opts or {}
local build_dir = vim.fn.fnameescape((utils.proj_root() or ".") .. "/build")
vim.system(
{ "sh", "-c", string.format("cd %s && cmake --build .", build_dir) },
{ 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
)
utils.term_override(buf, error_lines)
end)
else
vim.schedule(function()
local run_cmd = string.format(
"cd %s && ./%s",
build_dir,
utils.proj_name()
)
utils.term({ run_cmd }, opts.terminal, false)
end)
end
end
)
end
return M
-45
View File
@@ -1,45 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
---@param opts? VernCPPConfig Takes a table for the runtime
function M.run(opts)
opts = opts or {}
local build_dir = vim.fn.fnameescape((utils.proj_root() or ".") .. "/build")
vim.system(
{ "sh", "-c", string.format("cd %s && cmake --build .", build_dir) },
{ 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
)
utils.term_override(buf, error_lines)
end)
else
vim.schedule(function()
local run_cmd = string.format(
"cd %s && ./%s",
build_dir,
utils.proj_name()
)
utils.term({ run_cmd }, opts.terminal, false)
end)
end
end
)
end
return M
-58
View File
@@ -1,58 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
---@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
)
utils.term_override(buf, error_lines)
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
-19
View File
@@ -1,19 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
---@param opts VernLuaConfig Takes a table for the runtime
function M.run(opts)
opts = opts or {}
utils.term({
"lua " .. vim.fs.joinpath(
utils.proj_root(),
"lua",
utils.proj_name(),
"/init.lua"
),
}, opts.terminal or {}, false)
end
return M
-60
View File
@@ -1,60 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
---@param opts VernPythonConfig 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 bin = opts.python.templates.project.primary
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
function M.pip_install()
vim.ui.input({ prompt = "Enter pip module: " }, function(mod)
mod = mod and vim.trim(mod)
if not mod or mod == "" then
vim.notify(
"Pip Cancelled",
vim.log.levels.WARN,
{ title = "Vern Python" }
)
return
end
vim.notify(
"Installing " .. mod,
vim.log.levels.INFO,
{ title = "Vern Python" }
)
vim.system({ "pip", "install", mod }, { text = true }, function(obj)
vim.schedule(function()
if obj.code ~= 0 then
vim.notify(
"Pip failed: " .. obj.stderr,
vim.log.levels.WARN,
{ title = "Vern Python" }
)
else
vim.notify(
"Pip installed " .. mod,
vim.log.levels.INFO,
{ title = "Vern Python" }
)
end
end)
end)
end)
end
return M
-15
View File
@@ -1,15 +0,0 @@
local M = {}
local utils = require("vern-nvim.utils")
---@param opts VernRustConfig Takes a table for the runtime
function M.run(opts)
opts = opts or {}
utils.term(
{ "cd " .. utils.proj_root() .. " && cargo run" },
opts.terminal or {},
false
)
end
return M
+30 -19
View File
@@ -1,6 +1,9 @@
local utils = require("vern-nvim.utils")
local comp = require("vern-nvim.languages.shared.compile")
local M = {}
M.attach = function() end
M.attach = nil
---@param root string
M.create_project = function(root)
@@ -11,23 +14,31 @@ M.create_project = function(root)
end
---@type VernCreateFile
M.create_file = {
allowed = true,
---@param opts VernCConfig
func = function(opts, continue)
opts = opts or {}
local file = vim.tbl_get(opts, "c", "templates", "file")
local items = { "source", "header" }
vim.ui.select(items, {
prompt = "Select type:",
format_item = function(item) return item end,
}, function(choice, _)
if choice == items[1] then return continue(file.source) end
if choice == items[2] then return continue(file.header) end
continue(nil)
end)
end,
}
---@param opts VernCConfig
M.create_file = function(opts, continue)
opts = opts or {}
local file = vim.tbl_get(opts, "c", "templates", "file")
local items = { "source", "header" }
vim.ui.select(items, {
prompt = "Select type:",
format_item = function(item) return item end,
}, function(choice, _)
if choice == items[1] then return continue(file.source) end
if choice == items[2] then return continue(file.header) end
continue(nil)
end)
end
---@param opts? VernCConfig Takes a table for the runtime
M.run = function(opts)
opts = opts or {}
local build_dir = vim.fn.fnameescape((utils.proj_root() or ".") .. "/build")
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
local run_cmd = string.format("cd %s && ./%s", build_dir, utils.proj_name())
comp.compile(opts, build_cmd, run_cmd)
end
---@type VernLanguageConfig
M.c = {
@@ -36,7 +47,7 @@ M.c = {
src = "src",
include = "include/{project_name}",
},
keybinds = {},
keybinds = nil,
templates = {
project = {
primary = {
+30 -19
View File
@@ -1,6 +1,9 @@
local utils = require("vern-nvim.utils")
local comp = require("vern-nvim.languages.shared.compile")
local M = {}
M.attach = function() end
M.attach = nil
---@param root string
M.create_project = function(root)
@@ -11,23 +14,31 @@ M.create_project = function(root)
end
---@type VernCreateFile
M.create_file = {
allowed = true,
---@param opts VernCPPConfig
func = function(opts, continue)
opts = opts or {}
local file = vim.tbl_get(opts, "cpp", "templates", "file")
local items = { "source", "header" }
vim.ui.select(items, {
prompt = "Select type:",
format_item = function(item) return item end,
}, function(choice, _)
if choice == items[1] then return continue(file.source) end
if choice == items[2] then return continue(file.header) end
continue(nil)
end)
end,
}
---@param opts VernCPPConfig
M.create_file = function(opts, continue)
opts = opts or {}
local file = vim.tbl_get(opts, "cpp", "templates", "file")
local items = { "source", "header" }
vim.ui.select(items, {
prompt = "Select type:",
format_item = function(item) return item end,
}, function(choice, _)
if choice == items[1] then return continue(file.source) end
if choice == items[2] then return continue(file.header) end
continue(nil)
end)
end
---
---@param opts? VernCPPConfig Takes a table for the runtime
M.run = function(opts)
opts = opts or {}
local build_dir = vim.fn.fnameescape((utils.proj_root() or ".") .. "/build")
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
local run_cmd = string.format("cd %s && ./%s", build_dir, utils.proj_name())
comp.compile(opts, build_cmd, run_cmd)
end
---@type VernLanguageConfig
M.cpp = {
@@ -36,7 +47,7 @@ M.cpp = {
src = "src",
include = "include/{project_name}",
},
keybinds = {},
keybinds = nil,
templates = {
project = {
primary = {
+39 -8
View File
@@ -1,14 +1,45 @@
local utils = require("vern-nvim.utils")
local comp = require("vern-nvim.languages.shared.compile")
local M = {}
M.attach = function() end
M.attach = nil
M.create_project = function() end
M.create_project = nil
---@type VernCreateFile
M.create_file = {
allowed = false,
func = function(_, _) return nil end,
}
M.create_file = nil
---@param opts VernJavaConfig Takes a table for the runtime
M.run = function(opts)
opts = opts or {}
local root = utils.proj_root()
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
)
local run_cmd = string.format(
"java -cp %s com.%s.%s.Main",
build_dir,
context.company_name,
context.project_name
)
comp.compile(opts, build_cmd, run_cmd)
end
---@type VernLanguageConfig
M.java = {
@@ -17,7 +48,7 @@ M.java = {
src = "src/com/{company_name}/{project_name}",
bin = "bin",
},
keybinds = {},
keybinds = nil,
templates = {
project = {
primary = {
@@ -41,7 +72,7 @@ M.java = {
kind_path = "vern-nvim.templates.java",
},
},
extras = {},
extras = nil,
},
}
return M
+21 -8
View File
@@ -1,14 +1,27 @@
local utils = require("vern-nvim.utils")
local M = {}
M.attach = function() end
M.attach = nil
M.create_project = function() end
M.create_project = nil
---@type VernCreateFile
M.create_file = {
allowed = false,
func = function(_, _) return nil end,
}
M.create_file = nil
---@param opts VernLuaConfig Takes a table for the runtime
M.run = function(opts)
opts = opts or {}
utils.term({
"lua " .. vim.fs.joinpath(
utils.proj_root(),
"lua",
utils.proj_name(),
"/init.lua"
),
}, opts.terminal or {}, false)
end
---@type VernLanguageConfig
M.lua = {
@@ -16,7 +29,7 @@ M.lua = {
dirs = {
src = "lua/{project_name}",
},
keybinds = {},
keybinds = nil,
templates = {
project = {
primary = {
@@ -40,7 +53,7 @@ M.lua = {
kind_path = "vern-nvim.templates.lua",
},
},
extras = {},
extras = nil,
},
}
+60 -6
View File
@@ -1,3 +1,5 @@
local utils = require("vern-nvim.utils")
local M = {}
M.attach = function()
@@ -28,10 +30,62 @@ M.create_project = function(root)
end
---@type VernCreateFile
M.create_file = {
allowed = false,
func = function(_, _) return nil end,
}
M.create_file = nil
---@param opts VernPythonConfig Takes a table for the runtime
M.run = function(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 bin = opts.python.templates.project.primary
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
M.pip_install = function()
vim.ui.input({ prompt = "Enter pip module: " }, function(mod)
mod = mod and vim.trim(mod)
if not mod or mod == "" then
vim.notify(
"Pip Cancelled",
vim.log.levels.WARN,
{ title = "Vern Python" }
)
return
end
vim.notify(
"Installing " .. mod,
vim.log.levels.INFO,
{ title = "Vern Python" }
)
vim.system({ "pip", "install", mod }, { text = true }, function(obj)
vim.schedule(function()
if obj.code ~= 0 then
vim.notify(
"Pip failed: " .. obj.stderr,
vim.log.levels.WARN,
{ title = "Vern Python" }
)
else
vim.notify(
"Pip installed " .. mod,
vim.log.levels.INFO,
{ title = "Vern Python" }
)
end
end)
end)
end)
end
---@type VernLanguageConfig
M.python = {
@@ -43,7 +97,7 @@ M.python = {
["<leader>pi"] = {
user_command = "VernPythonPip",
desc = "Install python packages for environment",
action = require("vern-nvim.actions.python").pip_install,
action = M.pip_install,
},
},
templates = {
@@ -75,7 +129,7 @@ M.python = {
kind_path = "vern-nvim.templates.python",
},
},
extras = {},
extras = nil,
},
}
return M
+16 -7
View File
@@ -1,6 +1,8 @@
local utils = require("vern-nvim.utils")
local M = {}
M.attach = function() end
M.attach = nil
M.create_project = function(root)
local obj = vim.system({
@@ -17,16 +19,23 @@ M.create_project = function(root)
end
---@type VernCreateFile
M.create_file = {
allowed = false,
func = function(_, _) return nil end,
}
M.create_file = nil
---@param opts VernRustConfig Takes a table for the runtime
M.run = function(opts)
opts = opts or {}
utils.term(
{ "cd " .. utils.proj_root() .. " && cargo run" },
opts.terminal or {},
false
)
end
---@type VernLanguageConfig
M.rust = {
root = "Rust",
dirs = nil,
keybinds = {},
keybinds = nil,
templates = {
project = {
primary = { path = "src", name = "main.rs" },
@@ -39,7 +48,7 @@ M.rust = {
kind_path = "vern-nvim.templates.rust",
},
},
extras = {},
extras = nil,
},
}
+1 -1
View File
@@ -41,7 +41,7 @@ function M.setup(user_opts)
if not ok then return end
local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {})
if opts[ft] and opts[ft].keybinds then
if opts[ft] and opts[ft].keybinds ~= nil then
for key, def in pairs(opts[ft].keybinds or {}) do
if type(def.action) == "function" then
vim.api.nvim_buf_create_user_command(
@@ -0,0 +1,31 @@
local M = {}
local utils = require("vern-nvim.utils")
M.compile = function(opts, build_cmd, run_cmd)
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
)
utils.term_override(buf, error_lines)
end)
else
vim.schedule(
function() utils.term({ run_cmd }, opts.terminal, false) end
)
end
end)
end
return M
+2 -3
View File
@@ -3,8 +3,7 @@
---@alias SplitAnchorType "right" | "bottom"
---@class VernCreateFile
---@field allowed boolean Determines whether actions/init.lua uses the function
---@field func fun(opts: any, continue: fun(mod: VernFileLayout|nil)): any?
---@field func? fun(opts: any, continue: fun(mod: VernFileLayout|nil)): any?
---@class VernKeybindItem
---@field user_command string
@@ -57,7 +56,7 @@
---@class VernLanguageConfig
---@field root string
---@field dirs table<string, string>|nil
---@field keybinds table<string, VernKeybindItem>
---@field keybinds? table<string, VernKeybindItem>
---@field templates VernLanguageTemplates
---@class VernPythonConfig : VernCoreConfig