chore(actions.create_project): now has a list over manually typing for
easier creation
This commit is contained in:
1 parent
adbd2bc0e9
commit
1c13c8cbe2
21 files changed
+409
-187
No files matched your search
@@ -6,24 +6,44 @@ local fs = require("vern-nvim.core.fs")
|
|||||||
---@module "vern-nvim.core.template"
|
---@module "vern-nvim.core.template"
|
||||||
local templates = require("vern-nvim.core.template")
|
local templates = require("vern-nvim.core.template")
|
||||||
|
|
||||||
|
---@module "vern-nvim.providers.web"
|
||||||
|
local providers = require("vern-nvim.providers.web")
|
||||||
|
|
||||||
---Imitate create_file so you can skip over and use for each filetype
|
---Imitate create_file so you can skip over and use for each filetype
|
||||||
|
|
||||||
M.create_project = function(opts)
|
M.create_project = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
vim.ui.input(
|
local ft = ""
|
||||||
{ prompt = "Project language (e.g. python): ", completion = "filetype" },
|
local items = {
|
||||||
function(ft)
|
"cpp",
|
||||||
ft = ft and vim.trim(ft)
|
"c",
|
||||||
if not ft or vim.trim(ft) == "" then
|
"rust",
|
||||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
"python",
|
||||||
title = "Vern Project",
|
"go",
|
||||||
})
|
"lua",
|
||||||
|
"java",
|
||||||
|
"web - not yet implemented",
|
||||||
|
}
|
||||||
|
vim.ui.select(items, {
|
||||||
|
prompt = "Select available language:",
|
||||||
|
format_item = function(item) return item end,
|
||||||
|
}, function(choice, _)
|
||||||
|
if choice then ft = vim.trim(choice) end
|
||||||
|
local ok, langs = pcall(require, "vern-nvim.langs." .. ft)
|
||||||
|
if not ok or type(langs) ~= "table" then
|
||||||
|
-- vim.notify("Empty or nil ft", vim.log.levels.WARN, {
|
||||||
|
-- title = "Vern Project",
|
||||||
|
-- })
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local ok, langs = pcall(require, "vern-nvim.langs." .. ft)
|
|
||||||
if not ok or type(langs) ~= "table" then return end
|
|
||||||
local args = vim.tbl_deep_extend("force", {}, langs, opts or {})
|
local args = vim.tbl_deep_extend("force", {}, langs, opts or {})
|
||||||
if not args[ft] or type(args[ft]) ~= "table" then return end
|
if not args[ft] or type(args[ft]) ~= "table" then return end
|
||||||
|
if ft == "web" then
|
||||||
|
if type(langs.create_project) == "function" then
|
||||||
|
langs.create_project()
|
||||||
|
end
|
||||||
|
return
|
||||||
|
else
|
||||||
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)
|
||||||
if not pname or pname == "" then return end
|
if not pname or pname == "" then return end
|
||||||
@@ -40,8 +60,6 @@ M.create_project = function(opts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vim.fn.mkdir(root, "p")
|
vim.fn.mkdir(root, "p")
|
||||||
|
|
||||||
local tpl = args[ft].templates or {}
|
|
||||||
local dirs = args[ft].dirs
|
local dirs = args[ft].dirs
|
||||||
if type(dirs) == "table" and next(dirs) then
|
if type(dirs) == "table" and next(dirs) then
|
||||||
for _, dir in pairs(dirs) do
|
for _, dir in pairs(dirs) do
|
||||||
@@ -52,56 +70,52 @@ M.create_project = function(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function write(tpl)
|
||||||
|
if type(tpl) == "table" and next(tpl) then
|
||||||
|
for _, tbl in pairs(tpl) do
|
||||||
|
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
|
||||||
|
local path = fs.fmt_path(raw_path, args[ft].dirs, ctx)
|
||||||
|
if tbl.enabled ~= false and tbl.kind then
|
||||||
|
local abs_file_path =
|
||||||
|
vim.fs.normalize(vim.fs.joinpath(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
|
||||||
|
fs.write(
|
||||||
|
abs_file_path,
|
||||||
|
templates.fetch(tbl.kind_path, tbl.kind, ctx)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local tpl = args[ft].templates or {}
|
||||||
|
|
||||||
local bin
|
local bin
|
||||||
local project = tpl.project
|
local project = tpl.project
|
||||||
if type(project) == "table" and next(project) then
|
if type(project) == "table" and next(project) then
|
||||||
for tbl_name, tbl in pairs(project) do
|
for tbl_name, tbl in pairs(project) do
|
||||||
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
|
|
||||||
local path = fs.fmt_path(raw_path, args[ft].dirs, ctx)
|
|
||||||
if tbl_name == "primary" then
|
if tbl_name == "primary" then
|
||||||
bin = vim.fs.joinpath(root, path)
|
bin = vim.fs.joinpath(
|
||||||
end
|
root,
|
||||||
if tbl.kind then
|
fs.fmt_path(
|
||||||
local abs_file_path =
|
vim.fs.joinpath(tbl.path, tbl.name),
|
||||||
vim.fs.normalize(vim.fs.joinpath(root, path))
|
args[ft].dirs,
|
||||||
local abs_dir_path = vim.fs.dirname(abs_file_path)
|
ctx
|
||||||
if
|
|
||||||
abs_dir_path ~= root
|
|
||||||
and not vim.startswith(root, abs_dir_path)
|
|
||||||
then
|
|
||||||
vim.fn.mkdir(abs_dir_path, "p")
|
|
||||||
end
|
|
||||||
fs.write(
|
|
||||||
abs_file_path,
|
|
||||||
templates.fetch(tbl.kind_path, tbl.kind, ctx)
|
|
||||||
)
|
)
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local extras = tpl.extras
|
|
||||||
if type(extras) == "table" and next(extras) then
|
|
||||||
for _, tbl in pairs(extras) do
|
|
||||||
if tbl.enabled ~= false and tbl.kind then
|
|
||||||
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
|
|
||||||
local path =
|
|
||||||
fs.fmt_path(raw_path, args[ft].dirs, ctx)
|
|
||||||
local abs_file_path =
|
|
||||||
vim.fs.normalize(vim.fs.joinpath(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
|
|
||||||
fs.write(
|
|
||||||
abs_file_path,
|
|
||||||
templates.fetch(tbl.kind_path, tbl.kind, ctx)
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
write(project)
|
||||||
|
write(tpl.extras)
|
||||||
|
|
||||||
if type(langs.create_project) == "function" then
|
if type(langs.create_project) == "function" then
|
||||||
langs.create_project(root)
|
langs.create_project(root)
|
||||||
end
|
end
|
||||||
@@ -131,7 +145,7 @@ M.create_project = function(opts)
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.create_file = function(opts)
|
M.create_file = function(opts)
|
||||||
@@ -139,19 +153,14 @@ M.create_file = function(opts)
|
|||||||
local filetype = vim.bo.filetype
|
local filetype = vim.bo.filetype
|
||||||
|
|
||||||
local ft_ok, config = pcall(require, "vern-nvim.langs." .. filetype)
|
local ft_ok, config = pcall(require, "vern-nvim.langs." .. filetype)
|
||||||
---@type VernCreateFile
|
if not filetype or filetype == "" or not ft_ok or type(config) ~= "table" then
|
||||||
if
|
|
||||||
not filetype
|
|
||||||
or filetype == ""
|
|
||||||
or not ft_ok
|
|
||||||
or type(config) ~= "table"
|
|
||||||
then
|
|
||||||
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
|
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
|
||||||
title = "Vern File",
|
title = "Vern File",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
local args = vim.tbl_deep_extend("force", {}, config, opts or {})
|
local args = vim.tbl_deep_extend("force", {}, config, opts or {})
|
||||||
|
---@type VernCreateFile
|
||||||
local cf = args.create_file
|
local cf = args.create_file
|
||||||
local function function_write(mod, fname)
|
local function function_write(mod, fname)
|
||||||
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
||||||
@@ -160,13 +169,9 @@ M.create_file = function(opts)
|
|||||||
company_name = args.env.author,
|
company_name = args.env.author,
|
||||||
file_name = fname,
|
file_name = fname,
|
||||||
}
|
}
|
||||||
local path =
|
local path = fs.fmt_path(raw_path, args[filetype].dirs or {}, context)
|
||||||
fs.fmt_path(raw_path, args[filetype].dirs or {}, context)
|
|
||||||
local full_path = vim.fs.joinpath(fs.root(), path)
|
local full_path = vim.fs.joinpath(fs.root(), path)
|
||||||
fs.write(
|
fs.write(full_path, templates.fetch(mod.kind_path, mod.kind, context))
|
||||||
full_path,
|
|
||||||
templates.fetch(mod.kind_path, mod.kind, context)
|
|
||||||
)
|
|
||||||
vim.cmd.edit(vim.fn.fnameescape(full_path))
|
vim.cmd.edit(vim.fn.fnameescape(full_path))
|
||||||
vim.notify(
|
vim.notify(
|
||||||
fname .. " has been created!",
|
fname .. " has been created!",
|
||||||
|
|||||||
@@ -10,24 +10,17 @@ M.compile = function(opts, build_cmd, run_cmd)
|
|||||||
vim.system({ "sh", "-c", build_cmd }, { text = true }, function(obj)
|
vim.system({ "sh", "-c", build_cmd }, { text = true }, function(obj)
|
||||||
if obj.code ~= 0 then
|
if obj.code ~= 0 then
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local error_obj = (obj.stderr ~= "" and obj.stderr)
|
local error_obj = (obj.stderr ~= "" and obj.stderr) or obj.stdout or ""
|
||||||
or obj.stdout
|
|
||||||
or ""
|
|
||||||
local error_lines = vim.list_extend(
|
local error_lines = vim.list_extend(
|
||||||
{ "Error During compilation" },
|
{ "Error During compilation" },
|
||||||
vim.split(error_obj, "\n", { trimempty = true })
|
vim.split(error_obj, "\n", { trimempty = true })
|
||||||
)
|
)
|
||||||
local buf, _ = term.open(
|
local buf, _ =
|
||||||
{ "echo 'compilation failed'" },
|
term.open({ "echo 'compilation failed'" }, opts.terminal, true)
|
||||||
opts.terminal,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
term.set_lines(buf, error_lines)
|
term.set_lines(buf, error_lines)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
vim.schedule(
|
vim.schedule(function() term.open({ run_cmd }, opts.terminal, false) end)
|
||||||
function() term.open({ run_cmd }, opts.terminal, false) end
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function M.write(path, content)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
function M.name() return vim.fs.basename(M.proj_root()) or "" end
|
function M.name() return vim.fs.basename(M.root()) or "" end
|
||||||
|
|
||||||
---@param bufnr? integer Default is 0 (current buffer)
|
---@param bufnr? integer Default is 0 (current buffer)
|
||||||
---@return string
|
---@return string
|
||||||
|
|||||||
@@ -12,13 +12,9 @@ local registers = {
|
|||||||
---@return string Content Formatted string
|
---@return string Content Formatted string
|
||||||
function M.fetch(kind_path, kind, context)
|
function M.fetch(kind_path, kind, context)
|
||||||
kind, context = kind or "", context or {}
|
kind, context = kind or "", context or {}
|
||||||
if not kind or kind == "" then
|
if not kind or kind == "" then return "" end
|
||||||
return ""
|
|
||||||
end
|
|
||||||
local ok, mod = pcall(require, kind_path)
|
local ok, mod = pcall(require, kind_path)
|
||||||
if not ok or type(mod) ~= "table" or not mod[kind] then
|
if not ok or type(mod) ~= "table" or not mod[kind] then return "" end
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local template = mod[kind] or ""
|
local template = mod[kind] or ""
|
||||||
context = context or {}
|
context = context or {}
|
||||||
@@ -26,9 +22,7 @@ function M.fetch(kind_path, kind, context)
|
|||||||
if ok and type(mod) == "table" then
|
if ok and type(mod) == "table" then
|
||||||
for key, placeholder in pairs(registers) do
|
for key, placeholder in pairs(registers) do
|
||||||
local value = context[key]
|
local value = context[key]
|
||||||
if value then
|
if value then template = string.gsub(template, placeholder, value) end
|
||||||
template = string.gsub(template, placeholder, value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return template
|
return template
|
||||||
|
|||||||
+2
-12
@@ -6,11 +6,6 @@ local defaults = require("vern-nvim.config.defaults")
|
|||||||
---@type VernCoreConfig
|
---@type VernCoreConfig
|
||||||
M.opts = vim.deepcopy(defaults)
|
M.opts = vim.deepcopy(defaults)
|
||||||
|
|
||||||
---@class VernUserConfig
|
|
||||||
---@field workspace_root? string
|
|
||||||
---@field keybinds? table<string, VernKeybindItem>
|
|
||||||
---@field terminal? VernTerminalConfig | table
|
|
||||||
|
|
||||||
---@param user_opts? VernUserConfig
|
---@param user_opts? VernUserConfig
|
||||||
function M.setup(user_opts)
|
function M.setup(user_opts)
|
||||||
---@type VernCoreConfig
|
---@type VernCoreConfig
|
||||||
@@ -51,16 +46,11 @@ function M.setup(user_opts)
|
|||||||
function() def.action(opts) end,
|
function() def.action(opts) end,
|
||||||
{ nargs = "*", desc = def.desc }
|
{ nargs = "*", desc = def.desc }
|
||||||
)
|
)
|
||||||
vim.keymap.set(
|
vim.keymap.set("n", key, function() def.action(opts) end, {
|
||||||
"n",
|
|
||||||
key,
|
|
||||||
function() def.action(opts) end,
|
|
||||||
{
|
|
||||||
buffer = args.buf,
|
buffer = args.buf,
|
||||||
silent = true,
|
silent = true,
|
||||||
desc = def.desc,
|
desc = def.desc,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@module "vern-nvim.core.fs"
|
---@module "vern-nvim.core.fs"
|
||||||
local fs = require("vern-nvim.fs")
|
local fs = require("vern-nvim.core.fs")
|
||||||
|
|
||||||
---@module "vern-nvim.core.compile"
|
---@module "vern-nvim.core.compile"
|
||||||
local comp = require("vern-nvim.core.compile")
|
local comp = require("vern-nvim.core.compile")
|
||||||
@@ -36,7 +36,7 @@ end
|
|||||||
M.run = function(opts)
|
M.run = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local build_dir = vim.fn.fnameescape((fs.root() or ".") .. "/build")
|
local build_dir = vim.fn.fnameescape(fs.root() .. "/build")
|
||||||
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
||||||
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ end
|
|||||||
M.run = function(opts)
|
M.run = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local build_dir = vim.fn.fnameescape((fs.root() or ".") .. "/build")
|
local build_dir = vim.fn.fnameescape(fs.root() .. "/build")
|
||||||
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
||||||
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
---@module "vern-nvim.core.fs"
|
||||||
|
local fs = require("vern-nvim.core.fs")
|
||||||
|
|
||||||
|
---@module "vern-nvim.core.terminal"
|
||||||
|
local term = require("vern-nvim.core.terminal")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.attach = nil
|
||||||
|
|
||||||
|
M.create_project = function(root)
|
||||||
|
local obj = vim
|
||||||
|
.system({
|
||||||
|
"go",
|
||||||
|
"mod",
|
||||||
|
"init",
|
||||||
|
"com.DarthMooMancer." .. vim.fs.basename(root),
|
||||||
|
})
|
||||||
|
:wait()
|
||||||
|
if obj.code ~= 0 then
|
||||||
|
vim.notify(
|
||||||
|
"Go init failed" .. obj.stderr,
|
||||||
|
vim.log.levels.ERROR,
|
||||||
|
{ title = "Vern Go" }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type VernCreateFile
|
||||||
|
M.create_file = nil
|
||||||
|
|
||||||
|
---@param opts VernPythonConfig Takes a table for the runtime
|
||||||
|
M.run = function(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
local root = fs.root()
|
||||||
|
-- local context = {
|
||||||
|
-- project_name = fs.name(),
|
||||||
|
-- company_name = opts.env.author,
|
||||||
|
-- file_name = "",
|
||||||
|
-- }
|
||||||
|
-- local bin = vim.tbl_get(opts.python.templates.project.primary)
|
||||||
|
--
|
||||||
|
-- local exe = vim.fs.joinpath(bin.path, bin.name)
|
||||||
|
-- local exe_path = fs.fmt_path(exe, opts.python.dirs, context)
|
||||||
|
-- local full_path = vim.fs.joinpath(vim.fn.expand(root), exe_path)
|
||||||
|
|
||||||
|
term.open({ "go run ", root .. "/main.go" }, opts.terminal or {}, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type VernLanguageConfig
|
||||||
|
M.go = {
|
||||||
|
root = "Go",
|
||||||
|
dirs = {
|
||||||
|
src = "",
|
||||||
|
},
|
||||||
|
keybinds = nil,
|
||||||
|
templates = {
|
||||||
|
project = {
|
||||||
|
primary = {
|
||||||
|
path = "{dirs.src}",
|
||||||
|
name = "main.go",
|
||||||
|
kind = "main",
|
||||||
|
kind_path = "vern-nvim.templates.go",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
file = {
|
||||||
|
source = {
|
||||||
|
path = "{dirs.src}",
|
||||||
|
name = "{file_name}.go",
|
||||||
|
kind = "module",
|
||||||
|
kind_path = "vern-nvim.templates.go",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extras = nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return M
|
||||||
@@ -18,7 +18,7 @@ M.run = function(opts)
|
|||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local root = fs.root()
|
local root = fs.root()
|
||||||
local context = {
|
local context = {
|
||||||
project_name = fs.name()(),
|
project_name = fs.name(),
|
||||||
company_name = opts.env.author,
|
company_name = opts.env.author,
|
||||||
file_name = "",
|
file_name = "",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@module "vern-nvim.core.fs"
|
---@module "vern-nvim.core.fs"
|
||||||
local fs = require("vern-nvim.fs")
|
local fs = require("vern-nvim.core.fs")
|
||||||
|
|
||||||
---@module "vern-nvim.core.terminal"
|
---@module "vern-nvim.core.terminal"
|
||||||
local term = require("vern-nvim.core.terminal")
|
local term = require("vern-nvim.core.terminal")
|
||||||
@@ -34,7 +34,7 @@ M.lua = {
|
|||||||
primary = {
|
primary = {
|
||||||
path = "{dirs.src}",
|
path = "{dirs.src}",
|
||||||
name = "init.lua",
|
name = "init.lua",
|
||||||
kind = "init",
|
kind = "main",
|
||||||
kind_path = "vern-nvim.templates.lua",
|
kind_path = "vern-nvim.templates.lua",
|
||||||
},
|
},
|
||||||
style = {
|
style = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@module "vern-nvim.core.fs"
|
---@module "vern-nvim.core.fs"
|
||||||
local fs = require("vern-nvim.fs")
|
local fs = require("vern-nvim.core.fs")
|
||||||
|
|
||||||
---@module "vern-nvim.core.terminal"
|
---@module "vern-nvim.core.terminal"
|
||||||
local term = require("vern-nvim.core.terminal")
|
local term = require("vern-nvim.core.terminal")
|
||||||
@@ -39,16 +39,15 @@ M.create_file = nil
|
|||||||
---@param opts VernPythonConfig Takes a table for the runtime
|
---@param opts VernPythonConfig Takes a table for the runtime
|
||||||
M.run = function(opts)
|
M.run = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local root = fs.root() or "."
|
local root = fs.root()
|
||||||
local context = {
|
local context = {
|
||||||
project_name = fs.name(),
|
project_name = fs.name(),
|
||||||
company_name = opts.env.author,
|
company_name = opts.env.author,
|
||||||
file_name = "",
|
file_name = "",
|
||||||
}
|
}
|
||||||
local bin = opts.python.templates.project.primary
|
local bin = vim.tbl_get(opts.python.templates.project.primary)
|
||||||
|
|
||||||
local exe = vim.fs.joinpath(bin.path, bin.name)
|
local exe = vim.fs.joinpath(bin.path, bin.name)
|
||||||
or "src/{project_name}/main.py"
|
|
||||||
local exe_path = fs.fmt_path(exe, opts.python.dirs, context)
|
local exe_path = fs.fmt_path(exe, opts.python.dirs, context)
|
||||||
local full_path = vim.fs.joinpath(vim.fn.expand(root), exe_path)
|
local full_path = vim.fs.joinpath(vim.fn.expand(root), exe_path)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---@module "vern-nvim.core.fs"
|
---@module "vern-nvim.core.fs"
|
||||||
local fs = require("vern-nvim.fs")
|
local fs = require("vern-nvim.core.fs")
|
||||||
|
|
||||||
---@module "vern-nvim.core.terminal"
|
---@module "vern-nvim.core.terminal"
|
||||||
local term = require("vern-nvim.core.terminal")
|
local term = require("vern-nvim.core.terminal")
|
||||||
@@ -9,13 +9,15 @@ local M = {}
|
|||||||
M.attach = nil
|
M.attach = nil
|
||||||
|
|
||||||
M.create_project = function(root)
|
M.create_project = function(root)
|
||||||
local obj = vim.system({
|
local obj = vim
|
||||||
|
.system({
|
||||||
"cargo",
|
"cargo",
|
||||||
"init",
|
"init",
|
||||||
vim.fn.expand(root),
|
vim.fn.expand(root),
|
||||||
"--name",
|
"--name",
|
||||||
vim.fs.basename(root),
|
vim.fs.basename(root),
|
||||||
}):wait()
|
})
|
||||||
|
:wait()
|
||||||
|
|
||||||
if obj.code ~= 0 then
|
if obj.code ~= 0 then
|
||||||
vim.notify("Cargo init failed:" .. obj.stderr, vim.log.levels.ERROR)
|
vim.notify("Cargo init failed:" .. obj.stderr, vim.log.levels.ERROR)
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
---@module "vern-nvim.core.fs"
|
||||||
|
local fs = require("vern-nvim.core.fs")
|
||||||
|
|
||||||
|
---@module "vern-nvim.core.terminal"
|
||||||
|
local term = require("vern-nvim.core.terminal")
|
||||||
|
|
||||||
|
---@module "vern-nvim.providers.web"
|
||||||
|
local providers = require("vern-nvim.providers.web")
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.attach = nil
|
||||||
|
|
||||||
|
M.create_project = function(opts, continue)
|
||||||
|
opts = opts or {}
|
||||||
|
local provider = vim.tbl_get(opts, "web", "providers")
|
||||||
|
if vim.trim(provider) == "bun" then
|
||||||
|
local items = { "Vanilla", "Tailwind", "Shadcn" }
|
||||||
|
vim.ui.select(items, {
|
||||||
|
prompt = "Select scaffold from Bun:",
|
||||||
|
format_item = function(item) return item end,
|
||||||
|
}, function(choice, _)
|
||||||
|
if choice then return continue(choice) end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type VernCreateFile
|
||||||
|
M.create_file = nil
|
||||||
|
|
||||||
|
---@param opts VernWebConfig Takes a table for the runtime
|
||||||
|
M.run = function(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
|
||||||
|
-- term.open({
|
||||||
|
-- "lua " .. vim.fs.joinpath(fs.root(), "lua", fs.name(), "/init.lua"),
|
||||||
|
-- }, opts.terminal or {}, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type VernLanguageConfig
|
||||||
|
M.web = {
|
||||||
|
root = "Web",
|
||||||
|
dirs = nil,
|
||||||
|
providers = "bun", --- "bun"|"deno"|"vanilla"
|
||||||
|
keybinds = nil,
|
||||||
|
templates = {
|
||||||
|
project = nil,
|
||||||
|
file = {
|
||||||
|
source = {
|
||||||
|
path = "{dirs.src}",
|
||||||
|
name = "{file_name}.lua",
|
||||||
|
kind = "source",
|
||||||
|
kind_path = "vern-nvim.templates.lua",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extras = nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
--- Providers for bun
|
||||||
|
---
|
||||||
|
|
||||||
|
--[[ React
|
||||||
|
|
||||||
|
--react
|
||||||
|
--react=tailwind
|
||||||
|
--react=shadcn
|
||||||
|
|
||||||
|
--]]
|
||||||
Whitespace-only changes.
@@ -1,8 +1,8 @@
|
|||||||
return {
|
return {
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
TEMPLATE: MAIN (Entrypoint)
|
template: main (entrypoint)
|
||||||
File: main.c
|
file: main.c
|
||||||
Target: src/main.c
|
target: src/main.c
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
main = vim.trim([=[
|
main = vim.trim([=[
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -10,106 +10,106 @@ return {
|
|||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
char* str = "Hello World";
|
char* str = "hello world";
|
||||||
printf("%s\n", str);
|
printf("%s\n", str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
TEMPLATE: CLANG-FORMAT (Code formatter)
|
template: clang-format (code formatter)
|
||||||
File: .clang-format
|
file: .clang-format
|
||||||
Target: .clang-format
|
target: .clang-format
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
format = vim.trim([=[
|
format = vim.trim([=[
|
||||||
---
|
---
|
||||||
BasedOnStyle: Google
|
basedonstyle: google
|
||||||
Standard: Latest
|
standard: latest
|
||||||
UseTab: Always
|
usetab: always
|
||||||
TabWidth: 8
|
tabwidth: 8
|
||||||
IndentWidth: 8
|
indentwidth: 8
|
||||||
BreakBeforeBraces: Allman
|
breakbeforebraces: allman
|
||||||
SpaceBeforeCpp11BracedList: true
|
spacebeforecpp11bracedlist: true
|
||||||
SeparateDefinitionBlocks: Always
|
separatedefinitionblocks: always
|
||||||
Cpp11BracedListStyle: false
|
cpp11bracedliststyle: false
|
||||||
BreakAfterReturnType: TopLevel
|
breakafterreturntype: toplevel
|
||||||
ReflowComments: Always
|
reflowcomments: always
|
||||||
AllowShortFunctionsOnASingleLine: All
|
allowshortfunctionsonasingleline: all
|
||||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
allowshortifstatementsonasingleline: allifsandelse
|
||||||
AllowShortLoopsOnASingleLine: true
|
allowshortloopsonasingleline: true
|
||||||
IndentAccessModifiers: false # Indent access specifiers by one level
|
indentaccessmodifiers: false # indent access specifiers by one level
|
||||||
AccessModifierOffset: -4 # Optional: adjust offset relative to the class indentation level
|
accessmodifieroffset: -4 # optional: adjust offset relative to the class indentation level
|
||||||
IndentGotoLabels: InnerIndent
|
indentgotolabels: innerindent
|
||||||
DerivePointerAlignment: false
|
derivepointeralignment: false
|
||||||
PointerAlignment: Left
|
pointeralignment: left
|
||||||
IndentPPDirectives: AfterHash
|
indentppdirectives: afterhash
|
||||||
SortIncludes: CaseSensitive
|
sortincludes: casesensitive
|
||||||
IncludeBlocks: Preserve
|
includeblocks: preserve
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
TEMPLATE: CMAKELISTS (Spec / Build Manifest)
|
template: cmakelists (spec / build manifest)
|
||||||
File: CMakeLists.txt
|
file: cmakelists.txt
|
||||||
Target: CMakeLists.txt
|
target: cmakelists.txt
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
CmakeLists = vim.trim([=[
|
cmakelists = vim.trim([=[
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(version 3.16)
|
||||||
project(__PROJECT_NAME__ LANGUAGES C)
|
project(__project_name__ languages c)
|
||||||
set(CMAKE_C_STANDARD 23)
|
set(cmake_c_standard 23)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
set(cmake_c_standard_required on)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(cmake_export_compile_commands on)
|
||||||
|
|
||||||
set(LIB_SOURCES
|
set(lib_sources
|
||||||
# Add your other types here as you implement them:
|
# add your other types here as you implement them:
|
||||||
# src/example1.c
|
# src/example1.c
|
||||||
# src/example2.c
|
# src/example2.c
|
||||||
)
|
)
|
||||||
|
|
||||||
if(LIB_SOURCES)
|
if(lib_sources)
|
||||||
add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES})
|
add_library(__project_name__ static ${lib_sources})
|
||||||
target_include_directories(__PROJECT_NAME__
|
target_include_directories(__project_name__
|
||||||
PUBLIC
|
public
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
${cmake_current_source_dir}/include
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(__PROJECT_NAME___bin src/main.c)
|
add_executable(__project_name___bin src/main.c)
|
||||||
set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__")
|
set_target_properties(__project_name___bin properties output_name "__project_name__")
|
||||||
|
|
||||||
if(TARGET __PROJECT_NAME__)
|
if(target __project_name__)
|
||||||
target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__)
|
target_link_libraries(__project_name___bin private __project_name__)
|
||||||
endif()
|
endif()
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
TEMPLATE: HEADER (Standalone File)
|
template: header (standalone file)
|
||||||
File: {name}.h
|
file: {name}.h
|
||||||
Target: include/{project_name}/{name}.h
|
target: include/{project_name}/{name}.h
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
header = vim.trim([=[
|
header = vim.trim([=[
|
||||||
#ifndef __FILE_NAME___H
|
#ifndef __file_name___h
|
||||||
#define __FILE_NAME___H
|
#define __file_name___h
|
||||||
|
|
||||||
// Code
|
// code
|
||||||
|
|
||||||
#endif /* __FILE_NAME___H */
|
#endif /* __file_name___h */
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
TEMPLATE: SOURCE (Standalone File)
|
template: source (standalone file)
|
||||||
File: {name}.c
|
file: {name}.c
|
||||||
Target: src/{name}.c
|
target: src/{name}.c
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
source = vim.trim([=[
|
source = vim.trim([=[
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
|
|
||||||
--[[ =====================================================================
|
--[[ =====================================================================
|
||||||
TEMPLATE: CLANG_TIDY (LINTER)
|
template: clang_tidy (linter)
|
||||||
File: .clang-tidy
|
file: .clang-tidy
|
||||||
Target: .clang-tidy
|
target: .clang-tidy
|
||||||
===================================================================== --]]
|
===================================================================== --]]
|
||||||
linter = vim.trim([=[
|
linter = vim.trim([=[
|
||||||
Checks: >
|
checks: >
|
||||||
-*,
|
-*,
|
||||||
clang-analyzer-*,
|
clang-analyzer-*,
|
||||||
bugprone-*,
|
bugprone-*,
|
||||||
@@ -126,12 +126,12 @@ Checks: >
|
|||||||
|
|
||||||
-bugprone-narrowing-conversions,
|
-bugprone-narrowing-conversions,
|
||||||
-readability-identifier-length
|
-readability-identifier-length
|
||||||
CheckOptions:
|
checkoptions:
|
||||||
readability-identifier-naming.VariableCase: lower_case
|
readability-identifier-naming.variablecase: lower_case
|
||||||
readability-identifier-naming.FunctionCase: lower_case
|
readability-identifier-naming.functioncase: lower_case
|
||||||
readability-identifier-naming.StructCase: lower_case
|
readability-identifier-naming.structcase: lower_case
|
||||||
readability-identifier-naming.EnumCase: CamelCase
|
readability-identifier-naming.enumcase: camelcase
|
||||||
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
readability-identifier-naming.enumconstantcase: upper_case
|
||||||
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
|
readability-identifier-naming.macrodefinitioncase: upper_case
|
||||||
]=]) .. "\n",
|
]=]) .. "\n",
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
return {
|
||||||
|
--[[ =====================================================================
|
||||||
|
template: main (entrypoint)
|
||||||
|
file: main.go
|
||||||
|
target: main.go
|
||||||
|
===================================================================== --]]
|
||||||
|
main = vim.trim([=[
|
||||||
|
package main
|
||||||
|
|
||||||
|
import ("fmt")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Hello World")
|
||||||
|
}
|
||||||
|
]=]) .. "\n",
|
||||||
|
|
||||||
|
--[[ =====================================================================
|
||||||
|
template: source (standalone file)
|
||||||
|
file: {name}.go
|
||||||
|
target: {name}.go
|
||||||
|
===================================================================== --]]
|
||||||
|
--- Add boilder plate
|
||||||
|
source = vim.trim([=[
|
||||||
|
]=]) .. "\n",
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
return {
|
||||||
|
--[[ =====================================================================
|
||||||
|
template: main (entrypoint)
|
||||||
|
file: init.lua
|
||||||
|
target: lua/init.lua
|
||||||
|
===================================================================== --]]
|
||||||
|
main = vim.trim([=[
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param opts? table
|
||||||
|
function M.setup(opts)
|
||||||
|
M.opts = opts or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
]=]) .. "\n",
|
||||||
|
|
||||||
|
--[[ =====================================================================
|
||||||
|
template: stylua (code formatter)
|
||||||
|
file: stylua.toml
|
||||||
|
target: stylua.toml
|
||||||
|
===================================================================== --]]
|
||||||
|
format = vim.trim([=[
|
||||||
|
# stylua.toml
|
||||||
|
|
||||||
|
# How many characters per line before wrapping
|
||||||
|
column_width = 80
|
||||||
|
|
||||||
|
# Indentation style: "Tabs" or "Spaces"
|
||||||
|
line_endings = "Unix"
|
||||||
|
indent_type = "Spaces"
|
||||||
|
indent_width = 4
|
||||||
|
|
||||||
|
# Quote styling: "AutoPreferDouble", "AutoPreferSingle", "ForceDouble", "ForceSingle"
|
||||||
|
quote_style = "AutoPreferDouble"
|
||||||
|
|
||||||
|
# Call parentheses: "Always", "NoSingleString", "None", "Input"
|
||||||
|
# "None" removes parens when a single string/table literal is passed: fn "arg" / fn { ... }
|
||||||
|
# "Always" keeps them strictly standard: fn("arg") / fn({ ... })
|
||||||
|
call_parentheses = "Always"
|
||||||
|
|
||||||
|
# Sorting and formatting behavior
|
||||||
|
# collapse_simple_statement = "Never"
|
||||||
|
collapse_simple_statement = "Always"
|
||||||
|
|
||||||
|
]=]) .. "\n",
|
||||||
|
|
||||||
|
--[[ =====================================================================
|
||||||
|
template: source (standalone file)
|
||||||
|
file: {name}.lua
|
||||||
|
target: lua/{name}.lua
|
||||||
|
===================================================================== --]]
|
||||||
|
source = vim.trim([=[
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
return M
|
||||||
|
]=]) .. "\n",
|
||||||
|
}
|
||||||
+12
-5
@@ -2,13 +2,17 @@
|
|||||||
---@alias SplitDirection "vertical" | "horizontal"
|
---@alias SplitDirection "vertical" | "horizontal"
|
||||||
---@alias SplitAnchorType "right" | "bottom"
|
---@alias SplitAnchorType "right" | "bottom"
|
||||||
|
|
||||||
---@class VernCreateFile
|
---@alias VernCreateFile fun(opts: any, continue: fun(mod: VernFileLayout|nil))
|
||||||
---@field func? fun(opts: any, continue: fun(mod: VernFileLayout|nil)): any?
|
|
||||||
|
---@class VernUserConfig
|
||||||
|
---@field workspace_root? string
|
||||||
|
---@field keybinds? table<string, VernKeybindItem>
|
||||||
|
---@field terminal? VernTerminalConfig | table
|
||||||
|
|
||||||
---@class VernKeybindItem
|
---@class VernKeybindItem
|
||||||
---@field user_command string
|
---@field user_command string
|
||||||
---@field desc string
|
---@field desc string
|
||||||
---@field action function
|
---@field action fun(opts: VernCoreConfig)
|
||||||
|
|
||||||
---@class VernFloatWindowConfig
|
---@class VernFloatWindowConfig
|
||||||
---@field padding { left: integer, right: integer, top: integer, bottom: integer }
|
---@field padding { left: integer, right: integer, top: integer, bottom: integer }
|
||||||
@@ -46,7 +50,7 @@
|
|||||||
---@field kind_path? string
|
---@field kind_path? string
|
||||||
|
|
||||||
---@class VernExtrasLayout : VernFileLayout
|
---@class VernExtrasLayout : VernFileLayout
|
||||||
---@field enabled boolean
|
---@field enabled? boolean
|
||||||
|
|
||||||
---@class VernLanguageTemplates
|
---@class VernLanguageTemplates
|
||||||
---@field project table<string, VernFileLayout>|nil
|
---@field project table<string, VernFileLayout>|nil
|
||||||
@@ -70,9 +74,12 @@
|
|||||||
|
|
||||||
---@class VernLuaConfig : VernCoreConfig
|
---@class VernLuaConfig : VernCoreConfig
|
||||||
---@field lua? VernLanguageConfig
|
---@field lua? VernLanguageConfig
|
||||||
---
|
|
||||||
---@class VernJavaConfig : VernCoreConfig
|
---@class VernJavaConfig : VernCoreConfig
|
||||||
---@field java? VernLanguageConfig
|
---@field java? VernLanguageConfig
|
||||||
|
|
||||||
---@class VernRustConfig : VernCoreConfig
|
---@class VernRustConfig : VernCoreConfig
|
||||||
---@field rust? VernLanguageConfig
|
---@field rust? VernLanguageConfig
|
||||||
|
|
||||||
|
---@class VernWebConfig : VernCoreConfig
|
||||||
|
---@field web? VernLanguageConfig
|
||||||
+1
-1
@@ -6,7 +6,7 @@ column_width = 80
|
|||||||
# Indentation style: "Tabs" or "Spaces"
|
# Indentation style: "Tabs" or "Spaces"
|
||||||
line_endings = "Unix"
|
line_endings = "Unix"
|
||||||
indent_type = "Spaces"
|
indent_type = "Spaces"
|
||||||
indent_width = 4
|
indent_width = 2
|
||||||
|
|
||||||
# Quote styling: "AutoPreferDouble", "AutoPreferSingle", "ForceDouble", "ForceSingle"
|
# Quote styling: "AutoPreferDouble", "AutoPreferSingle", "ForceDouble", "ForceSingle"
|
||||||
quote_style = "AutoPreferDouble"
|
quote_style = "AutoPreferDouble"
|
||||||
|
|||||||
Reference in new issue
Block a user