REFACTOR: Merged templates into a per language file, deleted init.lua as
it was just a middle man and wasnt needed (in fact it is better without it) FT: Changes to python
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.create_project = function(opts, args)
|
||||||
|
opts = opts or {}
|
||||||
|
local test = nil
|
||||||
|
if opts and opts.terminal then
|
||||||
|
test = opts.terminal.mode
|
||||||
|
end
|
||||||
|
if args and args.args and args ~= "" then
|
||||||
|
print(string.format("Opts: %s, Args: %s", test, args.args))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
M.create_file = function(opts, args) end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -3,6 +3,9 @@ local M = {}
|
|||||||
local utils = require("vern.utils")
|
local utils = require("vern.utils")
|
||||||
M.default_target_file = "main.py"
|
M.default_target_file = "main.py"
|
||||||
|
|
||||||
|
function M.create_project(opts) end
|
||||||
|
function M.create_file(opts) end
|
||||||
|
|
||||||
--- Goal is to add providers for uv and venv so its available to more users
|
--- Goal is to add providers for uv and venv so its available to more users
|
||||||
---@param opts? table Takes a table for the runtime
|
---@param opts? table Takes a table for the runtime
|
||||||
function M.run(opts)
|
function M.run(opts)
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
function M.buf(bufnr, user_opts)
|
|
||||||
bufnr = (bufnr == nil or bufnr == 0) and vim.api.nvim_get_current_buf()
|
|
||||||
or bufnr
|
|
||||||
local ft = vim.bo[bufnr].filetype
|
|
||||||
if not ft or ft == "" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
user_opts = user_opts or {}
|
|
||||||
|
|
||||||
local default = require("vern.configs.default")
|
|
||||||
|
|
||||||
local lang_opts = (user_opts or {})[ft] or {}
|
|
||||||
local final_opts =
|
|
||||||
vim.tbl_deep_extend("force", {}, default, user_opts, lang_opts)
|
|
||||||
final_opts[ft] = nil
|
|
||||||
local ok, lang_attach = pcall(require, "vern.attach." .. ft) --- like a try / catch block in c++
|
|
||||||
if ok and type(lang_attach) == "function" then
|
|
||||||
lang_attach(bufnr, final_opts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
@@ -1,5 +1,16 @@
|
|||||||
|
local actions = require("vern.actions")
|
||||||
return {
|
return {
|
||||||
workspace_root = "~/personal/Projects",
|
workspace_root = "~/personal/Projects",
|
||||||
|
keybinds = {
|
||||||
|
["<leader>pc"] = {
|
||||||
|
desc = "Creates a new project",
|
||||||
|
action = actions.create_project,
|
||||||
|
},
|
||||||
|
["<leader>pf"] = {
|
||||||
|
desc = "Creates a new project file",
|
||||||
|
action = actions.create_file,
|
||||||
|
},
|
||||||
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
mode = "split",
|
mode = "split",
|
||||||
win = {
|
win = {
|
||||||
|
|||||||
@@ -15,27 +15,27 @@ return {
|
|||||||
templates = {
|
templates = {
|
||||||
project = {
|
project = {
|
||||||
["executable"] = {
|
["executable"] = {
|
||||||
template = "vern.templates.python.main",
|
template = { "vern.templates.python", "main" },
|
||||||
target = "src/%s/main.py",
|
target = "src/%s/main.py",
|
||||||
},
|
},
|
||||||
["init"] = {
|
["init"] = {
|
||||||
template = "vern.templates.python.__init__",
|
template = { "vern.templates.python", "__init__" },
|
||||||
target = "src/%s/__init__.py",
|
target = "src/%s/__init__.py",
|
||||||
},
|
},
|
||||||
["manifest"] = {
|
["manifest"] = {
|
||||||
template = "vern.templates.python.pyproject",
|
template = { "vern.templates.python", "pyproject" },
|
||||||
target = "pyproject.toml",
|
target = "pyproject.toml",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
file = {
|
file = {
|
||||||
["module"] = {
|
["module"] = {
|
||||||
template = "vern.templates.python.module",
|
template = { "vern.templates.python", "module" },
|
||||||
target = "src/%s.py",
|
target = "src/%s.py",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extras = {
|
extras = {
|
||||||
["gitignore"] = {
|
["gitignore"] = {
|
||||||
template = "vern.templates.extras.gitignore",
|
template = "vern.templates.extras.gitignore", --- needs to call the function in file
|
||||||
target = ".gitignore",
|
target = ".gitignore",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
+37
-4
@@ -1,9 +1,38 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.user_opts = {}
|
local global_opts = require("vern.configs.default")
|
||||||
|
local actions = require("vern.actions")
|
||||||
|
M.opts = {}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(user_opts)
|
||||||
M.user_opts = opts or {}
|
M.opts = vim.tbl_deep_extend("force", {}, global_opts, user_opts or {})
|
||||||
|
|
||||||
|
--- Bind global keybinds
|
||||||
|
for key, def in pairs(M.opts.keybinds or {}) do
|
||||||
|
if type(def.action) == "function" then
|
||||||
|
vim.keymap.set("n", key, function()
|
||||||
|
def.action(M.opts)
|
||||||
|
end, {
|
||||||
|
silent = true,
|
||||||
|
desc = def.desc,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Load project cmdline commands
|
||||||
|
vim.api.nvim_create_user_command("VernCreateProject", function(args)
|
||||||
|
if actions.create_project then
|
||||||
|
actions.create_project(M.opts, args)
|
||||||
|
end
|
||||||
|
end, { nargs = "*", desc = "Create a new project" })
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("VernCreateFile", function(args)
|
||||||
|
if type(actions.create_file) == "function" then
|
||||||
|
actions.create_file(M.opts, args)
|
||||||
|
end
|
||||||
|
end, { nargs = "*", desc = "Creates a new file for project" })
|
||||||
|
|
||||||
|
--- Create group and attach based on ft
|
||||||
local group =
|
local group =
|
||||||
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
||||||
|
|
||||||
@@ -11,7 +40,11 @@ function M.setup(opts)
|
|||||||
group = group,
|
group = group,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
require("vern.attach").buf(args.buf, M.user_opts)
|
local ft = vim.bo[args.buf].filetype
|
||||||
|
local ok, attach = pcall(require, "vern.attach." .. ft)
|
||||||
|
if ok and type(attach) == "function" then
|
||||||
|
attach(args.buf, M.user_opts)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
desc = "Attach languages to buffer",
|
desc = "Attach languages to buffer",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local M = {}
|
|||||||
|
|
||||||
---@param opts table
|
---@param opts table
|
||||||
M.template = function(opts)
|
M.template = function(opts)
|
||||||
local base = [=[
|
local base = [=[
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
@@ -12,8 +12,8 @@ M.template = function(opts)
|
|||||||
.env.*
|
.env.*
|
||||||
|
|
||||||
]=]
|
]=]
|
||||||
local lang_block = {
|
local lang_block = {
|
||||||
python = [=[
|
python = [=[
|
||||||
__pycache__/
|
__pycache__/
|
||||||
build/
|
build/
|
||||||
dist/
|
dist/
|
||||||
@@ -22,10 +22,10 @@ env/
|
|||||||
venv/
|
venv/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
]=],
|
]=],
|
||||||
}
|
}
|
||||||
|
|
||||||
local extra = (opts and opts and lang_block[opts.lang]) or ""
|
local extra = (opts and opts and lang_block[opts.lang]) or ""
|
||||||
return base .. extra
|
return base .. extra
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
---@param opts table
|
|
||||||
M.template = function(opts)
|
|
||||||
local template = [=[
|
|
||||||
# %s
|
|
||||||
|
|
||||||
__all__: list[str] = []
|
|
||||||
]=]
|
|
||||||
return string.format(template, opts.project_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.main = function(opts)
|
||||||
|
local template = [=[
|
||||||
|
def main() -> None:
|
||||||
|
printf("Hello from %s!")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
]=]
|
||||||
|
return string.format(template, opts.project_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.__init__ = function(opts)
|
||||||
|
local template = [=[
|
||||||
|
# %s
|
||||||
|
|
||||||
|
__all__: list[str] = []
|
||||||
|
]=]
|
||||||
|
return string.format(template, opts.project_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.pyproject = function(opts)
|
||||||
|
local n = opts.project_name
|
||||||
|
local template = [=[
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "%s"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Project %s"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.10"
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
%s = "%s.main:main"
|
||||||
|
]=]
|
||||||
|
return string.format(template, n, n, n, n)
|
||||||
|
end
|
||||||
|
|
||||||
|
M.module = function(opts)
|
||||||
|
local template = [=[
|
||||||
|
"""
|
||||||
|
%s module
|
||||||
|
"""
|
||||||
|
]=]
|
||||||
|
return string.format(template, opts.project_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
---@param opts table
|
|
||||||
M.template = function(opts)
|
|
||||||
local template = [=[
|
|
||||||
def main() -> None:
|
|
||||||
printf("Hello from %s!")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
]=]
|
|
||||||
return string.format(template, opts.project_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
---@param opts table
|
|
||||||
M.template = function(opts)
|
|
||||||
local template = [=[
|
|
||||||
"""
|
|
||||||
%s module
|
|
||||||
"""
|
|
||||||
]=]
|
|
||||||
return string.format(template, opts.project_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
---@param opts table
|
|
||||||
M.template = function(opts)
|
|
||||||
local n = opts.project_name
|
|
||||||
local template = [=[
|
|
||||||
[build-system]
|
|
||||||
requires = ["hatchling"]
|
|
||||||
build-backend = "hatchling.build"
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "%s"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Project %s"
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.10"
|
|
||||||
dependencies = []
|
|
||||||
|
|
||||||
[project.scripts]
|
|
||||||
%s = "%s.main:main"
|
|
||||||
]=]
|
|
||||||
return string.format(template, n, n, n, n)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
Reference in New Issue
Block a user