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")
|
||||
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
|
||||
---@param opts? table Takes a table for the runtime
|
||||
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 {
|
||||
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 = {
|
||||
mode = "split",
|
||||
win = {
|
||||
|
||||
@@ -15,27 +15,27 @@ return {
|
||||
templates = {
|
||||
project = {
|
||||
["executable"] = {
|
||||
template = "vern.templates.python.main",
|
||||
template = { "vern.templates.python", "main" },
|
||||
target = "src/%s/main.py",
|
||||
},
|
||||
["init"] = {
|
||||
template = "vern.templates.python.__init__",
|
||||
template = { "vern.templates.python", "__init__" },
|
||||
target = "src/%s/__init__.py",
|
||||
},
|
||||
["manifest"] = {
|
||||
template = "vern.templates.python.pyproject",
|
||||
template = { "vern.templates.python", "pyproject" },
|
||||
target = "pyproject.toml",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
["module"] = {
|
||||
template = "vern.templates.python.module",
|
||||
template = { "vern.templates.python", "module" },
|
||||
target = "src/%s.py",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
["gitignore"] = {
|
||||
template = "vern.templates.extras.gitignore",
|
||||
template = "vern.templates.extras.gitignore", --- needs to call the function in file
|
||||
target = ".gitignore",
|
||||
},
|
||||
},
|
||||
|
||||
+37
-4
@@ -1,9 +1,38 @@
|
||||
local M = {}
|
||||
|
||||
M.user_opts = {}
|
||||
local global_opts = require("vern.configs.default")
|
||||
local actions = require("vern.actions")
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(opts)
|
||||
M.user_opts = opts or {}
|
||||
function M.setup(user_opts)
|
||||
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 =
|
||||
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
||||
|
||||
@@ -11,7 +40,11 @@ function M.setup(opts)
|
||||
group = group,
|
||||
pattern = "*",
|
||||
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,
|
||||
desc = "Attach languages to buffer",
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ local M = {}
|
||||
|
||||
---@param opts table
|
||||
M.template = function(opts)
|
||||
local base = [=[
|
||||
local base = [=[
|
||||
.DS_Store
|
||||
|
||||
.vscode/
|
||||
@@ -12,8 +12,8 @@ M.template = function(opts)
|
||||
.env.*
|
||||
|
||||
]=]
|
||||
local lang_block = {
|
||||
python = [=[
|
||||
local lang_block = {
|
||||
python = [=[
|
||||
__pycache__/
|
||||
build/
|
||||
dist/
|
||||
@@ -22,10 +22,10 @@ env/
|
||||
venv/
|
||||
.pytest_cache/
|
||||
]=],
|
||||
}
|
||||
}
|
||||
|
||||
local extra = (opts and opts and lang_block[opts.lang]) or ""
|
||||
return base .. extra
|
||||
local extra = (opts and opts and lang_block[opts.lang]) or ""
|
||||
return base .. extra
|
||||
end
|
||||
|
||||
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