Chore: moved similar functions to a utils for actions so they dont
repeat and copy costantly. Going to have to think of a better way that consolidates it all as a lot of it overlaps
This commit is contained in:
+2
-31
@@ -2,6 +2,7 @@ local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.templates")
|
||||
local action_utils = require("vern.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
@@ -17,38 +18,8 @@ function M.create_project(opts)
|
||||
|
||||
---@type VernCConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
|
||||
local ctx = { project_name = pname }
|
||||
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname)
|
||||
vim.fn.mkdir(root, "p")
|
||||
local bin
|
||||
for tbl_name, tbl in pairs(cfg.c.templates.project) do
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.c.dirs, ctx)
|
||||
if tbl_name == "primary" then
|
||||
bin = join(root, path)
|
||||
end
|
||||
local abs_file_path = vim.fs.normalize(join(root, path))
|
||||
print("File Path: " .. abs_file_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.c.templates.extras) do
|
||||
if tbl.enabled then
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.c.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
|
||||
|
||||
local bin = action_utils.create(cfg.c, pname, root)
|
||||
utils.init_git(root, "c")
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
|
||||
@@ -2,6 +2,7 @@ local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.templates")
|
||||
local action_utils = require("vern.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
@@ -14,38 +15,11 @@ function M.create_project(opts)
|
||||
end
|
||||
|
||||
local configs = require("vern.configs.python")
|
||||
|
||||
---@type VernPythonConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
local ctx = { project_name = pname }
|
||||
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.python.root, pname)
|
||||
vim.fn.mkdir(root, "p")
|
||||
local bin
|
||||
for tbl_name, tbl in pairs(cfg.python.templates.project) do
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.python.dirs, ctx)
|
||||
if tbl_name == "primary" then
|
||||
bin = join(root, path)
|
||||
end
|
||||
local abs_file_path = 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.python.templates.extras) do
|
||||
if tbl.enabled then
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.python.dirs, ctx)
|
||||
local abs_file_path = 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
|
||||
local bin = action_utils.create(cfg.python, pname, root)
|
||||
|
||||
utils.init_git(root, "python")
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.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 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
|
||||
@@ -12,12 +12,6 @@ return function(bufnr, user_opts)
|
||||
end
|
||||
end, { desc = "Run c project" })
|
||||
|
||||
-- vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function(cmd_args)
|
||||
-- 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()
|
||||
@@ -29,19 +23,4 @@ return function(bufnr, user_opts)
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local root = require("vern.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
-1
@@ -6,7 +6,12 @@ local actions = require("vern.actions")
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.deepcopy(configs)
|
||||
|
||||
---@param user_opts? VernCoreConfig | table
|
||||
---@class VernUserConfig
|
||||
---@field workspace_root? string
|
||||
---@field keybinds? table<string, VernKeybindItem>
|
||||
---@field terminal? VernTerminalConfig | table
|
||||
|
||||
---@param user_opts? VernUserConfig
|
||||
function M.setup(user_opts)
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
||||
|
||||
Reference in New Issue
Block a user