Compare commits
17
Commits
774f14809d
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
421cf95bc6 | ||
|
|
1c13c8cbe2 | ||
|
|
adbd2bc0e9 | ||
|
|
15f3648af8 | ||
|
|
51e911ec33 | ||
|
|
1b5d413404 | ||
|
|
ae0df7fe28 | ||
|
|
08967f9070 | ||
|
|
9a6eb90efc | ||
|
|
72951f7327 | ||
|
|
4765da0539 | ||
|
|
9f4649b5d2 | ||
|
|
e8c55ec18f | ||
|
|
fcde51bc05 | ||
|
|
9eefdb6166 | ||
|
|
3046a3ce36 | ||
|
|
5eaa7d10a7 |
No files matched your search
@@ -1,54 +1,54 @@
|
||||
<h1 align="center">Vern.nvim</h1>
|
||||
<h1 align="center">Vern-nvim</h1>
|
||||
|
||||
<p align="center"><em>Vern.nvim or Vernacular.nvim is a multi lingual project manager. It creates new projects and files from templates, builds and runs code and can run language specific functions within Neovim</em></p>
|
||||
<p align="left">Vern-nvim (aka Vernacular-nvim) is a multilingual project scaffolder with a bunch of extra add-ons. It creates new projects, new files based on buffer filetype, runs projects and builds if needed and more.</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/Lua-1e90ff?style=for-the-badge&logo=lua&logoColor=white" />
|
||||
<img src="https://img.shields.io/badge/Neovim-0.10%2B-32c48d?style=for-the-badge&logo=neovim&logoColor=white" />
|
||||
<img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge" />
|
||||
<!-- <img src="https://img.shields.io/badge/Docs-Available-blue?style=for-the-badge&logo=readthedocs&logoColor=white" /> -->
|
||||
</p>
|
||||
> [!WARNING]
|
||||
> Vern-nvim is only tested on vim.pack as of right now.
|
||||
> Meaning it may not work well with lazy.nvim or any other package manager
|
||||
|
||||
|
||||
NOTE: The plugin may not work well with lazy or any other package manager other than vim.pack. I dont understand enough about nvim api and lua to handle these other things right now
|
||||
|
||||
> [!NOTE]
|
||||
> This is solely a passion project to improve my own workflow meaning that the plugin is very opinionated. If it were to ever pickup traction, I would love it if people could suggest larger changes that allowed this to be an even better neovim project scaffold
|
||||
|
||||
## Features
|
||||
|
||||
* Create projects directly from Neovim
|
||||
* Generate new files quickly
|
||||
* Build your code with customizable build systems
|
||||
* Run programs without leaving the editor
|
||||
* Integrated terminal for flexible command execution
|
||||
* Minimal configuration with extensibility in mind
|
||||
* Works out of the box with no additional configuration needed
|
||||
* Extensibility towards custom templates.
|
||||
* Custom commands
|
||||
* Builtin terminal for viewing code !(scratchpad in future)
|
||||
* !(Future) Allows for custom providers for languages and custom commands
|
||||
|
||||
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern-nvim.nvim/wiki/Home$0) for setup, configuration, and usage details.
|
||||
> All features and configs are documented here [Future Documentation](https://vern-nvim.moomancer.xyz/docs) (lies, it will be here one day)
|
||||
|
||||
## Supported Languages
|
||||
|
||||
Vern.nvim currently supports the following languages:
|
||||
Vern-nvim currently supports the following languages:
|
||||
|
||||
* Python
|
||||
* C / C++
|
||||
<!-- * Java -->
|
||||
<!-- * Lua -->
|
||||
<!-- * Rust -->
|
||||
<!-- * HTML -->
|
||||
* Lua
|
||||
* Java
|
||||
* Rust
|
||||
|
||||
Additional language support is planned for future releases.
|
||||
|
||||
- Web based languages (HTML, CSS, JS/TS), these will be scaffolded by deno, bun, etc
|
||||
- Other languages I am interested in
|
||||
|
||||
|
||||
## Roadmap
|
||||
|
||||
Current focus:
|
||||
* **Refactoring and internal cleanup.**
|
||||
- [ ] Refactoring and internal cleanup from v1.
|
||||
- [ ] Implement scratchpad functionality
|
||||
- [ ] Impleemtn custom provider support
|
||||
- [ ] Keybinds for specific languages to rebuild (c/c++/java/rust) (Part 1)
|
||||
- [ ] Adding language specific keybinds for extra information or convienence (Part 2)
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome and appreciated.
|
||||
Contributions are welcome and appreciated!
|
||||
|
||||
* Open an issue for bug reports, questions, or feature requests.
|
||||
* Submit a pull request if you'd like to contribute directly.
|
||||
|
||||
If you have an idea or use case you'd like to see supported, let’s discuss it.
|
||||
Your feedback and contributions are key to making Vern.nvim even better! Thank you for being part of the journey. 🙏
|
||||
Thank you for checking out Vern-nvim!
|
||||
@@ -1,106 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
local templates = require("vern-nvim.templates")
|
||||
local action_utils = require("vern-nvim.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
---@param opts VernCConfig
|
||||
function M.create_project(opts)
|
||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||
pname = pname and vim.trim(pname)
|
||||
if not pname or pname == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local configs = require("vern-nvim.configs.c")
|
||||
|
||||
---@type VernCConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.c.root, pname)
|
||||
local bin = action_utils.create(cfg.c, pname, root)
|
||||
|
||||
local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build"
|
||||
local _ = vim.system({ "sh", "-c", build_cmd }):wait()
|
||||
|
||||
utils.init_git(root, "c")
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
function M.create_file(opts)
|
||||
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or ft == "" then
|
||||
return
|
||||
end
|
||||
local configs = require("vern-nvim.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 path = utils.resolve_path(raw_path, cfg.c.dirs or {}, context)
|
||||
local abs_file_path = vim.fs.normalize(join(root, 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
|
||||
|
||||
---@param opts? VernCConfig Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
|
||||
local build_dir = root .. "/build"
|
||||
local build_cmd = "cd " .. build_dir .. " && cmake --build ."
|
||||
|
||||
vim.system({ "sh", "-c", build_cmd }, { text = true }, function(obj)
|
||||
if obj.code ~= 0 then
|
||||
vim.schedule(function()
|
||||
local error_obj = (obj.stderr ~= "" and obj.stderr) or obj.stdout or ""
|
||||
local error_lines = vim.list_extend(
|
||||
{ "Error During compilation" },
|
||||
vim.split(error_obj, "\n", { trimempty = true })
|
||||
)
|
||||
local buf, _ = utils.term({ "echo 'compilation failed'" }, opts.terminal, true)
|
||||
if buf and vim.api.nvim_buf_is_valid(buf) then
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = buf })
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, error_lines)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
|
||||
end
|
||||
end)
|
||||
else
|
||||
vim.schedule(function()
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. pname
|
||||
utils.term({ run_cmd }, opts.terminal, false)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,107 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
local templates = require("vern-nvim.templates")
|
||||
local action_utils = require("vern-nvim.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
---@param opts VernCPPConfig
|
||||
function M.create_project(opts)
|
||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||
pname = pname and vim.trim(pname)
|
||||
if not pname or pname == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local configs = require("vern-nvim.configs.cpp")
|
||||
|
||||
---@type VernCPPConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.cpp.root, pname)
|
||||
local bin = action_utils.create(cfg.cpp, pname, root)
|
||||
|
||||
local build_cmd = "cd " .. root .. " && cmake -S . -B build && cmake --build build"
|
||||
local _ = vim.system({ "sh", "-c", build_cmd }):wait()
|
||||
|
||||
utils.init_git(root, "cpp")
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts VernCPPConfig
|
||||
function M.create_file(opts)
|
||||
vim.ui.input({ prompt = "Enter type (c/h): " }, function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or ft == "" then
|
||||
return
|
||||
end
|
||||
local configs = require("vern-nvim.configs.cpp")
|
||||
---@type VernCPPConfig
|
||||
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.cpp.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.cpp.templates.file.source or {}
|
||||
end
|
||||
if ft == "h" then
|
||||
mod = cfg.cpp.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 path = utils.resolve_path(raw_path, cfg.cpp.dirs or {}, context)
|
||||
local abs_file_path = vim.fs.normalize(join(root, 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
|
||||
|
||||
---@param opts? VernCPPConfig Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
|
||||
local build_dir = root .. "/build"
|
||||
local build_cmd = "cd " .. build_dir .. " && cmake --build ."
|
||||
|
||||
vim.system({ "sh", "-c", build_cmd }, { text = true }, function(obj)
|
||||
if obj.code ~= 0 then
|
||||
vim.schedule(function()
|
||||
local error_obj = (obj.stderr ~= "" and obj.stderr) or obj.stdout or ""
|
||||
local error_lines = vim.list_extend(
|
||||
{ "Error During compilation" },
|
||||
vim.split(error_obj, "\n", { trimempty = true })
|
||||
)
|
||||
local buf, _ = utils.term({ "echo 'compilation failed'" }, opts.terminal, true)
|
||||
if buf and vim.api.nvim_buf_is_valid(buf) then
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = buf })
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, error_lines)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
|
||||
end
|
||||
end)
|
||||
else
|
||||
vim.schedule(function()
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. pname
|
||||
utils.term({ run_cmd }, opts.terminal, false)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,52 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.create_project = function(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input(
|
||||
{ prompt = "Project language (e.g. python): ", completion = "filetype" },
|
||||
function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or vim.trim(ft) == "" then
|
||||
return
|
||||
end
|
||||
local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
|
||||
local configs = require("vern-nvim.configs." .. ft)
|
||||
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
if ok and actions and type(actions.create_project) == "function" then
|
||||
actions.create_project(args)
|
||||
else
|
||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
||||
title = "Vern Project",
|
||||
})
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
M.create_file = function(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input({
|
||||
prompt = "File language (e.g. python): ",
|
||||
completion = "filetype",
|
||||
}, function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or vim.trim(ft) == "" then
|
||||
return
|
||||
end
|
||||
local ok, actions = pcall(require, "vern-nvim.actions." .. ft)
|
||||
local configs = require("vern-nvim.configs." .. ft)
|
||||
local args = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
if ok and actions and type(actions.create_file) == "function" then
|
||||
actions.create_file(args)
|
||||
else
|
||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
||||
title = "Vern File",
|
||||
})
|
||||
vim.notify("Error: " .. actions, vim.log.levels.ERROR, {
|
||||
title = "Vern File",
|
||||
})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,65 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
local templates = require("vern-nvim.templates")
|
||||
local action_utils = require("vern-nvim.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
---@param opts VernLuaConfig
|
||||
function M.create_project(opts)
|
||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||
pname = pname and vim.trim(pname)
|
||||
if not pname or pname == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local configs = require("vern-nvim.configs.lua")
|
||||
|
||||
---@type VernLuaConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, configs, opts or {})
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.lua.root, pname)
|
||||
local bin = action_utils.create(cfg.lua, pname, root)
|
||||
|
||||
utils.init_git(root, "lua")
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts VernLuaConfig
|
||||
function M.create_file(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||
fname = fname and vim.trim(fname)
|
||||
if not fname or fname == "" then
|
||||
return
|
||||
end
|
||||
local configs = require("vern-nvim.configs.lua")
|
||||
---@type VernLuaConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
local mod = cfg.lua.templates.file.source or {}
|
||||
|
||||
local raw_path = join(mod.path, mod.name)
|
||||
local context = { project_name = utils.proj_name(), name = fname }
|
||||
local path = utils.resolve_path(raw_path, cfg.lua.dirs or {}, context)
|
||||
|
||||
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))
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts VernCPPConfig Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
|
||||
local full_path = join(root, pname, "lua", pname)
|
||||
print(full_path .. "/init.lua")
|
||||
|
||||
utils.term({ "lua " .. full_path .. "/init.lua" }, opts.terminal or {}, false)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,90 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
local templates = require("vern-nvim.templates")
|
||||
local action_utils = require("vern-nvim.actions.utils")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
---@param opts VernPythonConfig
|
||||
function M.create_project(opts)
|
||||
vim.ui.input({ prompt = "Enter project name: " }, function(pname)
|
||||
pname = pname and vim.trim(pname)
|
||||
if not pname or pname == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local configs = require("vern-nvim.configs.python")
|
||||
|
||||
---@type VernPythonConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), cfg.python.root, pname)
|
||||
local bin = action_utils.create(cfg.python, pname, root)
|
||||
|
||||
utils.init_git(root, "python")
|
||||
|
||||
local venv_path = root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
|
||||
vim.notify("Project: " .. pname .. " has been created!")
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts VernPythonConfig
|
||||
function M.create_file(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||
fname = fname and vim.trim(fname)
|
||||
if not fname or fname == "" then
|
||||
return
|
||||
end
|
||||
local configs = require("vern-nvim.configs.python")
|
||||
---@type VernPythonConfig
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, opts or {})
|
||||
local mod = cfg.python.templates.file.source or {}
|
||||
|
||||
local raw_path = join(mod.path, mod.name)
|
||||
local context = { project_name = utils.proj_name(), name = fname }
|
||||
local path = utils.resolve_path(raw_path, cfg.python.dirs or {}, context)
|
||||
|
||||
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))
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts VernPythonConfig Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
local bin = opts.python.templates.project.primary
|
||||
|
||||
local exe = join(bin.path, bin.name) or "src/{project_name}/main.py"
|
||||
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 {}, false)
|
||||
end
|
||||
|
||||
function M.pip_install()
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(mod)
|
||||
mod = mod and vim.trim(mod)
|
||||
if not mod or mod == "" then
|
||||
vim.notify("Pip Cancelled", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
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
|
||||
|
||||
return M
|
||||
@@ -1,52 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
local templates = require("vern-nvim.templates")
|
||||
|
||||
local join = vim.fs.joinpath
|
||||
|
||||
---@param cfg table Language config
|
||||
---@param pname string Name of project
|
||||
---@param root string Project location
|
||||
---@return string bin Location of executable
|
||||
function M.create(cfg, pname, root)
|
||||
local ctx = { project_name = pname }
|
||||
|
||||
vim.fn.mkdir(root, "p")
|
||||
local bin
|
||||
|
||||
for _, dir in pairs(cfg.dirs) do
|
||||
local path = vim.fs.normalize(join(root, utils.fmt(dir, ctx)))
|
||||
vim.fn.mkdir(path, "p")
|
||||
end
|
||||
|
||||
for tbl_name, tbl in pairs(cfg.templates.project) do
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.dirs, ctx)
|
||||
if tbl_name == "primary" then
|
||||
bin = join(root, path)
|
||||
end
|
||||
local abs_file_path = vim.fs.normalize(join(root, path))
|
||||
local abs_dir_path = vim.fs.dirname(abs_file_path)
|
||||
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
|
||||
vim.fn.mkdir(abs_dir_path, "p")
|
||||
end
|
||||
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
|
||||
end
|
||||
for _, tbl in pairs(cfg.templates.extras) do
|
||||
if tbl.enabled then
|
||||
local raw_path = join(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, cfg.dirs, ctx)
|
||||
local abs_file_path = vim.fs.normalize(join(root, path))
|
||||
local abs_dir_path = vim.fs.dirname(abs_file_path)
|
||||
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
|
||||
vim.fn.mkdir(abs_dir_path, "p")
|
||||
end
|
||||
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, pname))
|
||||
end
|
||||
end
|
||||
|
||||
return bin
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,26 +0,0 @@
|
||||
local actions = require("vern-nvim.actions.c")
|
||||
local config = require("vern-nvim.configs.c")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernCConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernCConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "CRun", function()
|
||||
if type(actions.run) == "function" then
|
||||
actions.run(opts)
|
||||
end
|
||||
end, { desc = "Run c project" })
|
||||
|
||||
for key, def in pairs(opts.c.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
local actions = require("vern-nvim.actions.cpp")
|
||||
local config = require("vern-nvim.configs.cpp")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernCPPConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernCPPConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "CPPRun", function()
|
||||
if type(actions.run) == "function" then
|
||||
actions.run(opts)
|
||||
end
|
||||
end, { desc = "Run cpp project" })
|
||||
|
||||
for key, def in pairs(opts.cpp.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,26 +0,0 @@
|
||||
local actions = require("vern-nvim.actions.lua")
|
||||
local config = require("vern-nvim.configs.lua")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernLuaConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernLuaConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "LuaRun", function()
|
||||
if type(actions.run) == "function" then
|
||||
actions.run(opts)
|
||||
end
|
||||
end, { desc = "Run lua project" })
|
||||
|
||||
for key, def in pairs(opts.lua.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
local actions = require("vern-nvim.actions.python")
|
||||
local config = require("vern-nvim.configs.python")
|
||||
|
||||
---@param bufnr integer Buffer to activate on : defaults to 0
|
||||
---@param user_opts? VernPythonConfig
|
||||
return function(bufnr, user_opts)
|
||||
---@type VernPythonConfig
|
||||
local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {})
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function()
|
||||
if type(actions.run) == "function" then
|
||||
actions.run(opts)
|
||||
end
|
||||
end, { desc = "Run python project" })
|
||||
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function()
|
||||
if actions.pip_install then
|
||||
actions.pip_install()
|
||||
end
|
||||
end, { nargs = "*", desc = "Install python packages" })
|
||||
|
||||
for key, def in pairs(opts.python.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(opts)
|
||||
end, {
|
||||
buffer = bufnr,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local root = require("vern-nvim.utils").proj_root()
|
||||
if not root then
|
||||
return
|
||||
end
|
||||
local venv_dir = nil
|
||||
if vim.uv.fs_stat(root .. "/venv/bin/python") then
|
||||
venv_dir = root .. "/venv"
|
||||
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
|
||||
venv_dir = root .. "/.venv"
|
||||
end
|
||||
if venv_dir then
|
||||
vim.env.VIRTUAL_ENV = venv_dir
|
||||
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,52 @@
|
||||
---@module "vern-nvim.core.actions"
|
||||
local actions = require("vern-nvim.core.actions")
|
||||
|
||||
---@type VernCoreConfig
|
||||
return {
|
||||
workspace_root = "~/personal/Projects",
|
||||
env = {
|
||||
--- In documentation, make recommendation to change to username or name instead of company
|
||||
author = "company",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pc"] = {
|
||||
user_command = "VernCreateProject",
|
||||
desc = "Creates a new project",
|
||||
action = actions.create_project,
|
||||
},
|
||||
["<leader>pf"] = {
|
||||
user_command = "VernCreateFile",
|
||||
desc = "Creates a new project file based on current buffer filetype",
|
||||
action = actions.create_file,
|
||||
},
|
||||
["<leader>pr"] = {
|
||||
user_command = "VernRunProject",
|
||||
desc = "Builds and runs project based on current buffer filetype",
|
||||
action = actions.run,
|
||||
},
|
||||
},
|
||||
terminal = {
|
||||
mode = {
|
||||
type = "split", --- (float)|(split)
|
||||
win = {
|
||||
float = {
|
||||
padding = {
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
bottom = 0,
|
||||
},
|
||||
border = {
|
||||
enabled = true,
|
||||
type = vim.o.winborder, -- defaults to neovim winborder
|
||||
},
|
||||
},
|
||||
split = {
|
||||
direction = "horizontal", --- (vertical)|(horizontal)
|
||||
anchor = "bottom", --- (right)|(bottom)
|
||||
size = "20",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.c = {
|
||||
root = "C",
|
||||
dirs = {
|
||||
src = "src",
|
||||
include = "include/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes c code",
|
||||
action = require("vern-nvim.actions.c").run,
|
||||
},
|
||||
["<leader>pf"] = {
|
||||
desc = "Creates source/header files",
|
||||
action = require("vern-nvim.actions.c").create_file,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "main.c",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
manifest = {
|
||||
path = ".",
|
||||
name = "CMakeLists.txt",
|
||||
kind = "CmakeLists",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = ".clang-format",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
header = {
|
||||
path = "{dirs.include}",
|
||||
name = "{name}.h",
|
||||
kind = "header",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{name}.c",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
linter = {
|
||||
path = ".",
|
||||
name = ".clang-tidy",
|
||||
kind = "linter",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
enabled = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,67 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.cpp = {
|
||||
root = "CPP",
|
||||
dirs = {
|
||||
src = "src",
|
||||
include = "include/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes cpp code",
|
||||
action = require("vern-nvim.actions.cpp").run,
|
||||
},
|
||||
["<leader>pf"] = {
|
||||
desc = "Creates source/header files",
|
||||
action = require("vern-nvim.actions.cpp").create_file,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "main.cpp",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
manifest = {
|
||||
path = ".",
|
||||
name = "CMakeLists.txt",
|
||||
kind = "CmakeLists",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = ".clang-format",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
header = {
|
||||
path = "{dirs.include}",
|
||||
name = "{name}.hpp",
|
||||
kind = "header",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{name}.c",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
linter = {
|
||||
path = ".",
|
||||
name = ".clang-tidy",
|
||||
kind = "linter",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
enabled = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,40 +0,0 @@
|
||||
local actions = require("vern-nvim.actions")
|
||||
|
||||
---@type VernCoreConfig
|
||||
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 = {
|
||||
type = "split",
|
||||
win = {
|
||||
float = {
|
||||
padding = {
|
||||
left = 0,
|
||||
right = 0,
|
||||
top = 0,
|
||||
bottom = 0,
|
||||
},
|
||||
border = {
|
||||
enabled = true,
|
||||
type = vim.o.winborder, -- defaults to neovim winborder
|
||||
},
|
||||
},
|
||||
split = {
|
||||
direction = "horizontal",
|
||||
anchor = "bottom",
|
||||
size = "20",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.lua = {
|
||||
root = "Lua",
|
||||
dirs = {
|
||||
src = "lua/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes lua code",
|
||||
action = require("vern-nvim.actions.lua").run,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "init.lua",
|
||||
kind = "init",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = "stylua.toml",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{name}.lua",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
},
|
||||
extras = {},
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,51 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.python = {
|
||||
root = "Python",
|
||||
dirs = {
|
||||
src = "src/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes python code",
|
||||
action = require("vern-nvim.actions.python").run,
|
||||
},
|
||||
["<leader>pi"] = {
|
||||
desc = "Asks for what python package to install",
|
||||
action = require("vern-nvim.actions.python").pip_install,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "main.py",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
manifest = {
|
||||
path = ".",
|
||||
name = "pyproject.toml",
|
||||
kind = "pyproject",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
pkg_init = {
|
||||
path = "{dirs.src}",
|
||||
name = "__init__.py",
|
||||
kind = "__init__",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{name}.py",
|
||||
kind = "module",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
},
|
||||
extras = {},
|
||||
},
|
||||
}
|
||||
return M
|
||||
@@ -0,0 +1,227 @@
|
||||
local M = {}
|
||||
|
||||
---@module "vern-nvim.core.fs"
|
||||
local fs = require("vern-nvim.core.fs")
|
||||
|
||||
---@module "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
|
||||
|
||||
M.create_project = function(opts)
|
||||
opts = opts or {}
|
||||
local ft = ""
|
||||
local items = {
|
||||
"cpp",
|
||||
"c",
|
||||
"rust",
|
||||
"python",
|
||||
"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
|
||||
end
|
||||
local args = vim.tbl_deep_extend("force", {}, langs, opts or {})
|
||||
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)
|
||||
pname = pname and vim.trim(pname)
|
||||
if not pname or pname == "" then return end
|
||||
local root = vim.fs.joinpath(
|
||||
vim.fn.expand(args.workspace_root),
|
||||
args[ft].root,
|
||||
pname
|
||||
)
|
||||
|
||||
local ctx = {
|
||||
project_name = pname,
|
||||
company_name = args.env.author,
|
||||
file_name = "",
|
||||
}
|
||||
|
||||
vim.fn.mkdir(root, "p")
|
||||
local dirs = args[ft].dirs
|
||||
if type(dirs) == "table" and next(dirs) then
|
||||
for _, dir in pairs(dirs) do
|
||||
local path = vim.fs.normalize(
|
||||
vim.fs.joinpath(root, fs.fmt_path(dir, nil, ctx))
|
||||
)
|
||||
vim.fn.mkdir(path, "p")
|
||||
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 project = tpl.project
|
||||
if type(project) == "table" and next(project) then
|
||||
for tbl_name, tbl in pairs(project) do
|
||||
if tbl_name == "primary" then
|
||||
bin = vim.fs.joinpath(
|
||||
root,
|
||||
fs.fmt_path(
|
||||
vim.fs.joinpath(tbl.path, tbl.name),
|
||||
args[ft].dirs,
|
||||
ctx
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
write(project)
|
||||
write(tpl.extras)
|
||||
|
||||
if type(langs.create_project) == "function" then
|
||||
langs.create_project(root)
|
||||
end
|
||||
|
||||
--- Init git
|
||||
local gitignore =
|
||||
require("vern-nvim.templates.extras.gitignore").template(ft)
|
||||
local obj = vim.system({ "git", "-C", root, "init" }):wait()
|
||||
if obj.code ~= 0 then
|
||||
vim.notify(
|
||||
"Git init failed " .. obj.stderr,
|
||||
vim.log.levels.ERROR,
|
||||
{ title = "Vern Git" }
|
||||
)
|
||||
end
|
||||
fs.write(vim.fs.joinpath(root, ".gitignore"), gitignore)
|
||||
|
||||
--- Init Readme
|
||||
local readme = require("vern-nvim.templates.extras.readme")
|
||||
fs.write(vim.fs.joinpath(root, "README.md"), readme)
|
||||
|
||||
if bin then vim.cmd.edit(vim.fn.fnameescape(bin)) end
|
||||
vim.notify(
|
||||
"Project: " .. pname .. " has been created!",
|
||||
vim.log.levels.INFO,
|
||||
{ title = "Vern Project" }
|
||||
)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
M.create_file = function(opts)
|
||||
opts = opts or {}
|
||||
local filetype = vim.bo.filetype
|
||||
|
||||
local ft_ok, config = pcall(require, "vern-nvim.langs." .. filetype)
|
||||
if not filetype or filetype == "" or not ft_ok or type(config) ~= "table" then
|
||||
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
|
||||
title = "Vern File",
|
||||
})
|
||||
return
|
||||
else
|
||||
local args = vim.tbl_deep_extend("force", {}, config, opts or {})
|
||||
---@type VernCreateFile
|
||||
local cf = args.create_file
|
||||
local function function_write(mod, fname)
|
||||
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
||||
local context = {
|
||||
project_name = fs.name(),
|
||||
company_name = args.env.author,
|
||||
file_name = fname,
|
||||
}
|
||||
local path = fs.fmt_path(raw_path, args[filetype].dirs or {}, context)
|
||||
local full_path = vim.fs.joinpath(fs.root(), path)
|
||||
fs.write(full_path, templates.fetch(mod.kind_path, mod.kind, context))
|
||||
vim.cmd.edit(vim.fn.fnameescape(full_path))
|
||||
vim.notify(
|
||||
fname .. " has been created!",
|
||||
vim.log.levels.INFO,
|
||||
{ title = "Vern File" }
|
||||
)
|
||||
end
|
||||
|
||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||
fname = fname and vim.trim(fname)
|
||||
if not fname or fname == "" then return end
|
||||
|
||||
local done = function(mod)
|
||||
if not mod or vim.tbl_isempty(mod) then return end
|
||||
function_write(mod, fname)
|
||||
end
|
||||
|
||||
if cf and type(cf) == "function" then
|
||||
cf(args, done)
|
||||
else
|
||||
done(args[filetype].templates.file.source)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
M.run = function(opts)
|
||||
opts = opts or {}
|
||||
local filetype = vim.bo.filetype
|
||||
|
||||
local ft_ok, action = pcall(require, "vern-nvim.langs." .. filetype)
|
||||
if
|
||||
not filetype
|
||||
or filetype == ""
|
||||
or not ft_ok
|
||||
or type(action.run) ~= "function"
|
||||
then
|
||||
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
|
||||
title = "Vern Run",
|
||||
})
|
||||
return
|
||||
else
|
||||
local args = vim.tbl_deep_extend(
|
||||
"force",
|
||||
{},
|
||||
opts,
|
||||
require("vern-nvim.langs." .. filetype)
|
||||
)
|
||||
action.run(args)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,28 @@
|
||||
local M = {}
|
||||
|
||||
---@module "vern-nvim.core.terminal"
|
||||
local term = require("vern-nvim.core.terminal")
|
||||
|
||||
---@param opts table
|
||||
---@param build_cmd string
|
||||
---@param run_cmd string
|
||||
M.compile = function(opts, build_cmd, run_cmd)
|
||||
vim.system({ "sh", "-c", build_cmd }, { text = true }, function(obj)
|
||||
if obj.code ~= 0 then
|
||||
vim.schedule(function()
|
||||
local error_obj = (obj.stderr ~= "" and obj.stderr) or obj.stdout or ""
|
||||
local error_lines = vim.list_extend(
|
||||
{ "Error During compilation" },
|
||||
vim.split(error_obj, "\n", { trimempty = true })
|
||||
)
|
||||
local buf, _ =
|
||||
term.open({ "echo 'compilation failed'" }, opts.terminal, true)
|
||||
term.set_lines(buf, error_lines)
|
||||
end)
|
||||
else
|
||||
vim.schedule(function() term.open({ run_cmd }, opts.terminal, false) end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,49 @@
|
||||
local M = {}
|
||||
|
||||
---@param raw_path string Combination of tbl.path and tbl.name to override
|
||||
---@param dir_tbl? table<string, string> Strings to replace raw directories in {dirs.<>} with
|
||||
---@param ctx table<string, string> Strings to replace raw names like {project_name} with
|
||||
---@return string path Fully replaced path
|
||||
function M.fmt_path(raw_path, dir_tbl, ctx)
|
||||
--- Replace the {dirs.<key>}
|
||||
raw_path = raw_path:gsub(
|
||||
"{dirs%.([%w_]+)}",
|
||||
function(dir_key) return dir_tbl and dir_tbl[dir_key] or dir_key end
|
||||
)
|
||||
|
||||
--- Replace the {<key>}
|
||||
local path = raw_path:gsub(
|
||||
"{([%w_]+)}",
|
||||
function(key) return ctx and ctx[key] or ("{" .. key .. "}") end
|
||||
)
|
||||
|
||||
return path
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@param content string
|
||||
function M.write(path, content)
|
||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||
file:write(content)
|
||||
file:close()
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.name() return vim.fs.basename(M.root()) or "" end
|
||||
|
||||
---@param bufnr? integer Default is 0 (current buffer)
|
||||
---@return string
|
||||
function M.root(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
local root_markers = {
|
||||
".git",
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"Makefile",
|
||||
"CMakeLists",
|
||||
"Cargo.toml",
|
||||
}
|
||||
return vim.fs.root(bufnr, root_markers) or vim.uv.cwd() or "."
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,31 @@
|
||||
local M = {}
|
||||
|
||||
local registers = {
|
||||
project_name = "__PROJECT_NAME__",
|
||||
company_name = "__COMPANY_NAME__",
|
||||
file_name = "__FILE_NAME__",
|
||||
}
|
||||
|
||||
---@param kind_path string Filetype of template
|
||||
---@param kind string Template in language table
|
||||
---@param context table<string, string> A string to replace temp values in template
|
||||
---@return string Content Formatted string
|
||||
function M.fetch(kind_path, kind, context)
|
||||
kind, context = kind or "", context or {}
|
||||
if not kind or kind == "" then return "" end
|
||||
local ok, mod = pcall(require, kind_path)
|
||||
if not ok or type(mod) ~= "table" or not mod[kind] then return "" end
|
||||
|
||||
local template = mod[kind] or ""
|
||||
context = context or {}
|
||||
|
||||
if ok and type(mod) == "table" then
|
||||
for key, placeholder in pairs(registers) do
|
||||
local value = context[key]
|
||||
if value then template = string.gsub(template, placeholder, value) end
|
||||
end
|
||||
end
|
||||
return template
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,96 @@
|
||||
local M = {}
|
||||
|
||||
---@param cmd table
|
||||
---@param opts VernTerminalConfig
|
||||
---@param scratch boolean
|
||||
---@return integer, integer?
|
||||
function M.open(cmd, opts, scratch)
|
||||
opts = opts or {}
|
||||
local buf, win
|
||||
if opts.mode.type == "float" then
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
|
||||
local dim = {
|
||||
width = math.max(
|
||||
1,
|
||||
math.floor(ui.width * 0.9)
|
||||
- opts.mode.win.float.padding.left
|
||||
- opts.mode.win.float.padding.right
|
||||
),
|
||||
height = math.max(
|
||||
1,
|
||||
math.floor(ui.height * 0.9)
|
||||
- opts.mode.win.float.padding.top
|
||||
- opts.mode.win.float.padding.bottom
|
||||
),
|
||||
}
|
||||
|
||||
local pos = {
|
||||
row = math.floor(
|
||||
(
|
||||
ui.height
|
||||
- (vim.o.laststatus == 3 and 1 or 0)
|
||||
- vim.o.cmdheight
|
||||
- dim.height
|
||||
) / 2
|
||||
),
|
||||
col = math.floor((ui.width - dim.width) / 2),
|
||||
}
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = dim.width,
|
||||
height = dim.height,
|
||||
row = pos.row,
|
||||
col = pos.col,
|
||||
style = "minimal",
|
||||
border = opts.mode.win.float.border.enabled
|
||||
and opts.mode.win.float.border.type
|
||||
or nil,
|
||||
})
|
||||
if scratch then return buf, win end
|
||||
end
|
||||
if opts.mode.type == "split" then
|
||||
if opts.mode.win.split.direction == "vertical" then
|
||||
if opts.mode.win.split.anchor == "right" then
|
||||
vim.cmd("set splitright")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " vsplit")
|
||||
end
|
||||
if opts.mode.win.split.direction == "horizontal" then
|
||||
if opts.mode.win.split.anchor == "bottom" then
|
||||
vim.cmd("set splitbelow")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " split")
|
||||
end
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_get_current_win()
|
||||
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
if scratch then return buf, win end
|
||||
end
|
||||
local full_cmd = type(cmd) == "table" and table.concat(cmd, " ") or cmd
|
||||
vim.fn.jobstart(full_cmd, { term = true })
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<ESC>",
|
||||
"i<C-\\><C-n>:q<CR>",
|
||||
{ noremap = true, silent = true }
|
||||
)
|
||||
return buf, win
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
---@param lines table
|
||||
function M.set_lines(buf, lines)
|
||||
if buf and vim.api.nvim_buf_is_valid(buf) then
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = buf })
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = buf })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,157 +0,0 @@
|
||||
local ok, health = pcall(require, "vim.health")
|
||||
if not ok then
|
||||
health = nil
|
||||
end
|
||||
|
||||
local new_api = health ~= nil and type(health.start) == "function"
|
||||
|
||||
local function report_start(name)
|
||||
if new_api then health.start(name) else vim.health.report_start(name) end
|
||||
end
|
||||
|
||||
local function report_ok(msg)
|
||||
if new_api then health.ok(msg) else vim.health.report_ok(msg) end
|
||||
end
|
||||
|
||||
local function report_info(msg)
|
||||
if new_api then health.info(msg) else vim.health.report_info(msg) end
|
||||
end
|
||||
|
||||
local function report_warn(msg, advice)
|
||||
if new_api then
|
||||
health.warn(msg, advice)
|
||||
else
|
||||
vim.health.report_warn(msg, advice)
|
||||
end
|
||||
end
|
||||
|
||||
local function report_error(msg, advice)
|
||||
if new_api then
|
||||
health.error(msg, advice)
|
||||
else
|
||||
vim.health.report_error(msg, advice)
|
||||
end
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
local function fmt_langs(langs)
|
||||
if type(langs) == "table" then
|
||||
return "[" .. table.concat(langs, ", ") .. "]"
|
||||
end
|
||||
return "[" .. tostring(langs) .. "]"
|
||||
end
|
||||
|
||||
local function check_nvim_version()
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
report_ok(string.format("Neovim %s detected.", tostring(vim.version())))
|
||||
else
|
||||
report_error("Polydev requires Neovim 0.10 or newer.", "You are running " .. tostring(vim.version()))
|
||||
end
|
||||
end
|
||||
|
||||
local function check_setup()
|
||||
local ok_configs, configs = pcall(require, "Polydev.configs")
|
||||
if not ok_configs then
|
||||
report_error("Could not load Polydev.configs", tostring(configs))
|
||||
return nil
|
||||
end
|
||||
if next(configs.user_config or {}) == nil then
|
||||
report_warn("Polydev.setup() has not run.",
|
||||
"Add require('Polydev').setup() to your Neovim config, or make sure plugin/Polydev.lua is sourced by your plugin manager.")
|
||||
return nil
|
||||
end
|
||||
report_ok("Polydev.setup() ran and the config is loaded.")
|
||||
return configs
|
||||
end
|
||||
|
||||
local function check_project_root(configs)
|
||||
if not configs then return end
|
||||
local root = configs.get("globals").project_root
|
||||
local expanded = vim.fn.expand(root)
|
||||
if vim.fn.isdirectory(expanded) == 1 then
|
||||
if vim.fn.filewritable(expanded) == 2 then
|
||||
report_ok(string.format("project_root exists and is writable: %s", expanded))
|
||||
else
|
||||
report_warn(string.format("project_root exists but is not writable: %s", expanded))
|
||||
end
|
||||
else
|
||||
report_warn(string.format("project_root does not exist yet: %s", expanded),
|
||||
"It is created automatically the first time the manager is opened.")
|
||||
end
|
||||
end
|
||||
|
||||
local function check_ui_input()
|
||||
local ok_default, default = pcall(require, "vim.ui")
|
||||
if ok_default and default.input and vim.ui.input ~= default.input then
|
||||
report_warn("vim.ui.input has been overridden, likely by a UI plugin such as dressing.nvim or nui.nvim.",
|
||||
"An asynchronous override can break project/file creation from the manager. Polydev now uses callbacks, but report here if it still misbehaves.")
|
||||
else
|
||||
report_ok("vim.ui.input is Neovim's default (synchronous) implementation.")
|
||||
end
|
||||
end
|
||||
|
||||
local function check_tools()
|
||||
local tools = {
|
||||
{ name = "git", langs = "all" },
|
||||
{ name = "node", langs = "javascript" },
|
||||
{ name = "python3", langs = "python" },
|
||||
{ name = "pip3", langs = "python" },
|
||||
{ name = "javac", langs = "java" },
|
||||
{ name = "java", langs = "java" },
|
||||
{ name = "cmake", langs = { "c", "cpp" } },
|
||||
{ name = "cc", langs = { "c", "cpp" } },
|
||||
{ name = "clang", langs = { "c", "cpp" } },
|
||||
{ name = "clang-format", langs = { "c", "cpp" } },
|
||||
{ name = "clang-tidy", langs = { "c", "cpp" } },
|
||||
{ name = "cargo", langs = "rust" },
|
||||
{ name = "lua", langs = "lua" },
|
||||
{ name = "luajit", langs = "lua" },
|
||||
}
|
||||
for _, t in ipairs(tools) do
|
||||
if vim.fn.executable(t.name) == 1 then
|
||||
report_ok(string.format("%s is available for %s.", t.name, fmt_langs(t.langs)))
|
||||
else
|
||||
report_warn(string.format("%s was not found.", t.name),
|
||||
"Project templates for " .. fmt_langs(t.langs) .. " may fail without it.")
|
||||
end
|
||||
end
|
||||
|
||||
if vim.fn.executable("python3") == 1 then
|
||||
vim.fn.system("python3 -c 'import venv' 2>/dev/null")
|
||||
if vim.v.shell_error == 0 then
|
||||
report_ok("python3 venv module is available.")
|
||||
else
|
||||
report_warn("python3 venv module is missing.",
|
||||
"Python project creation sets up a virtualenv and needs python3 -m venv.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function check_walkup()
|
||||
local scripts = vim.api.nvim_get_runtime_file("bash_scripts/walkup.sh", false)
|
||||
if #scripts == 0 then
|
||||
report_error("bash_scripts/walkup.sh was not found on the runtimepath.",
|
||||
"Reinstall the plugin so bash_scripts/ sits next to lua/ and plugin/.")
|
||||
return
|
||||
end
|
||||
local script = scripts[1]
|
||||
if vim.fn.executable(script) == 1 then
|
||||
report_ok(string.format("bash_scripts/walkup.sh found and executable: %s", script))
|
||||
else
|
||||
report_warn(string.format("bash_scripts/walkup.sh is not executable: %s", script),
|
||||
"Run: chmod +x " .. script)
|
||||
end
|
||||
end
|
||||
|
||||
function M.check()
|
||||
report_start("Polydev")
|
||||
check_nvim_version()
|
||||
local configs = check_setup()
|
||||
check_project_root(configs)
|
||||
check_ui_input()
|
||||
check_tools()
|
||||
check_walkup()
|
||||
end
|
||||
|
||||
return M
|
||||
+51
-43
@@ -1,57 +1,65 @@
|
||||
local M = {}
|
||||
|
||||
local configs = require("vern-nvim.configs")
|
||||
local actions = require("vern-nvim.actions")
|
||||
---@module "vern-nvim.config.defaults"
|
||||
local defaults = require("vern-nvim.config.defaults")
|
||||
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.deepcopy(configs)
|
||||
|
||||
---@class VernUserConfig
|
||||
---@field workspace_root? string
|
||||
---@field keybinds? table<string, VernKeybindItem>
|
||||
---@field terminal? VernTerminalConfig | table
|
||||
M.opts = vim.deepcopy(defaults)
|
||||
|
||||
---@param user_opts? VernUserConfig
|
||||
function M.setup(user_opts)
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.tbl_deep_extend("force", {}, defaults, user_opts or {})
|
||||
|
||||
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
|
||||
for key, def in pairs(M.opts.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_create_user_command(
|
||||
def.user_command,
|
||||
function() def.action(M.opts) end,
|
||||
{ nargs = "*", desc = def.desc }
|
||||
)
|
||||
vim.keymap.set("n", key, function() def.action(M.opts) end, {
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("VernCreateProject", function()
|
||||
if actions.create_project then
|
||||
actions.create_project(M.opts)
|
||||
local group =
|
||||
vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = group,
|
||||
pattern = "*",
|
||||
callback = function(args)
|
||||
local ft = vim.bo[args.buf].filetype
|
||||
if not ft or ft == "" then return end
|
||||
local ok, mod = pcall(require, "vern-nvim.langs." .. ft)
|
||||
if not ok then return end
|
||||
|
||||
local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {})
|
||||
if opts[ft] and opts[ft].keybinds ~= nil then
|
||||
for key, def in pairs(opts[ft].keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.api.nvim_buf_create_user_command(
|
||||
args.buf,
|
||||
def.user_command,
|
||||
function() def.action(opts) end,
|
||||
{ nargs = "*", desc = def.desc }
|
||||
)
|
||||
vim.keymap.set("n", key, function() def.action(opts) end, {
|
||||
buffer = args.buf,
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
end, { nargs = "*", desc = "Create a new project" })
|
||||
|
||||
vim.api.nvim_create_user_command("VernCreateFile", function()
|
||||
if type(actions.create_file) == "function" then
|
||||
actions.create_file(M.opts)
|
||||
end
|
||||
end, { nargs = "*", desc = "Creates a new file for project" })
|
||||
|
||||
local group = vim.api.nvim_create_augroup("VernAutocommands", { clear = true })
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = group,
|
||||
pattern = "*",
|
||||
callback = function(args)
|
||||
local ft = vim.bo[args.buf].filetype
|
||||
local ok, attach = pcall(require, "vern-nvim.attach." .. ft)
|
||||
if ok and type(attach) == "function" then
|
||||
attach(args.buf, M.opts)
|
||||
end
|
||||
end,
|
||||
desc = "Attach languages to buffer",
|
||||
})
|
||||
end
|
||||
if ok and type(mod.attach) == "function" then
|
||||
mod.attach(args.buf, opts)
|
||||
end
|
||||
end,
|
||||
desc = "Attach languages to buffer",
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,101 @@
|
||||
---@module "vern-nvim.core.fs"
|
||||
local fs = require("vern-nvim.core.fs")
|
||||
|
||||
---@module "vern-nvim.core.compile"
|
||||
local comp = require("vern-nvim.core.compile")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.attach = nil
|
||||
|
||||
---@param root string
|
||||
M.create_project = function(root)
|
||||
local build_cmd = "cd "
|
||||
.. root
|
||||
.. " && cmake -S . -B build && cmake --build build"
|
||||
local _ = vim.system({ "sh", "-c", build_cmd }):wait()
|
||||
end
|
||||
|
||||
---@type VernCreateFile
|
||||
---@param opts VernCConfig
|
||||
M.create_file = function(opts, continue)
|
||||
opts = opts or {}
|
||||
local file = vim.tbl_get(opts, "c", "templates", "file")
|
||||
local items = { "source", "header" }
|
||||
vim.ui.select(items, {
|
||||
prompt = "Select type:",
|
||||
format_item = function(item) return item end,
|
||||
}, function(choice, _)
|
||||
if choice == items[1] then return continue(file.source) end
|
||||
if choice == items[2] then return continue(file.header) end
|
||||
continue(nil)
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts? VernCConfig Takes a table for the runtime
|
||||
M.run = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local build_dir = vim.fn.fnameescape(fs.root() .. "/build")
|
||||
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
||||
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
||||
|
||||
comp.compile(opts, build_cmd, run_cmd)
|
||||
end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.c = {
|
||||
root = "C",
|
||||
dirs = {
|
||||
src = "src",
|
||||
include = "include/{project_name}",
|
||||
},
|
||||
keybinds = nil,
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "main.c",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
manifest = {
|
||||
path = ".",
|
||||
name = "CMakeLists.txt",
|
||||
kind = "CmakeLists",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = ".clang-format",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
header = {
|
||||
path = "{dirs.include}",
|
||||
name = "{file_name}.h",
|
||||
kind = "header",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{file_name}.c",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
linter = {
|
||||
path = ".",
|
||||
name = ".clang-tidy",
|
||||
kind = "linter",
|
||||
kind_path = "vern-nvim.templates.c",
|
||||
enabled = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,101 @@
|
||||
---@module "vern-nvim.core.fs"
|
||||
local fs = require("vern-nvim.core.fs")
|
||||
|
||||
---@module "vern-nvim.core.compile"
|
||||
local comp = require("vern-nvim.core.compile")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.attach = nil
|
||||
|
||||
---@param root string
|
||||
M.create_project = function(root)
|
||||
local build_cmd = "cd "
|
||||
.. root
|
||||
.. " && cmake -S . -B build && cmake --build build"
|
||||
local _ = vim.system({ "sh", "-c", build_cmd }):wait()
|
||||
end
|
||||
|
||||
---@type VernCreateFile
|
||||
---@param opts VernCPPConfig
|
||||
M.create_file = function(opts, continue)
|
||||
opts = opts or {}
|
||||
local file = vim.tbl_get(opts, "cpp", "templates", "file")
|
||||
local items = { "source", "header" }
|
||||
vim.ui.select(items, {
|
||||
prompt = "Select type:",
|
||||
format_item = function(item) return item end,
|
||||
}, function(choice, _)
|
||||
if choice == items[1] then return continue(file.source) end
|
||||
if choice == items[2] then return continue(file.header) end
|
||||
continue(nil)
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts? VernCPPConfig Takes a table for the runtime
|
||||
M.run = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local build_dir = vim.fn.fnameescape(fs.root() .. "/build")
|
||||
local build_cmd = string.format("cd %s && cmake --build .", build_dir)
|
||||
local run_cmd = string.format("cd %s && ./%s", build_dir, fs.name())
|
||||
|
||||
comp.compile(opts, build_cmd, run_cmd)
|
||||
end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.cpp = {
|
||||
root = "CPP",
|
||||
dirs = {
|
||||
src = "src",
|
||||
include = "include/{project_name}",
|
||||
},
|
||||
keybinds = nil,
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "main.cpp",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
manifest = {
|
||||
path = ".",
|
||||
name = "CMakeLists.txt",
|
||||
kind = "CmakeLists",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = ".clang-format",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
header = {
|
||||
path = "{dirs.include}",
|
||||
name = "{file_name}.hpp",
|
||||
kind = "header",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{file_name}.cpp",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
linter = {
|
||||
path = ".",
|
||||
name = ".clang-tidy",
|
||||
kind = "linter",
|
||||
kind_path = "vern-nvim.templates.cpp",
|
||||
enabled = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,82 @@
|
||||
---@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 root_name = vim.fs.basename(root)
|
||||
local module_name = "com.DarthMooMancer." .. root_name
|
||||
local obj = vim
|
||||
.system({
|
||||
"sh",
|
||||
"-c",
|
||||
string.format(
|
||||
"go mod init %s && go build -o bin/%s main.go",
|
||||
module_name,
|
||||
root_name
|
||||
),
|
||||
}, { cwd = 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
|
||||
@@ -0,0 +1,81 @@
|
||||
---@module "vern-nvim.core.fs"
|
||||
local fs = require("vern-nvim.core.fs")
|
||||
|
||||
---@module "vern-nvim.core.compile"
|
||||
local comp = require("vern-nvim.core.compile")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.attach = nil
|
||||
|
||||
M.create_project = nil
|
||||
|
||||
---@type VernCreateFile
|
||||
M.create_file = nil
|
||||
|
||||
---@param opts VernJavaConfig 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 src_root = vim.fs.joinpath(
|
||||
root,
|
||||
fs.fmt_path(opts.java.dirs.src, opts.java.dirs, context)
|
||||
)
|
||||
local build_dir = root .. "/bin"
|
||||
local build_cmd = string.format(
|
||||
"javac -d %s -sourcepath %s $(find %s -name '*java')",
|
||||
build_dir,
|
||||
src_root,
|
||||
src_root
|
||||
)
|
||||
local run_cmd = string.format(
|
||||
"java -cp %s com.%s.%s.Main",
|
||||
build_dir,
|
||||
context.company_name,
|
||||
context.project_name
|
||||
)
|
||||
|
||||
comp.compile(opts, build_cmd, run_cmd)
|
||||
end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.java = {
|
||||
root = "Java",
|
||||
dirs = {
|
||||
src = "src/com/{company_name}/{project_name}",
|
||||
bin = "bin",
|
||||
},
|
||||
keybinds = nil,
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "Main.java",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.java",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = ".clang-format",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.java",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{file_name}.java",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.java",
|
||||
},
|
||||
},
|
||||
extras = nil,
|
||||
},
|
||||
}
|
||||
return M
|
||||
@@ -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")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.attach = nil
|
||||
|
||||
M.create_project = nil
|
||||
|
||||
---@type VernCreateFile
|
||||
M.create_file = nil
|
||||
|
||||
---@param opts VernLuaConfig 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.lua = {
|
||||
root = "Lua",
|
||||
dirs = {
|
||||
src = "lua/{project_name}",
|
||||
},
|
||||
keybinds = nil,
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "init.lua",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
style = {
|
||||
path = ".",
|
||||
name = "stylua.toml",
|
||||
kind = "format",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{file_name}.lua",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
},
|
||||
extras = nil,
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,138 @@
|
||||
---@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 = function()
|
||||
local root = fs.root()
|
||||
if not root then return end
|
||||
local venv_dir = nil
|
||||
if vim.uv.fs_stat(root .. "/venv/bin/python") then
|
||||
venv_dir = root .. "/venv"
|
||||
elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then
|
||||
venv_dir = root .. "/.venv"
|
||||
end
|
||||
if venv_dir then
|
||||
vim.env.VIRTUAL_ENV = venv_dir
|
||||
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
|
||||
---@param root string
|
||||
M.create_project = function(root)
|
||||
local obj = vim.system({ "python3", "-m", "venv", root .. "/venv" }):wait()
|
||||
if obj.code ~= 0 then
|
||||
vim.notify(
|
||||
"Virtual environment failed to initialize " .. obj.stderr,
|
||||
vim.log.levels.ERROR,
|
||||
{ title = "Vern Python" }
|
||||
)
|
||||
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({ "python3 " .. full_path }, opts.terminal or {}, false)
|
||||
end
|
||||
|
||||
M.pip_install = function()
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(mod)
|
||||
mod = mod and vim.trim(mod)
|
||||
if not mod or mod == "" then
|
||||
vim.notify(
|
||||
"Pip Cancelled",
|
||||
vim.log.levels.WARN,
|
||||
{ title = "Vern Python" }
|
||||
)
|
||||
return
|
||||
end
|
||||
vim.notify(
|
||||
"Installing " .. mod,
|
||||
vim.log.levels.INFO,
|
||||
{ title = "Vern Python" }
|
||||
)
|
||||
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,
|
||||
{ title = "Vern Python" }
|
||||
)
|
||||
else
|
||||
vim.notify(
|
||||
"Pip installed " .. mod,
|
||||
vim.log.levels.INFO,
|
||||
{ title = "Vern Python" }
|
||||
)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.python = {
|
||||
root = "Python",
|
||||
dirs = {
|
||||
src = "src/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pi"] = {
|
||||
user_command = "VernPythonPip",
|
||||
desc = "Install python packages for environment",
|
||||
action = M.pip_install,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
primary = {
|
||||
path = "{dirs.src}",
|
||||
name = "main.py",
|
||||
kind = "main",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
manifest = {
|
||||
path = ".",
|
||||
name = "pyproject.toml",
|
||||
kind = "pyproject",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
pkg_init = {
|
||||
path = "{dirs.src}",
|
||||
name = "__init__.py",
|
||||
kind = "__init__",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
source = {
|
||||
path = "{dirs.src}",
|
||||
name = "{file_name}.py",
|
||||
kind = "module",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
},
|
||||
extras = nil,
|
||||
},
|
||||
}
|
||||
return M
|
||||
@@ -0,0 +1,61 @@
|
||||
---@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({
|
||||
"cargo",
|
||||
"init",
|
||||
vim.fn.expand(root),
|
||||
"--name",
|
||||
vim.fs.basename(root),
|
||||
})
|
||||
:wait()
|
||||
|
||||
if obj.code ~= 0 then
|
||||
vim.notify("Cargo init failed:" .. obj.stderr, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
---@type VernCreateFile
|
||||
M.create_file = nil
|
||||
|
||||
---@param opts VernRustConfig Takes a table for the runtime
|
||||
M.run = function(opts)
|
||||
opts = opts or {}
|
||||
term.open(
|
||||
{ "cd " .. fs.root() .. " && cargo run" },
|
||||
opts.terminal or {},
|
||||
false
|
||||
)
|
||||
end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.rust = {
|
||||
root = "Rust",
|
||||
dirs = nil,
|
||||
keybinds = nil,
|
||||
templates = {
|
||||
project = {
|
||||
primary = { path = "src", name = "main.rs" },
|
||||
},
|
||||
file = {
|
||||
source = {
|
||||
path = "src",
|
||||
name = "{file_name}.rs",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.rust",
|
||||
},
|
||||
},
|
||||
extras = nil,
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -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
|
||||
@@ -1,142 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local configs = require("Polydev.configs")
|
||||
local M = {}
|
||||
|
||||
M.languages = {
|
||||
javascript = {
|
||||
setup = function(self, user_opts)
|
||||
local opts =
|
||||
vim.tbl_deep_extend("force", {}, configs.get("javascript"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavascriptRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavascriptRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local cmd = string.format("node " .. root .. "/main.js")
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "node " .. root .. "/main.js" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("JavaRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
|
||||
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
|
||||
local output = vim.fn.system(cmd)
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal({ cmd })
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
setup = function(user_opts)
|
||||
vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {})
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("RustRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":RustRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
if not root then
|
||||
return print("Error: Project root not found.")
|
||||
end
|
||||
|
||||
local cmd = { "cargo build" }
|
||||
local output = vim.fn.system(table.concat(cmd))
|
||||
|
||||
if not vim.v.shell_error == 0 then
|
||||
local term_buf = utils.terminal(cmd)
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
term_buf,
|
||||
0,
|
||||
-1,
|
||||
false,
|
||||
vim.list_extend(
|
||||
{ "Error during compilation:" },
|
||||
vim.split(output, "\n", { trimempty = true })
|
||||
)
|
||||
)
|
||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
||||
else
|
||||
utils.terminal({ "cargo run" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
lua = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("LuaRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local init_lua_path = utils.get_project_root()
|
||||
.. "/lua/"
|
||||
.. utils.get_project_name()
|
||||
.. "/init.lua"
|
||||
if vim.fn.filereadable(init_lua_path) == 1 then
|
||||
utils.terminal({ "lua " .. init_lua_path })
|
||||
end
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,26 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local presets = {
|
||||
right = {
|
||||
left = 100,
|
||||
right = 0,
|
||||
top = 0,
|
||||
bottom = 0,
|
||||
},
|
||||
corner = {
|
||||
left = 100,
|
||||
right = 0,
|
||||
top = 25,
|
||||
bottom = 0,
|
||||
}
|
||||
}
|
||||
|
||||
---@param preset string
|
||||
---@return table|nil
|
||||
function M.getPresets(preset)
|
||||
if presets[preset] then
|
||||
return presets[preset]
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,10 @@
|
||||
--- Providers for bun
|
||||
---
|
||||
|
||||
--[[ React
|
||||
|
||||
--react
|
||||
--react=tailwind
|
||||
--react=shadcn
|
||||
|
||||
--]]
|
||||
Whitespace-only changes.
@@ -1,195 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.projects = {
|
||||
javascript = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root, "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "main.js" },
|
||||
[[
|
||||
console.log("Hello World!");
|
||||
]]
|
||||
)
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.js")
|
||||
end,
|
||||
},
|
||||
lua = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/lua/" .. project_name, "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "lua", project_name, "init.lua" },
|
||||
[[
|
||||
local M = {}
|
||||
|
||||
return M
|
||||
]]
|
||||
)
|
||||
local gitignore = { "" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/lua/" .. project_name .. "/init.lua")
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
for _, path in ipairs({ "/src", "/build" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
local content = [[
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
]]
|
||||
local gitignore = {
|
||||
"build/",
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
utils.write_file({ full_project_root, "src", "Main.java" }, content)
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.mkdir(full_project_root .. "/include", "p")
|
||||
utils.write_file(
|
||||
{ full_project_root, "main.py" },
|
||||
[[
|
||||
def main():
|
||||
print("Hello, World!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
]]
|
||||
)
|
||||
utils.write_file({ full_project_root, "include/__init__.py" }, "")
|
||||
utils.write_file({ full_project_root, "requirements.txt" }, "")
|
||||
utils.write_file(
|
||||
{ full_project_root, "setup.py" },
|
||||
string.format(
|
||||
[[
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="%s",
|
||||
version="0.1.0",
|
||||
packages=find_packages(),
|
||||
install_requires=[],
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
]],
|
||||
project_name
|
||||
)
|
||||
)
|
||||
local gitignore = {
|
||||
"venv/",
|
||||
}
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.cmd("edit " .. full_project_root .. "/main.py")
|
||||
local venv_path = full_project_root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
vim.g.python3_host_prog = venv_path .. "/bin/python"
|
||||
vim.fn.setenv("VIRTUAL_ENV", venv_path)
|
||||
vim.fn.setenv("PATH", venv_path .. "/bin:" .. vim.fn.getenv("PATH"))
|
||||
print("Virtual environment activated for " .. project_name)
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
vim.fn.system("cargo new " .. full_project_root)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.rs")
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root) .. "/" .. project_name
|
||||
if vim.fn.isdirectory(full_project_root) == 0 then
|
||||
vim.fn.mkdir(full_project_root, "p") -- Create directory with parent directories
|
||||
end
|
||||
local main_html_content = [[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]]
|
||||
utils.write_file({ full_project_root, "index.html" }, main_html_content)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
M.files = {
|
||||
lua = {
|
||||
run = function(file_name)
|
||||
utils.write_file({
|
||||
utils.get_project_root(),
|
||||
"lua",
|
||||
utils.get_project_name(),
|
||||
file_name .. ".lua",
|
||||
}, "")
|
||||
end,
|
||||
},
|
||||
java = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".java" },
|
||||
string.format(
|
||||
[[
|
||||
public class %s {
|
||||
// New File
|
||||
}
|
||||
]],
|
||||
file_name
|
||||
)
|
||||
)
|
||||
end,
|
||||
},
|
||||
python = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "include", file_name .. ".py" }, "")
|
||||
end,
|
||||
},
|
||||
rust = {
|
||||
run = function(file_name)
|
||||
utils.write_file({ utils.get_project_root(), "src", file_name .. ".rs" }, "")
|
||||
end,
|
||||
},
|
||||
html = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ ".", file_name .. ".html" },
|
||||
string.format([[
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>My First Heading</h1>
|
||||
<p>My first paragraph.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
]])
|
||||
)
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,115 +1,115 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: main.c
|
||||
Target: src/main.c
|
||||
--[[ =====================================================================
|
||||
template: main (entrypoint)
|
||||
file: main.c
|
||||
target: src/main.c
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
main = vim.trim([=[
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char* str = "Hello World";
|
||||
char* str = "hello world";
|
||||
printf("%s\n", str);
|
||||
return 0;
|
||||
}
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG-FORMAT (Code formatter)
|
||||
File: .clang-format
|
||||
Target: .clang-format
|
||||
--[[ =====================================================================
|
||||
template: clang-format (code formatter)
|
||||
file: .clang-format
|
||||
target: .clang-format
|
||||
===================================================================== --]]
|
||||
format = vim.trim([=[
|
||||
format = vim.trim([=[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
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
|
||||
basedonstyle: google
|
||||
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",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CMAKELISTS (Spec / Build Manifest)
|
||||
File: CMakeLists.txt
|
||||
Target: CMakeLists.txt
|
||||
--[[ =====================================================================
|
||||
template: cmakelists (spec / build manifest)
|
||||
file: cmakelists.txt
|
||||
target: cmakelists.txt
|
||||
===================================================================== --]]
|
||||
CmakeLists = vim.trim([=[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(__PROJECT_NAME__ LANGUAGES C)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
cmakelists = vim.trim([=[
|
||||
cmake_minimum_required(version 3.16)
|
||||
project(__project_name__ languages c)
|
||||
set(cmake_c_standard 23)
|
||||
set(cmake_c_standard_required on)
|
||||
set(cmake_export_compile_commands on)
|
||||
|
||||
set(LIB_SOURCES
|
||||
# Add your other types here as you implement them:
|
||||
set(lib_sources
|
||||
# add your other types here as you implement them:
|
||||
# src/example1.c
|
||||
# src/example2.c
|
||||
)
|
||||
|
||||
if(LIB_SOURCES)
|
||||
add_library(__PROJECT_NAME__ STATIC ${LIB_SOURCES})
|
||||
target_include_directories(__PROJECT_NAME__
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
if(lib_sources)
|
||||
add_library(__project_name__ static ${lib_sources})
|
||||
target_include_directories(__project_name__
|
||||
public
|
||||
${cmake_current_source_dir}/include
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(__PROJECT_NAME___bin src/main.c)
|
||||
set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__")
|
||||
add_executable(__project_name___bin src/main.c)
|
||||
set_target_properties(__project_name___bin properties output_name "__project_name__")
|
||||
|
||||
if(TARGET __PROJECT_NAME__)
|
||||
target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__)
|
||||
if(target __project_name__)
|
||||
target_link_libraries(__project_name___bin private __project_name__)
|
||||
endif()
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: HEADER (Standalone File)
|
||||
File: {name}.h
|
||||
Target: include/{project_name}/{name}.h
|
||||
--[[ =====================================================================
|
||||
template: header (standalone file)
|
||||
file: {name}.h
|
||||
target: include/{project_name}/{name}.h
|
||||
===================================================================== --]]
|
||||
header = vim.trim([=[
|
||||
#ifndef __PROJECT_NAME___H
|
||||
#define __PROJECT_NAME___H
|
||||
header = vim.trim([=[
|
||||
#ifndef __file_name___h
|
||||
#define __file_name___h
|
||||
|
||||
// Code
|
||||
// code
|
||||
|
||||
#endif /* __PROJECT_NAME___H */
|
||||
#endif /* __file_name___h */
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: SOURCE (Standalone File)
|
||||
File: {name}.c
|
||||
Target: src/{name}.c
|
||||
--[[ =====================================================================
|
||||
template: source (standalone file)
|
||||
file: {name}.c
|
||||
target: src/{name}.c
|
||||
===================================================================== --]]
|
||||
source = vim.trim([=[
|
||||
source = vim.trim([=[
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG_TIDY (LINTER)
|
||||
File: .clang-tidy
|
||||
Target: .clang-tidy
|
||||
--[[ =====================================================================
|
||||
template: clang_tidy (linter)
|
||||
file: .clang-tidy
|
||||
target: .clang-tidy
|
||||
===================================================================== --]]
|
||||
linter = vim.trim([=[
|
||||
Checks: >
|
||||
linter = vim.trim([=[
|
||||
checks: >
|
||||
-*,
|
||||
clang-analyzer-*,
|
||||
bugprone-*,
|
||||
@@ -126,12 +126,12 @@ Checks: >
|
||||
|
||||
-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
|
||||
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",
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: main.cpp
|
||||
Target: src/main.cpp
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
main = vim.trim([=[
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
@@ -16,12 +16,12 @@ main()
|
||||
}
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG-FORMAT (Code formatter)
|
||||
File: .clang-format
|
||||
Target: .clang-format
|
||||
===================================================================== --]]
|
||||
format = vim.trim([=[
|
||||
format = vim.trim([=[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
@@ -47,12 +47,12 @@ SortIncludes: CaseSensitive
|
||||
IncludeBlocks: Preserve
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CMAKELISTS (Spec / Build Manifest)
|
||||
File: CMakeLists.txt
|
||||
Target: CMakeLists.txt
|
||||
===================================================================== --]]
|
||||
CmakeLists = vim.trim([=[
|
||||
CmakeLists = vim.trim([=[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(__PROJECT_NAME__ LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
@@ -81,34 +81,34 @@ if(TARGET __PROJECT_NAME__)
|
||||
endif()
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: HEADER (Standalone File)
|
||||
File: {name}.hpp
|
||||
Target: include/{project_name}/{name}.hpp
|
||||
===================================================================== --]]
|
||||
header = vim.trim([=[
|
||||
#ifndef __PROJECT_NAME___HPP
|
||||
#define __PROJECT_NAME___HPP
|
||||
header = vim.trim([=[
|
||||
#ifndef __FILE_NAME___HPP
|
||||
#define __FILE_NAME___HPP
|
||||
|
||||
// Code
|
||||
|
||||
#endif /* __PROJECT_NAME___HPP */
|
||||
#endif /* __FILE_NAME___HPP */
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: SOURCE (Standalone File)
|
||||
File: {name}.cpp
|
||||
Target: src/{name}.cpp
|
||||
===================================================================== --]]
|
||||
source = vim.trim([=[
|
||||
source = vim.trim([=[
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG_TIDY (LINTER)
|
||||
File: .clang-tidy
|
||||
Target: .clang-tidy
|
||||
===================================================================== --]]
|
||||
linter = vim.trim([=[
|
||||
linter = vim.trim([=[
|
||||
Checks: >
|
||||
-*,
|
||||
clang-analyzer-*,
|
||||
|
||||
@@ -2,7 +2,7 @@ local M = {}
|
||||
|
||||
---@param lang string
|
||||
M.template = function(lang)
|
||||
local base = [=[
|
||||
local base = [=[
|
||||
.DS_Store
|
||||
|
||||
.vscode/
|
||||
@@ -12,8 +12,8 @@ M.template = function(lang)
|
||||
.env.*
|
||||
|
||||
]=]
|
||||
local lang_block = {
|
||||
python = vim.trim([=[
|
||||
local lang_block = {
|
||||
python = vim.trim([=[
|
||||
__pycache__/
|
||||
build/
|
||||
dist/
|
||||
@@ -23,23 +23,41 @@ venv/
|
||||
.pytest_cache/
|
||||
]=]),
|
||||
|
||||
c = vim.trim([=[
|
||||
c = vim.trim([=[
|
||||
build/
|
||||
.cache/
|
||||
]=]),
|
||||
|
||||
cpp = vim.trim([=[
|
||||
cpp = vim.trim([=[
|
||||
build/
|
||||
.cache/
|
||||
]=]),
|
||||
|
||||
lua = vim.trim([=[
|
||||
lua = vim.trim([=[
|
||||
luac.out
|
||||
]=]),
|
||||
}
|
||||
|
||||
local extra = (lang and lang_block[lang]) or ""
|
||||
return base .. extra
|
||||
java = vim.trim([=[
|
||||
bin/
|
||||
*.class
|
||||
*.jar
|
||||
]=]),
|
||||
rust = vim.trim([=[
|
||||
debug
|
||||
target
|
||||
**/*.rs.bk
|
||||
*.pdb
|
||||
**/mutants.out*/
|
||||
rustc-ice-*.txt
|
||||
#.idea/
|
||||
]=]),
|
||||
go = vim.trim([=[
|
||||
bin/
|
||||
]=]),
|
||||
}
|
||||
|
||||
local extra = (lang and lang_block[lang]) or ""
|
||||
return base .. extra
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1 @@
|
||||
return "# Hello from your fellow README.md"
|
||||
@@ -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",
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@param kind_path string Filetype of template
|
||||
---@param kind string Template in language table
|
||||
---@param name string A string to replace temp values in template
|
||||
---@return string Content Formatted string
|
||||
function M.fetch(kind_path, kind, name)
|
||||
kind, name = kind or "", name or ""
|
||||
if (kind == "" or nil) or (name == "" or nil) then
|
||||
return ""
|
||||
end
|
||||
local ok, mod = pcall(require, kind_path)
|
||||
if ok and type(mod) == "table" then
|
||||
return (string.gsub(mod[kind], "__PROJECT_NAME__", name))
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,65 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: Main.java
|
||||
Target: src/com/company/app/Main.java
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
package com.__COMPANY_NAME__.__PROJECT_NAME__;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
||||
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG-FORMAT (Code formatter)
|
||||
File: .clang-format
|
||||
Target: .clang-format
|
||||
===================================================================== --]]
|
||||
format = vim.trim([=[
|
||||
---
|
||||
Language: Java
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SeparateDefinitionBlocks: Always
|
||||
BreakAfterReturnType: TopLevel
|
||||
ReflowComments: Always
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
SortIncludes: CaseSensitive
|
||||
IncludeBlocks: Preserve
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: SOURCE (Standalone File)
|
||||
File: {name}.java
|
||||
Target: src/com/company/app/{name}.java
|
||||
===================================================================== --]]
|
||||
source = vim.trim([=[
|
||||
package com.__COMPANY_NAME__.__PROJECT_NAME__;
|
||||
|
||||
public class __FILE_NAME__ {
|
||||
|
||||
// Fields / Attributes
|
||||
private String data;
|
||||
|
||||
// Constructor
|
||||
public __FILE_NAME__() {
|
||||
}
|
||||
|
||||
// Methods
|
||||
public void doSomething() {
|
||||
|
||||
}
|
||||
}
|
||||
]=]) .. "\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",
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: main.py
|
||||
Target: src/{project_name}/main.py
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
main = vim.trim([=[
|
||||
def main() -> None:
|
||||
print("Hello from __PROJECT_NAME__!")
|
||||
|
||||
@@ -13,23 +13,23 @@ if __name__ == "__main__":
|
||||
main()
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: INIT (Package Anchor)
|
||||
File: __init__.py
|
||||
Target: src/{project_name}/__init__.py
|
||||
===================================================================== --]]
|
||||
__init__ = vim.trim([=[
|
||||
__init__ = vim.trim([=[
|
||||
# __PROJECT_NAME__ init
|
||||
|
||||
__all__: list[str] = []
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: PYPROJECT (Spec / Build Manifest)
|
||||
File: pyproject.toml
|
||||
Target: pyproject.toml
|
||||
===================================================================== --]]
|
||||
pyproject = vim.trim([=[
|
||||
pyproject = vim.trim([=[
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
@@ -46,14 +46,14 @@ dependencies = []
|
||||
__PROJECT_NAME__ = "__PROJECT_NAME__.main:main"
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MODULE (Standalone File)
|
||||
File: {name}.py
|
||||
Target: src/{project_name}/{name}.py
|
||||
===================================================================== --]]
|
||||
module = vim.trim([=[
|
||||
module = vim.trim([=[
|
||||
"""
|
||||
Module: __PROJECT_NAME__
|
||||
Module: __FILE_NAME__
|
||||
"""
|
||||
]=]) .. "\n",
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: SOURCE (Standalone File)
|
||||
File: {name}.rs
|
||||
Target: src/{name}.rs
|
||||
===================================================================== --]]
|
||||
source = vim.trim([=[
|
||||
]=]) .. "\n",
|
||||
}
|
||||
+30
-9
@@ -2,9 +2,17 @@
|
||||
---@alias SplitDirection "vertical" | "horizontal"
|
||||
---@alias SplitAnchorType "right" | "bottom"
|
||||
|
||||
---@alias VernCreateFile fun(opts: any, continue: fun(mod: VernFileLayout|nil))
|
||||
|
||||
---@class VernUserConfig
|
||||
---@field workspace_root? string
|
||||
---@field keybinds? table<string, VernKeybindItem>
|
||||
---@field terminal? VernTerminalConfig | table
|
||||
|
||||
---@class VernKeybindItem
|
||||
---@field user_command string
|
||||
---@field desc string
|
||||
---@field action function
|
||||
---@field action fun(opts: VernCoreConfig)
|
||||
|
||||
---@class VernFloatWindowConfig
|
||||
---@field padding { left: integer, right: integer, top: integer, bottom: integer }
|
||||
@@ -26,29 +34,33 @@
|
||||
---@class VernTerminalConfig
|
||||
---@field mode VernModeConfig
|
||||
|
||||
---@class VernEnvItem
|
||||
---@field author string
|
||||
|
||||
---@class VernCoreConfig
|
||||
---@field workspace_root string
|
||||
---@field env VernEnvItem
|
||||
---@field keybinds table<string, VernKeybindItem>
|
||||
---@field terminal VernTerminalConfig
|
||||
|
||||
---@class VernFileLayout
|
||||
---@field path string
|
||||
---@field name string
|
||||
---@field kind string
|
||||
---@field kind_path string
|
||||
---@field kind? string
|
||||
---@field kind_path? string
|
||||
|
||||
---@class VernExtrasLayout : VernFileLayout
|
||||
---@field enabled boolean
|
||||
---@field enabled? boolean
|
||||
|
||||
---@class VernLanguageTemplates
|
||||
---@field project table<string, VernFileLayout>
|
||||
---@field file table<string, VernFileLayout>
|
||||
---@field extras table<string, VernExtrasLayout>
|
||||
---@field project table<string, VernFileLayout>|nil
|
||||
---@field file table<string, VernFileLayout>|nil
|
||||
---@field extras table<string, VernExtrasLayout>|nil
|
||||
|
||||
---@class VernLanguageConfig
|
||||
---@field root string
|
||||
---@field dirs table<string, string>
|
||||
---@field keybinds table<string, VernKeybindItem>
|
||||
---@field dirs table<string, string>|nil
|
||||
---@field keybinds? table<string, VernKeybindItem>
|
||||
---@field templates VernLanguageTemplates
|
||||
|
||||
---@class VernPythonConfig : VernCoreConfig
|
||||
@@ -62,3 +74,12 @@
|
||||
|
||||
---@class VernLuaConfig : VernCoreConfig
|
||||
---@field lua? VernLanguageConfig
|
||||
|
||||
---@class VernJavaConfig : VernCoreConfig
|
||||
---@field java? VernLanguageConfig
|
||||
|
||||
---@class VernRustConfig : VernCoreConfig
|
||||
---@field rust? VernLanguageConfig
|
||||
|
||||
---@class VernWebConfig : VernCoreConfig
|
||||
---@field web? VernLanguageConfig
|
||||
@@ -1,154 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@param path string
|
||||
---@param content string
|
||||
function M.dump(path, content)
|
||||
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
|
||||
file:write(content)
|
||||
file:close()
|
||||
end
|
||||
|
||||
---@param str string String to replace
|
||||
---@param ctx table<string, string> Replacment characters
|
||||
---@return string
|
||||
function M.fmt(str, ctx)
|
||||
return (str:gsub("{([^}]+)}", ctx))
|
||||
end
|
||||
|
||||
---@param bufnr? integer Default is 0 (current buffer)
|
||||
function M.proj_root(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
local root_markers = {
|
||||
".git",
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"Makefile",
|
||||
"CMakeLists",
|
||||
"Cargo.toml",
|
||||
}
|
||||
return vim.fs.root(bufnr, root_markers) or vim.uv.cwd()
|
||||
end
|
||||
|
||||
---@param raw_path string Combination of tbl.path and tbl.name to override
|
||||
---@param dir_tbl table<string, string> Strings to replace raw directories in {dirs.<>} with
|
||||
---@param ctx table<string, string> Strings to replace raw names like {project_name} with
|
||||
---@return string path Fully replaced path
|
||||
function M.resolve_path(raw_path, dir_tbl, ctx)
|
||||
--- Replace the {dirs.<key>}
|
||||
raw_path = raw_path:gsub("{dirs%.([%w_]+)}", function(dir_key)
|
||||
return dir_tbl and dir_tbl[dir_key] or dir_key
|
||||
end)
|
||||
|
||||
--- Replace the {<key>}
|
||||
local path = raw_path:gsub("{([%w_]+)}", function(key)
|
||||
return ctx and ctx[key] or ("{" .. key .. "}")
|
||||
end)
|
||||
|
||||
return path
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.proj_name()
|
||||
return vim.fn.fnamemodify(M.proj_root(), ":t")
|
||||
end
|
||||
|
||||
---@param path string
|
||||
---@param ft string
|
||||
function M.init_git(path, ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or ft == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local gitignore = require("vern-nvim.templates.extras.gitignore").template(ft)
|
||||
vim.fn.system({ "git", "-C", path, "init" })
|
||||
M.dump(vim.fs.joinpath(path, ".gitignore"), gitignore)
|
||||
end
|
||||
|
||||
---@param path string
|
||||
function M.init_readme(path)
|
||||
local readme = require("vern-nvim.templates.extras.readme")
|
||||
M.dump(vim.fs.joinpath(path, "README.md"), readme)
|
||||
end
|
||||
|
||||
---@param cmd table
|
||||
---@param opts VernTerminalConfig
|
||||
---@param scratch boolean
|
||||
---@return integer, integer?
|
||||
function M.term(cmd, opts, scratch)
|
||||
opts = opts or {}
|
||||
local buf, win
|
||||
if opts.mode.type == "float" then
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
|
||||
local dim = {
|
||||
width = math.max(
|
||||
1,
|
||||
math.floor(ui.width * 0.9)
|
||||
- opts.mode.win.float.padding.left
|
||||
- opts.mode.win.float.padding.right
|
||||
),
|
||||
height = math.max(
|
||||
1,
|
||||
math.floor(ui.height * 0.9)
|
||||
- opts.mode.win.float.padding.top
|
||||
- opts.mode.win.float.padding.bottom
|
||||
),
|
||||
}
|
||||
|
||||
local pos = {
|
||||
row = math.floor(
|
||||
(ui.height - (vim.o.laststatus == 3 and 1 or 0) - vim.o.cmdheight - dim.height) / 2
|
||||
),
|
||||
col = math.floor((ui.width - dim.width) / 2),
|
||||
}
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = dim.width,
|
||||
height = dim.height,
|
||||
row = pos.row,
|
||||
col = pos.col,
|
||||
style = "minimal",
|
||||
border = opts.mode.win.float.border.enabled and opts.mode.win.float.border.type or nil,
|
||||
})
|
||||
if scratch then
|
||||
return buf, win
|
||||
end
|
||||
end
|
||||
if opts.mode.type == "split" then
|
||||
if opts.mode.win.split.direction == "vertical" then
|
||||
if opts.mode.win.split.anchor == "right" then
|
||||
vim.cmd("set splitright")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " vsplit")
|
||||
end
|
||||
if opts.mode.win.split.direction == "horizontal" then
|
||||
if opts.mode.win.split.anchor == "bottom" then
|
||||
vim.cmd("set splitbelow")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " split")
|
||||
end
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_get_current_win()
|
||||
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
if scratch then
|
||||
return buf, win
|
||||
end
|
||||
end
|
||||
local full_cmd = type(cmd) == "table" and table.concat(cmd, " ") or cmd
|
||||
vim.fn.jobstart(full_cmd, { term = true })
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
buf,
|
||||
"n",
|
||||
"<ESC>",
|
||||
"i<C-\\><C-n>:q<CR>",
|
||||
{ noremap = true, silent = true }
|
||||
)
|
||||
return buf, win
|
||||
end
|
||||
|
||||
return M
|
||||
+4
-3
@@ -1,12 +1,12 @@
|
||||
# stylua.toml
|
||||
|
||||
# How many characters per line before wrapping
|
||||
column_width = 100
|
||||
column_width = 80
|
||||
|
||||
# Indentation style: "Tabs" or "Spaces"
|
||||
line_endings = "Unix"
|
||||
indent_type = "Spaces"
|
||||
indent_width = 4
|
||||
indent_width = 2
|
||||
|
||||
# Quote styling: "AutoPreferDouble", "AutoPreferSingle", "ForceDouble", "ForceSingle"
|
||||
quote_style = "AutoPreferDouble"
|
||||
@@ -17,4 +17,5 @@ quote_style = "AutoPreferDouble"
|
||||
call_parentheses = "Always"
|
||||
|
||||
# Sorting and formatting behavior
|
||||
collapse_simple_statement = "Never"
|
||||
# collapse_simple_statement = "Never"
|
||||
collapse_simple_statement = "Always"
|
||||
Reference in new issue
Block a user