REFACTOR: Annotations for autocompletion, reworked how projects are made
and handled, wrote the c file replacing the copied python code.
This commit is contained in:
+68
-27
@@ -3,7 +3,9 @@ local M = {}
|
|||||||
local utils = require("vern.utils")
|
local utils = require("vern.utils")
|
||||||
local templates = require("vern.templates")
|
local templates = require("vern.templates")
|
||||||
|
|
||||||
local join, get = vim.fs.joinpath, vim.tbl_get
|
local join = vim.fs.joinpath
|
||||||
|
|
||||||
|
---@param opts VernCConfig
|
||||||
function M.create_project(opts)
|
function M.create_project(opts)
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||||
pname = pname and vim.trim(pname)
|
pname = pname and vim.trim(pname)
|
||||||
@@ -11,46 +13,85 @@ function M.create_project(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local configs = require("vern.configs")
|
local configs = require("vern.configs.c")
|
||||||
local pconfigs = require("vern.configs.python")
|
|
||||||
|
|
||||||
local cfg = vim.tbl_deep_extend("force", {}, configs, pconfigs, opts or {})
|
---@type VernCConfig
|
||||||
|
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
|
||||||
local ctx = { project_name = pname }
|
local ctx = { project_name = pname }
|
||||||
local py = cfg.python
|
|
||||||
|
|
||||||
local root = join(vim.fn.expand(cfg.workspace_root), py.root, pname)
|
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname)
|
||||||
vim.fn.mkdir(join(root, utils.fmt(py.source_root, ctx)), "p")
|
vim.fn.mkdir(root, "p")
|
||||||
|
local bin
|
||||||
local tmpl = get(py, "templates", "project") or {}
|
for tbl_name, tbl in pairs(cfg.c.templates.project) do
|
||||||
local function dump(k, alt, id)
|
local raw_path = join(tbl.path, tbl.name)
|
||||||
local path = join(root, utils.fmt(get(tmpl, k, "target") or alt, ctx))
|
local path = utils.resolve_path(raw_path, cfg.c.dirs, ctx)
|
||||||
utils.dump(path, templates.fetch("python", id, pname))
|
if tbl_name == "primary" then
|
||||||
return path
|
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
|
end
|
||||||
|
|
||||||
local bin = dump("bin", py.source_root .. "/main.py", "main")
|
utils.init_git(root, "c")
|
||||||
dump("pkg", py.source_root .. "/__init__.py", "__init__")
|
|
||||||
dump("cfg", "pyproject.toml", "pyproject")
|
|
||||||
utils.init_git(root, "python")
|
|
||||||
|
|
||||||
local venv_path = root .. "/venv"
|
|
||||||
vim.fn.system("python3 -m venv " .. venv_path)
|
|
||||||
|
|
||||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.create_file(opts)
|
function M.create_file(opts)
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
|
||||||
fname = fname and vim.trim(fname)
|
ft = ft and vim.trim(ft)
|
||||||
if not fname or fname == "" then
|
if not ft or ft == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local root = get(opts, "python", "templates", "file", "mod").target or {}
|
local configs = require("vern.configs.c")
|
||||||
|
---@type VernCConfig
|
||||||
|
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||||
|
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
|
||||||
|
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 context = { project_name = utils.proj_name(), name = fname }
|
||||||
local path = join(utils.proj_root(), utils.fmt(root, context))
|
local path = utils.resolve_path(raw_path, cfg.c.dirs or {}, context)
|
||||||
utils.dump(path, templates.fetch("python", "module", fname))
|
local abs_file_path = vim.fs.normalize(join(root, path))
|
||||||
vim.cmd.edit(vim.fn.expand(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))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+55
-46
@@ -1,26 +1,11 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- -- Simple test function that pulls directly from the table and prints
|
|
||||||
-- function M.test_print()
|
|
||||||
-- local configs = require("vern.configs")
|
|
||||||
-- local pconfigs = require("vern.configs.python")
|
|
||||||
--
|
|
||||||
-- local cfg = vim.tbl_deep_extend("force", {}, configs, pconfigs)
|
|
||||||
-- -- Pulling straight from the python_config table
|
|
||||||
-- local raw_path = cfg.python.templates.project.bin.path
|
|
||||||
-- local dirs = cfg.python.dirs
|
|
||||||
-- local context = { project_name = "my_cool_app" }
|
|
||||||
--
|
|
||||||
-- local final_path = M.resolve_path(raw_path, dirs, context)
|
|
||||||
--
|
|
||||||
-- print("Raw path:", raw_path)
|
|
||||||
-- print("Resolved path:", final_path)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
local utils = require("vern.utils")
|
local utils = require("vern.utils")
|
||||||
local templates = require("vern.templates")
|
local templates = require("vern.templates")
|
||||||
|
|
||||||
local join, get = vim.fs.joinpath, vim.tbl_get
|
local join = vim.fs.joinpath
|
||||||
|
|
||||||
|
---@param opts VernPythonConfig
|
||||||
function M.create_project(opts)
|
function M.create_project(opts)
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||||
pname = pname and vim.trim(pname)
|
pname = pname and vim.trim(pname)
|
||||||
@@ -28,79 +13,103 @@ function M.create_project(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local configs = require("vern.configs")
|
local configs = require("vern.configs.python")
|
||||||
local pconfigs = require("vern.configs.python")
|
---@type VernPythonConfig
|
||||||
|
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||||
local cfg = vim.tbl_deep_extend("force", {}, configs, pconfigs, opts or {})
|
|
||||||
local ctx = { project_name = pname }
|
local ctx = { project_name = pname }
|
||||||
local py = cfg.python
|
|
||||||
|
|
||||||
local root = join(vim.fn.expand(cfg.workspace_root), py.root, pname)
|
local root = join(vim.fn.expand(cfg.workspace_root), cfg.python.root, pname)
|
||||||
|
vim.fn.mkdir(root, "p")
|
||||||
local bin
|
local bin
|
||||||
for tbl_name, tbl in pairs(py.templates.project) do
|
for tbl_name, tbl in pairs(cfg.python.templates.project) do
|
||||||
local raw_path = join(tbl.path, tbl.name)
|
local raw_path = join(tbl.path, tbl.name)
|
||||||
local path = utils.resolve_path(raw_path, py.dirs, ctx)
|
local path = utils.resolve_path(raw_path, cfg.python.dirs, ctx)
|
||||||
if tbl_name == "bin" then
|
if tbl_name == "primary" then
|
||||||
bin = join(root, path)
|
bin = join(root, path)
|
||||||
end
|
end
|
||||||
local abs_file_path = join(root, path)
|
local abs_file_path = join(root, path)
|
||||||
local abs_dir_path = vim.fs.dirname(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")
|
vim.fn.mkdir(abs_dir_path, "p")
|
||||||
|
end
|
||||||
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
|
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
|
||||||
end
|
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
|
||||||
|
|
||||||
utils.init_git(root, "python")
|
utils.init_git(root, "python")
|
||||||
|
|
||||||
local venv_path = root .. "/venv"
|
local venv_path = root .. "/venv"
|
||||||
vim.fn.system("python3 -m venv " .. venv_path)
|
vim.fn.system("python3 -m venv " .. venv_path)
|
||||||
|
|
||||||
|
vim.notify("Project: " .. pname .. " has been created!")
|
||||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param opts VernPythonConfig
|
||||||
function M.create_file(opts)
|
function M.create_file(opts)
|
||||||
|
opts = opts or {}
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||||
fname = fname and vim.trim(fname)
|
fname = fname and vim.trim(fname)
|
||||||
if not fname or fname == "" then
|
if not fname or fname == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local py = get(opts, "python")
|
local configs = require("vern.configs.python")
|
||||||
local cfg = get(py, "templates", "file", "mod") or {}
|
---@type VernPythonConfig
|
||||||
|
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||||
|
local mod = cfg.python.templates.file.mod or {}
|
||||||
|
|
||||||
local raw_path = join(cfg.path, cfg.name)
|
local raw_path = join(mod.path, mod.name)
|
||||||
local context = { project_name = utils.proj_name(), name = fname }
|
local context = { project_name = utils.proj_name(), name = fname }
|
||||||
local path = utils.resolve_path(raw_path, py.dirs or {}, context)
|
local path = utils.resolve_path(raw_path, cfg.python.dirs or {}, context)
|
||||||
|
|
||||||
utils.dump(path, templates.fetch("python", "module", fname))
|
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))
|
vim.cmd.edit(vim.fn.expand(path))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Goal is to add providers for uv and venv so its available to more users
|
---@param opts VernPythonConfig Takes a table for the runtime
|
||||||
---@param opts? table Takes a table for the runtime
|
|
||||||
function M.run(opts)
|
function M.run(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local root = utils.proj_root() or "."
|
local root = utils.proj_root() or "."
|
||||||
local pname = vim.fs.basename(root)
|
local pname = vim.fs.basename(root)
|
||||||
|
local bin = opts.python.templates.project.primary
|
||||||
|
|
||||||
local exe = opts.python.templates.project.bin.target or "src/{project_name}/main.py"
|
local exe = join(bin.path, bin.name) or "src/{project_name}/main.py"
|
||||||
local full_path = join(vim.fn.expand(root), utils.fmt(exe, { project_name = pname }))
|
local exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname })
|
||||||
|
local full_path = join(vim.fn.expand(root), exe_path)
|
||||||
utils.term({ "python3 " .. full_path }, opts.terminal or {})
|
utils.term({ "python3 " .. full_path }, opts.terminal or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param cmd_args? table Takes a table for the runtime
|
function M.pip_install()
|
||||||
function M.pip_install(opts, cmd_args)
|
vim.ui.input({ prompt = "Enter pip module: " }, function(mod)
|
||||||
local args = cmd_args and cmd_args.args and vim.trim(cmd_args.args) or ""
|
mod = mod and vim.trim(mod)
|
||||||
if args ~= "" then
|
if not mod or mod == "" then
|
||||||
utils.term({ "pip install " .. args }, opts.terminal or {})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
|
||||||
if not pip_module or vim.trim(pip_module) == "" then
|
|
||||||
vim.notify("Pip Cancelled", vim.log.levels.WARN)
|
vim.notify("Pip Cancelled", vim.log.levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
utils.term({ "pip install " .. vim.trim(pip_module) }, opts.terminal or {})
|
vim.notify("Installing " .. mod, vim.log.levels.INFO)
|
||||||
|
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)
|
||||||
|
else
|
||||||
|
vim.notify("Pip installed " .. mod, vim.log.levels.INFO)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+10
-7
@@ -1,19 +1,22 @@
|
|||||||
local actions = require("vern.actions.python")
|
local actions = require("vern.actions.python")
|
||||||
local config = require("vern.configs.python")
|
local config = require("vern.configs.python")
|
||||||
|
|
||||||
|
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||||
|
---@param user_opts? VernPythonConfig
|
||||||
return function(bufnr, user_opts)
|
return function(bufnr, user_opts)
|
||||||
|
---@type VernPythonConfig
|
||||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
|
vim.api.nvim_buf_create_user_command(bufnr, "CRun", function()
|
||||||
if type(actions.run) == "function" then
|
if type(actions.run) == "function" then
|
||||||
actions.run(opts)
|
actions.run(opts)
|
||||||
end
|
end
|
||||||
end, { desc = "Run python project" })
|
end, { desc = "Run c project" })
|
||||||
|
|
||||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function(cmd_args)
|
-- vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function(cmd_args)
|
||||||
if actions.pip_install then
|
-- if actions.pip_install then
|
||||||
actions.pip_install(opts, cmd_args)
|
-- actions.pip_install()
|
||||||
end
|
-- end
|
||||||
end, { nargs = "*", desc = "Install python packages" })
|
-- end, { nargs = "*", desc = "Install python packages" })
|
||||||
|
|
||||||
for key, def in pairs(opts.python.keybinds or {}) do
|
for key, def in pairs(opts.python.keybinds or {}) do
|
||||||
if type(def.action) == "function" then
|
if type(def.action) == "function" then
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
local actions = require("vern.actions.python")
|
local actions = require("vern.actions.python")
|
||||||
local config = require("vern.configs.python")
|
local config = require("vern.configs.python")
|
||||||
|
|
||||||
|
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||||
|
---@param user_opts? VernPythonConfig
|
||||||
return function(bufnr, user_opts)
|
return function(bufnr, user_opts)
|
||||||
|
---@type VernPythonConfig
|
||||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
|
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
|
||||||
if type(actions.run) == "function" then
|
if type(actions.run) == "function" then
|
||||||
@@ -9,9 +12,9 @@ return function(bufnr, user_opts)
|
|||||||
end
|
end
|
||||||
end, { desc = "Run python project" })
|
end, { desc = "Run python project" })
|
||||||
|
|
||||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function(cmd_args)
|
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function()
|
||||||
if actions.pip_install then
|
if actions.pip_install then
|
||||||
actions.pip_install(opts, cmd_args)
|
actions.pip_install()
|
||||||
end
|
end
|
||||||
end, { nargs = "*", desc = "Install python packages" })
|
end, { nargs = "*", desc = "Install python packages" })
|
||||||
|
|
||||||
|
|||||||
+45
-18
@@ -1,40 +1,67 @@
|
|||||||
return {
|
local M = {}
|
||||||
c = {
|
|
||||||
|
---@type VernLanguageConfig
|
||||||
|
M.c = {
|
||||||
root = "C",
|
root = "C",
|
||||||
-- source_root = "src/{project_name}",
|
dirs = {
|
||||||
|
src = "src",
|
||||||
|
include = "include/{project_name}",
|
||||||
|
},
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = {
|
["<leader>pr"] = {
|
||||||
desc = "Executes c code",
|
desc = "Executes c code",
|
||||||
action = require("vern.actions.c").run,
|
action = require("vern.actions.c").run,
|
||||||
},
|
},
|
||||||
["<leader>px"] = {
|
["<leader>pf"] = {
|
||||||
desc = "Creates header files",
|
desc = "Creates source/header files",
|
||||||
action = require("vern.actions.python").create_header,
|
action = require("vern.actions.c").create_file,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
templates = {
|
templates = {
|
||||||
project = {
|
project = {
|
||||||
bin = {
|
primary = {
|
||||||
target = "src/{project_name}/main.py",
|
path = "{dirs.src}",
|
||||||
|
name = "main.c",
|
||||||
|
kind = "main",
|
||||||
|
kind_path = "vern.templates.c",
|
||||||
},
|
},
|
||||||
pkg = {
|
manifest = {
|
||||||
target = "src/{project_name}/__init__.py",
|
path = ".",
|
||||||
|
name = "CMakeLists.txt",
|
||||||
|
kind = "CmakeLists",
|
||||||
|
kind_path = "vern.templates.c",
|
||||||
},
|
},
|
||||||
cfg = {
|
style = {
|
||||||
target = "pyproject.toml",
|
path = ".",
|
||||||
|
name = ".clang-format",
|
||||||
|
kind = "format",
|
||||||
|
kind_path = "vern.templates.c",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
file = {
|
file = {
|
||||||
mod = {
|
header = {
|
||||||
target = "src/{project_name}/{name}.py",
|
path = "{dirs.include}",
|
||||||
|
name = "{name}.h",
|
||||||
|
kind = "header",
|
||||||
|
kind_path = "vern.templates.c",
|
||||||
|
},
|
||||||
|
source = {
|
||||||
|
path = "{dirs.src}",
|
||||||
|
name = "{name}.c",
|
||||||
|
kind = "source",
|
||||||
|
kind_path = "vern.templates.c",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extras = {
|
extras = {
|
||||||
gitignore = {
|
linter = {
|
||||||
template = "vern.templates.extras.gitignore", --- needs to call the function in file
|
path = ".",
|
||||||
target = ".gitignore",
|
name = ".clang-tidy",
|
||||||
},
|
kind = "linter",
|
||||||
|
kind_path = "vern.templates.c",
|
||||||
|
enabled = false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return M
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
local actions = require("vern.actions")
|
local actions = require("vern.actions")
|
||||||
|
|
||||||
|
---@type VernCoreConfig
|
||||||
return {
|
return {
|
||||||
workspace_root = "~/personal/Projects",
|
workspace_root = "~/personal/Projects",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
@@ -13,7 +15,7 @@ return {
|
|||||||
},
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
mode = {
|
mode = {
|
||||||
type = "split", --- can be split or float
|
type = "split",
|
||||||
win = {
|
win = {
|
||||||
float = {
|
float = {
|
||||||
padding = {
|
padding = {
|
||||||
@@ -24,12 +26,12 @@ return {
|
|||||||
},
|
},
|
||||||
border = {
|
border = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
type = vim.o.winborder,
|
type = vim.o.winborder, -- defaults to neovim winborder
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
split = {
|
split = {
|
||||||
type = "horizontal", --- can be vertical or horizontal
|
direction = "horizontal",
|
||||||
anchor = "bottom", --- can be right or bottom
|
anchor = "bottom",
|
||||||
size = "20",
|
size = "20",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+10
-12
@@ -1,5 +1,6 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@type VernLanguageConfig
|
||||||
M.python = {
|
M.python = {
|
||||||
root = "Python",
|
root = "Python",
|
||||||
dirs = {
|
dirs = {
|
||||||
@@ -10,38 +11,35 @@ M.python = {
|
|||||||
desc = "Executes python code",
|
desc = "Executes python code",
|
||||||
action = require("vern.actions.python").run,
|
action = require("vern.actions.python").run,
|
||||||
},
|
},
|
||||||
["<leader>pb"] = {
|
["<leader>pi"] = {
|
||||||
desc = "Asks for what python package to install",
|
desc = "Asks for what python package to install",
|
||||||
action = require("vern.actions.python").pip_install,
|
action = require("vern.actions.python").pip_install,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
templates = {
|
templates = {
|
||||||
project = {
|
project = {
|
||||||
bin = {
|
primary = {
|
||||||
path = "{dirs.src}",
|
path = "{dirs.src}",
|
||||||
-- path = "src/{project_name}",
|
|
||||||
name = "main.py",
|
name = "main.py",
|
||||||
kind = "main",
|
kind = "main",
|
||||||
kind_path = "vern.templates.python",
|
kind_path = "vern.templates.python",
|
||||||
},
|
},
|
||||||
pkg = {
|
manifest = {
|
||||||
path = "{dirs.src}",
|
|
||||||
-- path = "src/{project_name}",
|
|
||||||
name = "__init__.py",
|
|
||||||
kind = "__init__",
|
|
||||||
kind_path = "vern.templates.python",
|
|
||||||
},
|
|
||||||
cfg = {
|
|
||||||
path = ".",
|
path = ".",
|
||||||
name = "pyproject.toml",
|
name = "pyproject.toml",
|
||||||
kind = "pyproject",
|
kind = "pyproject",
|
||||||
kind_path = "vern.templates.python",
|
kind_path = "vern.templates.python",
|
||||||
},
|
},
|
||||||
|
pkg_init = {
|
||||||
|
path = "{dirs.src}",
|
||||||
|
name = "__init__.py",
|
||||||
|
kind = "__init__",
|
||||||
|
kind_path = "vern.templates.python",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
file = {
|
file = {
|
||||||
mod = {
|
mod = {
|
||||||
path = "{dirs.src}",
|
path = "{dirs.src}",
|
||||||
-- path = "src/{project_name}",
|
|
||||||
name = "{name}.py",
|
name = "{name}.py",
|
||||||
kind = "module",
|
kind = "module",
|
||||||
kind_path = "vern.templates.python",
|
kind_path = "vern.templates.python",
|
||||||
|
|||||||
+6
-13
@@ -1,19 +1,16 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.test()
|
|
||||||
vim.ui.input({ prompt = "Test: ", default = "" }, function(input)
|
|
||||||
print(input)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local configs = require("vern.configs")
|
local configs = require("vern.configs")
|
||||||
local actions = require("vern.actions")
|
local actions = require("vern.actions")
|
||||||
M.opts = {}
|
|
||||||
|
|
||||||
|
---@type VernCoreConfig
|
||||||
|
M.opts = vim.deepcopy(configs)
|
||||||
|
|
||||||
|
---@param user_opts? VernCoreConfig | table
|
||||||
function M.setup(user_opts)
|
function M.setup(user_opts)
|
||||||
|
---@type VernCoreConfig
|
||||||
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
||||||
|
|
||||||
--- Bind global keybinds
|
|
||||||
for key, def in pairs(M.opts.keybinds or {}) do
|
for key, def in pairs(M.opts.keybinds or {}) do
|
||||||
if type(def.action) == "function" then
|
if type(def.action) == "function" then
|
||||||
vim.keymap.set("n", key, function()
|
vim.keymap.set("n", key, function()
|
||||||
@@ -25,7 +22,6 @@ function M.setup(user_opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Load project cmdline commands
|
|
||||||
vim.api.nvim_create_user_command("VernCreateProject", function()
|
vim.api.nvim_create_user_command("VernCreateProject", function()
|
||||||
if actions.create_project then
|
if actions.create_project then
|
||||||
actions.create_project(M.opts)
|
actions.create_project(M.opts)
|
||||||
@@ -38,10 +34,7 @@ function M.setup(user_opts)
|
|||||||
end
|
end
|
||||||
end, { nargs = "*", desc = "Creates a new file for project" })
|
end, { nargs = "*", desc = "Creates a new file for project" })
|
||||||
|
|
||||||
--- Create group and attach based on ft
|
local group = vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
||||||
local group =
|
|
||||||
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = group,
|
group = group,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
|
|||||||
+81
-21
@@ -21,10 +21,30 @@ main()
|
|||||||
File: __init__.py
|
File: __init__.py
|
||||||
Target: src/{project_name}/__init__.py
|
Target: src/{project_name}/__init__.py
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
__init__ = vim.trim([=[
|
format = vim.trim([=[
|
||||||
# %s init
|
---
|
||||||
|
BasedOnStyle: Google
|
||||||
__all__: list[str] = []
|
Standard: Latest
|
||||||
|
UseTab: Always
|
||||||
|
TabWidth: 8
|
||||||
|
IndentWidth: 8
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
SpaceBeforeCpp11BracedList: true
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
BreakAfterReturnType: TopLevel
|
||||||
|
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
|
||||||
|
IndentGotoLabels: InnerIndent
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Left
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
IncludeBlocks: Preserve
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
@@ -32,21 +52,28 @@ __all__: list[str] = []
|
|||||||
File: pyproject.toml
|
File: pyproject.toml
|
||||||
Target: pyproject.toml
|
Target: pyproject.toml
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
pyproject = vim.trim([=[
|
CmakeLists = vim.trim([=[
|
||||||
[build-system]
|
cmake_minimum_required(VERSION 3.16)
|
||||||
requires = ["hatchling"]
|
project(__PROJECT_NAME__ LANGUAGES C)
|
||||||
build-backend = "hatchling.build"
|
set(CMAKE_C_STANDARD 23)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
[project]
|
add_library(__PROJECT_NAME__ STATIC
|
||||||
name = "%s"
|
# Add your other types here as you implement them:
|
||||||
version = "0.1.0"
|
# src/example1.c
|
||||||
description = "Project %s"
|
# src/example2.c
|
||||||
readme = "README.md"
|
)
|
||||||
requires-python = ">=3.10"
|
|
||||||
dependencies = []
|
|
||||||
|
|
||||||
[project.scripts]
|
target_include_directories(__PROJECT_NAME__
|
||||||
%s = "%s.main:main"
|
PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(__PROJECT_NAME___bin src/main.c)
|
||||||
|
set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__")
|
||||||
|
|
||||||
|
target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__)
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
@@ -54,9 +81,42 @@ dependencies = []
|
|||||||
File: {name}.py
|
File: {name}.py
|
||||||
Target: src/{project_name}/{name}.py
|
Target: src/{project_name}/{name}.py
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
module = vim.trim([=[
|
header = vim.trim([=[
|
||||||
"""
|
#ifndef __PROJECT_NAME___H
|
||||||
Module: %s
|
#define __PROJECT_NAME___H
|
||||||
"""
|
|
||||||
|
// Code
|
||||||
|
|
||||||
|
#endif /* __PROJECT_NAME___H */
|
||||||
|
]=]) .. "\n",
|
||||||
|
|
||||||
|
source = vim.trim([=[
|
||||||
|
]=]) .. "\n",
|
||||||
|
|
||||||
|
linter = vim.trim([=[
|
||||||
|
Checks: >
|
||||||
|
-*,
|
||||||
|
clang-analyzer-*,
|
||||||
|
bugprone-*,
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-reserved-identifier,
|
||||||
|
performance-*,
|
||||||
|
security-*
|
||||||
|
|
||||||
|
readability-redundant-declaration
|
||||||
|
readability-misleading-indentation
|
||||||
|
readability-implicit-bool-conversion
|
||||||
|
misc-misplaced-const,
|
||||||
|
misc-include-cleaner
|
||||||
|
|
||||||
|
-bugprone-narrowing-conversions,
|
||||||
|
-readability-identifier-length
|
||||||
|
CheckOptions:
|
||||||
|
readability-identifier-naming.VariableCase: lower_case
|
||||||
|
readability-identifier-naming.FunctionCase: lower_case
|
||||||
|
readability-identifier-naming.StructCase: lower_case
|
||||||
|
readability-identifier-naming.EnumCase: CamelCase
|
||||||
|
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
||||||
|
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@param path string Filetype of template
|
---@param kind_path string Filetype of template
|
||||||
---@param kind string Template in language table
|
---@param kind string Template in language table
|
||||||
---@param name string A string to replace temp values in template
|
---@param name string A string to replace temp values in template
|
||||||
---@return string
|
---@return string Content Formatted string
|
||||||
function M.fetch(kind_path, kind, name)
|
function M.fetch(kind_path, kind, name)
|
||||||
kind_path, kind, name = kind_path or "", kind or "", name or ""
|
kind, name = kind or "", name or ""
|
||||||
if kind_path == "" or kind == "" or name == "" then
|
if (kind == "" or nil) or (name == "" or nil) then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
local ok, mod = pcall(require, kind_path)
|
local ok, mod = pcall(require, kind_path)
|
||||||
if ok and type(mod) == "table" then
|
if ok and type(mod) == "table" then
|
||||||
return (string.gsub(mod[kind], "%%s", name))
|
return (string.gsub(mod[kind], "__PROJECT_NAME__", name))
|
||||||
end
|
end
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ return {
|
|||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
main = vim.trim([=[
|
main = vim.trim([=[
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
print("Hello from %s!")
|
print("Hello from __PROJECT_NAME__!")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -19,7 +19,7 @@ if __name__ == "__main__":
|
|||||||
Target: src/{project_name}/__init__.py
|
Target: src/{project_name}/__init__.py
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
__init__ = vim.trim([=[
|
__init__ = vim.trim([=[
|
||||||
# %s init
|
# __PROJECT_NAME__ init
|
||||||
|
|
||||||
__all__: list[str] = []
|
__all__: list[str] = []
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
@@ -35,15 +35,15 @@ requires = ["hatchling"]
|
|||||||
build-backend = "hatchling.build"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "%s"
|
name = "__PROJECT_NAME__"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Project %s"
|
description = "Project __PROJECT_NAME__"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
%s = "%s.main:main"
|
__PROJECT_NAME__ = "__PROJECT_NAME__.main:main"
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
@@ -53,7 +53,7 @@ dependencies = []
|
|||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
module = vim.trim([=[
|
module = vim.trim([=[
|
||||||
"""
|
"""
|
||||||
Module: %s
|
Module: __PROJECT_NAME__
|
||||||
"""
|
"""
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
---@alias TerminalModeType "split" | "float"
|
||||||
|
---@alias SplitDirection "vertical" | "horizontal"
|
||||||
|
---@alias SplitAnchorType "right" | "bottom"
|
||||||
|
|
||||||
|
---@class VernKeybindItem
|
||||||
|
---@field desc string
|
||||||
|
---@field action function
|
||||||
|
|
||||||
|
---@class VernFloatWindowConfig
|
||||||
|
---@field padding { left: integer, right: integer, top: integer, bottom: integer }
|
||||||
|
---@field border { enabled: boolean, type: string }
|
||||||
|
|
||||||
|
---@class VernSplitWindowConfig
|
||||||
|
---@field direction SplitDirection
|
||||||
|
---@field anchor SplitAnchorType
|
||||||
|
---@field size string
|
||||||
|
|
||||||
|
---@class VernWindowConfig
|
||||||
|
---@field float VernFloatWindowConfig
|
||||||
|
---@field split VernSplitWindowConfig
|
||||||
|
|
||||||
|
---@class VernModeConfig
|
||||||
|
---@field type TerminalModeType
|
||||||
|
---@field win VernWindowConfig
|
||||||
|
|
||||||
|
---@class VernTerminalConfig
|
||||||
|
---@field mode VernModeConfig
|
||||||
|
|
||||||
|
---@class VernCoreConfig
|
||||||
|
---@field workspace_root string
|
||||||
|
---@field keybinds table<string, VernKeybindItem>
|
||||||
|
---@field terminal VernTerminalConfig
|
||||||
|
|
||||||
|
---@class VernFileLayout
|
||||||
|
---@field path string
|
||||||
|
---@field name string
|
||||||
|
---@field kind string
|
||||||
|
---@field kind_path string
|
||||||
|
|
||||||
|
---@class VernExtrasLayout : VernFileLayout
|
||||||
|
---@field enabled boolean
|
||||||
|
|
||||||
|
---@class VernLanguageTemplates
|
||||||
|
---@field project table<string, VernFileLayout>
|
||||||
|
---@field file table<string, VernFileLayout>
|
||||||
|
---@field extras table<string, VernExtrasLayout>
|
||||||
|
|
||||||
|
---@class VernLanguageConfig
|
||||||
|
---@field root string
|
||||||
|
---@field dirs table<string, string>
|
||||||
|
---@field keybinds table<string, VernKeybindItem>
|
||||||
|
---@field templates VernLanguageTemplates
|
||||||
|
|
||||||
|
---@class VernPythonConfig : VernCoreConfig
|
||||||
|
---@field python VernLanguageConfig
|
||||||
|
|
||||||
|
---@class VernCConfig : VernCoreConfig
|
||||||
|
---@field c VernLanguageConfig
|
||||||
+3
-2
@@ -69,6 +69,7 @@ function M.init_readme(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param cmd table
|
---@param cmd table
|
||||||
|
---@param opts VernTerminalConfig
|
||||||
---@return integer, integer?
|
---@return integer, integer?
|
||||||
function M.term(cmd, opts)
|
function M.term(cmd, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
@@ -110,13 +111,13 @@ function M.term(cmd, opts)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
if opts.mode.type == "split" then
|
if opts.mode.type == "split" then
|
||||||
if opts.mode.win.split.type == "vertical" then
|
if opts.mode.win.split.direction == "vertical" then
|
||||||
if opts.mode.win.split.anchor == "right" then
|
if opts.mode.win.split.anchor == "right" then
|
||||||
vim.cmd("set splitright")
|
vim.cmd("set splitright")
|
||||||
end
|
end
|
||||||
vim.cmd(opts.mode.win.split.size .. " vsplit")
|
vim.cmd(opts.mode.win.split.size .. " vsplit")
|
||||||
end
|
end
|
||||||
if opts.mode.win.split.type == "horizontal" then
|
if opts.mode.win.split.direction == "horizontal" then
|
||||||
if opts.mode.win.split.anchor == "bottom" then
|
if opts.mode.win.split.anchor == "bottom" then
|
||||||
vim.cmd("set splitbelow")
|
vim.cmd("set splitbelow")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user