Compare commits
16
Commits
57e8eb0248
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72951f7327 | ||
|
|
4765da0539 | ||
|
|
9f4649b5d2 | ||
|
|
e8c55ec18f | ||
|
|
fcde51bc05 | ||
|
|
9eefdb6166 | ||
|
|
3046a3ce36 | ||
|
|
5eaa7d10a7 | ||
|
|
774f14809d | ||
|
|
645eeed296 | ||
|
|
4bf705df03 | ||
|
|
1c4a61ce7f | ||
|
|
b6d46a0cef | ||
|
|
685a711644 | ||
|
|
3bb97d833b | ||
|
|
df760783ba |
@@ -1,128 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
dmm.dev@pm.me.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
||||
@@ -1 +0,0 @@
|
||||
- Its really simple. Just if you see an error/bug, enhancment or feature to be improved on just make an issue or make a pr.
|
||||
@@ -5,8 +5,8 @@
|
||||
<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-Apache-yellow.svg?style=for-the-badge" />
|
||||
<img src="https://img.shields.io/badge/Docs-Available-blue?style=for-the-badge&logo=readthedocs&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>
|
||||
|
||||
|
||||
@@ -22,16 +22,16 @@ NOTE: The plugin may not work well with lazy or any other package manager other
|
||||
* Integrated terminal for flexible command execution
|
||||
* Minimal configuration with extensibility in mind
|
||||
|
||||
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern.nvim/wiki/Home$0) for setup, configuration, and usage details.
|
||||
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern-nvim.nvim/wiki/Home$0) for setup, configuration, and usage details.
|
||||
|
||||
## Supported Languages
|
||||
|
||||
Vern.nvim currently supports the following languages:
|
||||
|
||||
* Python
|
||||
<!-- * Java -->
|
||||
<!-- * C / C++ -->
|
||||
<!-- * Lua -->
|
||||
* C / C++
|
||||
* Lua
|
||||
* Java
|
||||
<!-- * Rust -->
|
||||
<!-- * HTML -->
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
|
||||
---@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
|
||||
|
||||
---@param opts VernCConfig
|
||||
M.create_file = function(opts)
|
||||
opts = opts or {}
|
||||
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 mod = {}
|
||||
if ft == "c" then
|
||||
mod = opts.c.templates.file.source or {}
|
||||
end
|
||||
if ft == "h" then
|
||||
mod = opts.c.templates.file.header or {}
|
||||
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 raw_path = vim.fs.joinpath(mod.path, mod.name)
|
||||
local context = {
|
||||
project_name = utils.proj_name(),
|
||||
company_name = opts.env.author,
|
||||
file_name = fname,
|
||||
}
|
||||
local path = utils.resolve_path(raw_path, opts.c.dirs or {}, context)
|
||||
local root = utils.proj_root()
|
||||
utils.dump(
|
||||
vim.fs.joinpath(root, path),
|
||||
require("vern-nvim.templates").fetch(mod.kind_path, mod.kind, context)
|
||||
)
|
||||
vim.cmd.edit(vim.fn.expand(path))
|
||||
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
|
||||
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
|
||||
@@ -0,0 +1,83 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
|
||||
---@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
|
||||
|
||||
---@param opts VernCPPConfig
|
||||
M.create_file = function(opts)
|
||||
opts = opts or {}
|
||||
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 mod = {}
|
||||
if ft == "c" then
|
||||
mod = opts.cpp.templates.file.source or {}
|
||||
end
|
||||
if ft == "h" then
|
||||
mod = opts.cpp.templates.file.header or {}
|
||||
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 raw_path = vim.fs.joinpath(mod.path, mod.name)
|
||||
local context = {
|
||||
project_name = utils.proj_name(),
|
||||
company_name = opts.env.author,
|
||||
file_name = fname,
|
||||
}
|
||||
local path = utils.resolve_path(raw_path, opts.cpp.dirs or {}, context)
|
||||
local root = utils.proj_root()
|
||||
utils.dump(
|
||||
vim.fs.joinpath(root, path),
|
||||
require("vern-nvim.templates").fetch(mod.kind_path, mod.kind, context)
|
||||
)
|
||||
vim.cmd.edit(vim.fn.expand(path))
|
||||
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
|
||||
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
|
||||
@@ -0,0 +1,150 @@
|
||||
local M = {}
|
||||
|
||||
---TODO
|
||||
---Split filetype only and just change a filetype variable and vairables both share and then run the duplicate code
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
local templates = require("vern-nvim.templates")
|
||||
|
||||
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
|
||||
vim.notify("Unknown Filetype: " .. ft, vim.log.levels.WARN, {
|
||||
title = "Vern Project",
|
||||
})
|
||||
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 {})
|
||||
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")
|
||||
|
||||
for _, dir in pairs(args[ft].dirs) do
|
||||
local path = vim.fs.normalize(vim.fs.joinpath(root, utils.fmt(dir, ctx)))
|
||||
vim.fn.mkdir(path, "p")
|
||||
end
|
||||
|
||||
local bin
|
||||
for tbl_name, tbl in pairs(args[ft].templates.project) do
|
||||
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, args[ft].dirs, ctx)
|
||||
if tbl_name == "primary" then
|
||||
bin = vim.fs.joinpath(root, path)
|
||||
end
|
||||
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
|
||||
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, ctx))
|
||||
end
|
||||
for _, tbl in pairs(args[ft].templates.extras) do
|
||||
if tbl.enabled then
|
||||
local raw_path = vim.fs.joinpath(tbl.path, tbl.name)
|
||||
local path = utils.resolve_path(raw_path, args[ft].dirs, ctx)
|
||||
local abs_file_path = vim.fs.normalize(vim.fs.joinpath(root, path))
|
||||
local abs_dir_path = vim.fs.dirname(abs_file_path)
|
||||
if abs_dir_path ~= root and not vim.startswith(root, abs_dir_path) then
|
||||
vim.fn.mkdir(abs_dir_path, "p")
|
||||
end
|
||||
utils.dump(abs_file_path, templates.fetch(tbl.kind_path, tbl.kind, ctx))
|
||||
end
|
||||
end
|
||||
|
||||
utils.init_git(root, ft)
|
||||
utils.init_readme(root)
|
||||
if ok and actions and type(actions.create_project) == "function" then
|
||||
actions.create_project(root)
|
||||
end
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
vim.notify(
|
||||
"Project: " .. pname .. " has been created!",
|
||||
vim.log.levels.INFO,
|
||||
{ title = "Vern Project" }
|
||||
)
|
||||
end)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
M.create_file = function(opts)
|
||||
opts = opts or {}
|
||||
local filetype = vim.bo.filetype
|
||||
|
||||
local function continue_filetype(ft)
|
||||
filetype = ft
|
||||
local ok, actions = pcall(require, "vern-nvim.actions." .. filetype)
|
||||
if not ok then
|
||||
vim.notify("Unknown Filetype: " .. filetype, vim.log.levels.WARN, {
|
||||
title = "Vern File",
|
||||
})
|
||||
return
|
||||
end
|
||||
local configs = require("vern-nvim.configs." .. filetype)
|
||||
local args = vim.tbl_deep_extend("force", {}, configs, 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 mod
|
||||
if ok and actions and type(actions.create_file) == "function" then
|
||||
mod = actions.create_file(args[filetype])
|
||||
or args[filetype].templates.file.source
|
||||
or {}
|
||||
end
|
||||
local raw_path = vim.fs.joinpath(mod.path, mod.name)
|
||||
local context = {
|
||||
project_name = utils.proj_name(),
|
||||
company_name = opts.env.author,
|
||||
file_name = fname,
|
||||
}
|
||||
local path = utils.resolve_path(raw_path, args[filetype].dirs or {}, context)
|
||||
local root = utils.proj_root()
|
||||
utils.dump(
|
||||
vim.fs.joinpath(root, path),
|
||||
templates.fetch(mod.kind_path, mod.kind, context)
|
||||
)
|
||||
vim.cmd.edit(vim.fn.fnameescape(path))
|
||||
vim.notify(fname .. " has been created!", vim.log.levels.INFO, { title = "Vern File" })
|
||||
end)
|
||||
end
|
||||
|
||||
local ft_ok, ft_config = pcall(require, "vern-nvim.configs." .. filetype)
|
||||
if not filetype or filetype == "" or not ft_ok or type(ft_config) ~= "table" then
|
||||
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
|
||||
continue_filetype(ft)
|
||||
end)
|
||||
else
|
||||
continue_filetype(filetype)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,58 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
|
||||
M.create_project = function() end
|
||||
|
||||
M.create_file = function() end
|
||||
|
||||
---@param opts VernJavaConfig Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local context = {
|
||||
project_name = utils.proj_name(),
|
||||
company_name = opts.env.author,
|
||||
file_name = "",
|
||||
}
|
||||
|
||||
local src_root =
|
||||
vim.fs.joinpath(root, utils.resolve_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
|
||||
)
|
||||
|
||||
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 = string.format(
|
||||
"java -cp %s com.%s.%s.Main",
|
||||
build_dir,
|
||||
context.company_name,
|
||||
context.project_name
|
||||
)
|
||||
utils.term({ run_cmd }, opts.terminal, false)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,21 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
|
||||
M.create_project = function() end
|
||||
|
||||
M.create_file = function() 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 = vim.fs.joinpath(root, "lua", pname)
|
||||
print(full_path .. "/init.lua")
|
||||
|
||||
utils.term({ "lua " .. full_path .. "/init.lua" }, opts.terminal or {}, false)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,49 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern-nvim.utils")
|
||||
|
||||
---@param root string
|
||||
M.create_project = function(root)
|
||||
vim.fn.system("python3 -m venv " .. root .. "/venv")
|
||||
end
|
||||
|
||||
M.create_file = function() end
|
||||
|
||||
---@param opts VernPythonConfig Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local context = {
|
||||
project_name = utils.proj_name(),
|
||||
company_name = opts.env.author,
|
||||
file_name = "",
|
||||
}
|
||||
local bin = opts.python.templates.project.primary
|
||||
|
||||
local exe = vim.fs.joinpath(bin.path, bin.name) or "src/{project_name}/main.py"
|
||||
local exe_path = utils.resolve_path(exe, opts.python.dirs, context)
|
||||
local full_path = vim.fs.joinpath(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
|
||||
@@ -0,0 +1,71 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.c = {
|
||||
root = "C",
|
||||
dirs = {
|
||||
src = "src",
|
||||
include = "include/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
user_command = "CRun",
|
||||
desc = "Executes c code",
|
||||
action = require("vern-nvim.actions.c").run,
|
||||
},
|
||||
["<leader>pf"] = {
|
||||
user_command = "CCreateFile",
|
||||
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 = "{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,71 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.cpp = {
|
||||
root = "CPP",
|
||||
dirs = {
|
||||
src = "src",
|
||||
include = "include/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
user_command = "CPPRun",
|
||||
desc = "Executes cpp code",
|
||||
action = require("vern-nvim.actions.cpp").run,
|
||||
},
|
||||
["<leader>pf"] = {
|
||||
user_command = "CPPCreateFile",
|
||||
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 = "{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
|
||||
@@ -1,19 +1,27 @@
|
||||
local actions = require("vern.actions")
|
||||
local actions = require("vern-nvim.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",
|
||||
action = actions.create_file,
|
||||
},
|
||||
},
|
||||
terminal = {
|
||||
mode = {
|
||||
type = "split", --- can be split or float
|
||||
type = "split",
|
||||
win = {
|
||||
float = {
|
||||
padding = {
|
||||
@@ -24,12 +32,12 @@ return {
|
||||
},
|
||||
border = {
|
||||
enabled = true,
|
||||
type = vim.o.winborder,
|
||||
type = vim.o.winborder, -- defaults to neovim winborder
|
||||
},
|
||||
},
|
||||
split = {
|
||||
type = "horizontal", --- can be vertical or horizontal
|
||||
anchor = "bottom", --- can be right or bottom
|
||||
direction = "horizontal",
|
||||
anchor = "bottom",
|
||||
size = "20",
|
||||
},
|
||||
},
|
||||
@@ -0,0 +1,45 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.java = {
|
||||
root = "Java",
|
||||
dirs = {
|
||||
src = "src/com/{company_name}/{project_name}",
|
||||
bin = "bin",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
user_command = "JavaRun",
|
||||
desc = "Executes java code",
|
||||
action = require("vern-nvim.actions.java").run,
|
||||
},
|
||||
},
|
||||
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 = {},
|
||||
},
|
||||
}
|
||||
return M
|
||||
@@ -0,0 +1,45 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function() end
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.lua = {
|
||||
root = "Lua",
|
||||
dirs = {
|
||||
src = "lua/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
user_command = "LuaRun",
|
||||
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 = "{file_name}.lua",
|
||||
kind = "source",
|
||||
kind_path = "vern-nvim.templates.lua",
|
||||
},
|
||||
},
|
||||
extras = {},
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,70 @@
|
||||
local M = {}
|
||||
|
||||
M.attach = function()
|
||||
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
|
||||
|
||||
---@type VernLanguageConfig
|
||||
M.python = {
|
||||
root = "Python",
|
||||
dirs = {
|
||||
src = "src/{project_name}",
|
||||
},
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
user_command = "Pythonrun",
|
||||
desc = "Executes python code",
|
||||
action = require("vern-nvim.actions.python").run,
|
||||
},
|
||||
["<leader>pi"] = {
|
||||
user_command = "Pythonpip",
|
||||
desc = "Install python packages for environment",
|
||||
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 = "{file_name}.py",
|
||||
kind = "module",
|
||||
kind_path = "vern-nvim.templates.python",
|
||||
},
|
||||
},
|
||||
extras = {},
|
||||
},
|
||||
}
|
||||
return M
|
||||
@@ -0,0 +1,72 @@
|
||||
local M = {}
|
||||
|
||||
local configs = require("vern-nvim.configs")
|
||||
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.deepcopy(configs)
|
||||
|
||||
---@class VernUserConfig
|
||||
---@field workspace_root? string
|
||||
---@field keybinds? table<string, VernKeybindItem>
|
||||
---@field terminal? VernTerminalConfig | table
|
||||
|
||||
---@param user_opts? VernUserConfig
|
||||
function M.setup(user_opts)
|
||||
---@type VernCoreConfig
|
||||
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
||||
|
||||
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
|
||||
|
||||
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 has_config, mod = pcall(require, "vern-nvim.configs." .. ft)
|
||||
if not has_config then
|
||||
return
|
||||
end
|
||||
|
||||
local opts = vim.tbl_deep_extend("force", {}, mod, M.opts or {})
|
||||
if opts[ft] and opts[ft].keybinds 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
|
||||
local ok, attach_mod = pcall(require, "vern-nvim.configs." .. ft)
|
||||
if ok and type(attach_mod.attach) == "function" then
|
||||
attach_mod.attach(args.buf, opts)
|
||||
end
|
||||
end,
|
||||
desc = "Attach languages to buffer",
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,87 @@
|
||||
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,
|
||||
},
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,82 @@
|
||||
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,
|
||||
},
|
||||
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 = {
|
||||
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
|
||||
@@ -0,0 +1,137 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: main.c
|
||||
Target: src/main.c
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char* str = "Hello World";
|
||||
printf("%s\n", str);
|
||||
return 0;
|
||||
}
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG-FORMAT (Code formatter)
|
||||
File: .clang-format
|
||||
Target: .clang-format
|
||||
===================================================================== --]]
|
||||
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
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
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)
|
||||
|
||||
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
|
||||
)
|
||||
endif()
|
||||
|
||||
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__)
|
||||
endif()
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: HEADER (Standalone File)
|
||||
File: {name}.h
|
||||
Target: include/{project_name}/{name}.h
|
||||
===================================================================== --]]
|
||||
header = vim.trim([=[
|
||||
#ifndef __FILE_NAME___H
|
||||
#define __FILE_NAME___H
|
||||
|
||||
// Code
|
||||
|
||||
#endif /* __FILE_NAME___H */
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: SOURCE (Standalone File)
|
||||
File: {name}.c
|
||||
Target: src/{name}.c
|
||||
===================================================================== --]]
|
||||
source = vim.trim([=[
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG_TIDY (LINTER)
|
||||
File: .clang-tidy
|
||||
Target: .clang-tidy
|
||||
===================================================================== --]]
|
||||
linter = vim.trim([=[
|
||||
Checks: >
|
||||
-*,
|
||||
clang-analyzer-*,
|
||||
bugprone-*,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-bugprone-reserved-identifier,
|
||||
performance-*,
|
||||
security-*
|
||||
|
||||
readability-redundant-declaration
|
||||
readability-misleading-indentation
|
||||
readability-implicit-bool-conversion
|
||||
misc-misplaced-const,
|
||||
misc-include-cleaner
|
||||
|
||||
-bugprone-narrowing-conversions,
|
||||
-readability-identifier-length
|
||||
CheckOptions:
|
||||
readability-identifier-naming.VariableCase: lower_case
|
||||
readability-identifier-naming.FunctionCase: lower_case
|
||||
readability-identifier-naming.StructCase: lower_case
|
||||
readability-identifier-naming.EnumCase: CamelCase
|
||||
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
|
||||
]=]) .. "\n",
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
return {
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: MAIN (Entrypoint)
|
||||
File: main.cpp
|
||||
Target: src/main.cpp
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
std::string str = "Hello World";
|
||||
std::cout << str << "\n";
|
||||
return 0;
|
||||
}
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG-FORMAT (Code formatter)
|
||||
File: .clang-format
|
||||
Target: .clang-format
|
||||
===================================================================== --]]
|
||||
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
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CMAKELISTS (Spec / Build Manifest)
|
||||
File: CMakeLists.txt
|
||||
Target: CMakeLists.txt
|
||||
===================================================================== --]]
|
||||
CmakeLists = vim.trim([=[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(__PROJECT_NAME__ LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(LIB_SOURCES
|
||||
# Add your other types here as you implement them:
|
||||
# src/example1.cpp
|
||||
# src/example2.cpp
|
||||
)
|
||||
|
||||
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.cpp)
|
||||
set_target_properties(__PROJECT_NAME___bin PROPERTIES OUTPUT_NAME "__PROJECT_NAME__")
|
||||
|
||||
if(TARGET __PROJECT_NAME__)
|
||||
target_link_libraries(__PROJECT_NAME___bin PRIVATE __PROJECT_NAME__)
|
||||
endif()
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: HEADER (Standalone File)
|
||||
File: {name}.hpp
|
||||
Target: include/{project_name}/{name}.hpp
|
||||
===================================================================== --]]
|
||||
header = vim.trim([=[
|
||||
#ifndef __FILE_NAME___HPP
|
||||
#define __FILE_NAME___HPP
|
||||
|
||||
// Code
|
||||
|
||||
#endif /* __FILE_NAME___HPP */
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: SOURCE (Standalone File)
|
||||
File: {name}.cpp
|
||||
Target: src/{name}.cpp
|
||||
===================================================================== --]]
|
||||
source = vim.trim([=[
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
TEMPLATE: CLANG_TIDY (LINTER)
|
||||
File: .clang-tidy
|
||||
Target: .clang-tidy
|
||||
===================================================================== --]]
|
||||
linter = vim.trim([=[
|
||||
Checks: >
|
||||
-*,
|
||||
clang-analyzer-*,
|
||||
bugprone-*,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-bugprone-reserved-identifier,
|
||||
performance-*,
|
||||
security-*
|
||||
|
||||
readability-redundant-declaration
|
||||
readability-misleading-indentation
|
||||
readability-implicit-bool-conversion
|
||||
misc-misplaced-const,
|
||||
misc-include-cleaner
|
||||
|
||||
-bugprone-narrowing-conversions,
|
||||
-readability-identifier-length
|
||||
CheckOptions:
|
||||
readability-identifier-naming.VariableCase: lower_case
|
||||
readability-identifier-naming.FunctionCase: lower_case
|
||||
readability-identifier-naming.StructCase: lower_case
|
||||
readability-identifier-naming.EnumCase: CamelCase
|
||||
readability-identifier-naming.EnumConstantCase: UPPER_CASE
|
||||
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
|
||||
]=]) .. "\n",
|
||||
}
|
||||
+20
@@ -22,6 +22,26 @@ env/
|
||||
venv/
|
||||
.pytest_cache/
|
||||
]=]),
|
||||
|
||||
c = vim.trim([=[
|
||||
build/
|
||||
.cache/
|
||||
]=]),
|
||||
|
||||
cpp = vim.trim([=[
|
||||
build/
|
||||
.cache/
|
||||
]=]),
|
||||
|
||||
lua = vim.trim([=[
|
||||
luac.out
|
||||
]=]),
|
||||
|
||||
java = vim.trim([=[
|
||||
bin/
|
||||
*.class
|
||||
*.jar
|
||||
]=]),
|
||||
}
|
||||
|
||||
local extra = (lang and lang_block[lang]) or ""
|
||||
@@ -0,0 +1 @@
|
||||
return "# Hello from your fellow README.md"
|
||||
@@ -0,0 +1,37 @@
|
||||
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,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",
|
||||
}
|
||||
@@ -6,7 +6,7 @@ return {
|
||||
===================================================================== --]]
|
||||
main = vim.trim([=[
|
||||
def main() -> None:
|
||||
print("Hello from %s!")
|
||||
print("Hello from __PROJECT_NAME__!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -19,7 +19,7 @@ if __name__ == "__main__":
|
||||
Target: src/{project_name}/__init__.py
|
||||
===================================================================== --]]
|
||||
__init__ = vim.trim([=[
|
||||
# %s init
|
||||
# __PROJECT_NAME__ init
|
||||
|
||||
__all__: list[str] = []
|
||||
]=]) .. "\n",
|
||||
@@ -35,15 +35,15 @@ requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "%s"
|
||||
name = "__PROJECT_NAME__"
|
||||
version = "0.1.0"
|
||||
description = "Project %s"
|
||||
description = "Project __PROJECT_NAME__"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = []
|
||||
|
||||
[project.scripts]
|
||||
%s = "%s.main:main"
|
||||
__PROJECT_NAME__ = "__PROJECT_NAME__.main:main"
|
||||
]=]) .. "\n",
|
||||
|
||||
--[[ =====================================================================
|
||||
@@ -53,7 +53,7 @@ dependencies = []
|
||||
===================================================================== --]]
|
||||
module = vim.trim([=[
|
||||
"""
|
||||
Module: %s
|
||||
Module: __FILE_NAME__
|
||||
"""
|
||||
]=]) .. "\n",
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
---@alias TerminalModeType "split" | "float"
|
||||
---@alias SplitDirection "vertical" | "horizontal"
|
||||
---@alias SplitAnchorType "right" | "bottom"
|
||||
|
||||
---@class VernKeybindItem
|
||||
---@field user_command string
|
||||
---@field desc string
|
||||
---@field action function
|
||||
|
||||
---@class VernFloatWindowConfig
|
||||
---@field padding { left: integer, right: integer, top: integer, bottom: integer }
|
||||
---@field border { enabled: boolean, type: string }
|
||||
|
||||
---@class VernSplitWindowConfig
|
||||
---@field direction SplitDirection
|
||||
---@field anchor SplitAnchorType
|
||||
---@field size string
|
||||
|
||||
---@class VernWindowConfig
|
||||
---@field float VernFloatWindowConfig
|
||||
---@field split VernSplitWindowConfig
|
||||
|
||||
---@class VernModeConfig
|
||||
---@field type TerminalModeType
|
||||
---@field win VernWindowConfig
|
||||
|
||||
---@class VernTerminalConfig
|
||||
---@field mode VernModeConfig
|
||||
|
||||
---@class 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
|
||||
|
||||
---@class VernExtrasLayout : VernFileLayout
|
||||
---@field enabled boolean
|
||||
|
||||
---@class VernLanguageTemplates
|
||||
---@field project table<string, VernFileLayout>
|
||||
---@field file table<string, VernFileLayout>
|
||||
---@field extras table<string, VernExtrasLayout>
|
||||
|
||||
---@class VernLanguageConfig
|
||||
---@field root string
|
||||
---@field dirs table<string, string>
|
||||
---@field keybinds table<string, VernKeybindItem>
|
||||
---@field templates VernLanguageTemplates
|
||||
|
||||
---@class VernPythonConfig : VernCoreConfig
|
||||
---@field python? VernLanguageConfig
|
||||
|
||||
---@class VernCConfig : VernCoreConfig
|
||||
---@field c? VernLanguageConfig
|
||||
|
||||
---@class VernCPPConfig : VernCoreConfig
|
||||
---@field cpp? VernLanguageConfig
|
||||
|
||||
---@class VernLuaConfig : VernCoreConfig
|
||||
---@field lua? VernLanguageConfig
|
||||
---
|
||||
---@class VernJavaConfig : VernCoreConfig
|
||||
---@field java? VernLanguageConfig
|
||||
@@ -8,6 +8,9 @@ function M.dump(path, 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
|
||||
@@ -26,6 +29,24 @@ function M.proj_root(bufnr)
|
||||
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")
|
||||
@@ -39,14 +60,22 @@ function M.init_git(path, ft)
|
||||
return
|
||||
end
|
||||
|
||||
local gitignore = require("vern.templates.extras.gitignore").template(ft)
|
||||
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)
|
||||
function M.term(cmd, opts, scratch)
|
||||
opts = opts or {}
|
||||
local buf, win
|
||||
if opts.mode.type == "float" then
|
||||
@@ -84,15 +113,18 @@ function M.term(cmd, opts)
|
||||
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.type == "vertical" 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.type == "horizontal" then
|
||||
if opts.mode.win.split.direction == "horizontal" then
|
||||
if opts.mode.win.split.anchor == "bottom" then
|
||||
vim.cmd("set splitbelow")
|
||||
end
|
||||
@@ -103,8 +135,12 @@ function M.term(cmd, opts)
|
||||
win = vim.api.nvim_get_current_win()
|
||||
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
if scratch then
|
||||
return buf, win
|
||||
end
|
||||
end
|
||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
||||
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",
|
||||
@@ -116,12 +152,3 @@ function M.term(cmd, opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
-- function M.exists(path)
|
||||
-- return (io.open(path, "r") ~= nil)
|
||||
-- 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.actions." .. ft)
|
||||
local configs = require("vern.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.actions." .. ft)
|
||||
local configs = require("vern.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,85 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
local utils = require("vern.utils")
|
||||
local templates = require("vern.templates")
|
||||
|
||||
local join, get = vim.fs.joinpath, vim.tbl_get
|
||||
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.configs")
|
||||
local pconfigs = require("vern.configs.python")
|
||||
|
||||
local cfg = vim.tbl_deep_extend("force", {}, configs, pconfigs, opts or {})
|
||||
local ctx = { project_name = pname }
|
||||
local py = cfg.python
|
||||
|
||||
local root = join(vim.fn.expand(cfg.workspace_root), py.root, pname)
|
||||
vim.fn.mkdir(join(root, utils.fmt(py.source_root, ctx)), "p")
|
||||
|
||||
local tmpl = get(py, "templates", "project") or {}
|
||||
local function dump(k, alt, id)
|
||||
local path = join(root, utils.fmt(get(tmpl, k, "target") or alt, ctx))
|
||||
utils.dump(path, templates.fetch("python", id, pname))
|
||||
return path
|
||||
end
|
||||
|
||||
local bin = dump("bin", "src/{project_name}/main.py", "main")
|
||||
dump("pkg", "src/{project_name}/__init__.py", "__init__")
|
||||
dump("spec", "pyproject.toml", "pyproject")
|
||||
utils.init_git(root, "python")
|
||||
|
||||
local venv_path = root .. "/venv"
|
||||
vim.fn.system("python3 -m venv " .. venv_path)
|
||||
|
||||
vim.cmd.edit(vim.fn.fnameescape(bin))
|
||||
end)
|
||||
end
|
||||
|
||||
function M.create_file(opts)
|
||||
vim.ui.input({ prompt = "Enter file name: " }, function(fname)
|
||||
fname = fname and vim.trim(fname)
|
||||
if not fname or fname == "" then
|
||||
return
|
||||
end
|
||||
local root = get(opts, "python", "templates", "file", "module").target or {}
|
||||
local context = { project_name = utils.proj_name(), name = fname }
|
||||
local path = join(utils.proj_root(), utils.fmt(root, context))
|
||||
utils.dump(path, templates.fetch("python", "module", fname))
|
||||
vim.cmd.edit(vim.fn.expand(path))
|
||||
end)
|
||||
end
|
||||
|
||||
--- Goal is to add providers for uv and venv so its available to more users
|
||||
---@param opts? table Takes a table for the runtime
|
||||
function M.run(opts)
|
||||
opts = opts or {}
|
||||
local root = utils.proj_root() or "."
|
||||
local pname = vim.fs.basename(root)
|
||||
|
||||
local exe = opts.python.templates.project.bin.target or "src/%s/main.py"
|
||||
local full_path = vim.fn.expand(root, utils.fmt(exe, { project_name = pname }))
|
||||
utils.term({ "python3 " .. full_path }, opts.terminal or {})
|
||||
end
|
||||
|
||||
---@param cmd_args? table Takes a table for the runtime
|
||||
function M.pip_install(opts, cmd_args)
|
||||
local args = cmd_args and cmd_args.args and vim.trim(cmd_args.args) or ""
|
||||
if args ~= "" then
|
||||
utils.term({ "pip install " .. args }, opts.terminal or {})
|
||||
return
|
||||
end
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||
if not pip_module or vim.trim(pip_module) == "" then
|
||||
vim.notify("Pip Cancelled", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
utils.term({ "pip install " .. vim.trim(pip_module) }, opts.terminal or {})
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,44 +0,0 @@
|
||||
local actions = require("vern.actions.python")
|
||||
local config = require("vern.configs.python")
|
||||
|
||||
return function(bufnr, user_opts)
|
||||
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(cmd_args)
|
||||
if actions.pip_install then
|
||||
actions.pip_install(opts, cmd_args)
|
||||
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.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
|
||||
@@ -1,40 +0,0 @@
|
||||
return {
|
||||
python = {
|
||||
root = "Python",
|
||||
source_root = "src/{project_name}",
|
||||
keybinds = {
|
||||
["<leader>pr"] = {
|
||||
desc = "Executes python code",
|
||||
action = require("vern.actions.python").run,
|
||||
},
|
||||
["<leader>pb"] = {
|
||||
desc = "Asks for what python package to install",
|
||||
action = require("vern.actions.python").pip_install,
|
||||
},
|
||||
},
|
||||
templates = {
|
||||
project = {
|
||||
["bin"] = {
|
||||
target = "src/{project_name}/main.py",
|
||||
},
|
||||
["pkg"] = {
|
||||
target = "src/{project_name}/__init__.py",
|
||||
},
|
||||
["spec"] = {
|
||||
target = "pyproject.toml",
|
||||
},
|
||||
},
|
||||
file = {
|
||||
["module"] = {
|
||||
target = "src/{project_name}/{name}.py",
|
||||
},
|
||||
},
|
||||
extras = {
|
||||
["gitignore"] = {
|
||||
template = "vern.templates.extras.gitignore", --- needs to call the function in file
|
||||
target = ".gitignore",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
function M.test()
|
||||
vim.ui.input({ prompt = "Test: ", default = "" }, function(input)
|
||||
print(input)
|
||||
end)
|
||||
end
|
||||
|
||||
local configs = require("vern.configs")
|
||||
local actions = require("vern.actions")
|
||||
M.opts = {}
|
||||
|
||||
function M.setup(user_opts)
|
||||
M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
|
||||
|
||||
--- Bind global keybinds
|
||||
for key, def in pairs(M.opts.keybinds or {}) do
|
||||
if type(def.action) == "function" then
|
||||
vim.keymap.set("n", key, function()
|
||||
def.action(M.opts)
|
||||
end, {
|
||||
silent = true,
|
||||
desc = def.desc,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
--- Load project cmdline commands
|
||||
vim.api.nvim_create_user_command("VernCreateProject", function()
|
||||
if actions.create_project then
|
||||
actions.create_project(M.opts)
|
||||
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" })
|
||||
|
||||
--- Create group and attach based on ft
|
||||
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.attach." .. ft)
|
||||
if ok and type(attach) == "function" then
|
||||
attach(args.buf, M.opts)
|
||||
end
|
||||
end,
|
||||
desc = "Attach languages to buffer",
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,285 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
local configs = require("Polydev.configs")
|
||||
local M = {}
|
||||
|
||||
local loaded_languages = {}
|
||||
|
||||
---@param lang string
|
||||
---@param opts? table
|
||||
---@return boolean
|
||||
function M.load_language_module(lang, opts)
|
||||
if loaded_languages[lang] then
|
||||
return true
|
||||
end
|
||||
|
||||
local ok, mod = pcall(require, "Polydev.languages")
|
||||
if not ok or type(mod.languages) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
local lang_mod = mod.languages[lang]
|
||||
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then
|
||||
return false
|
||||
end
|
||||
|
||||
lang_mod:setup(opts and opts[lang] or {})
|
||||
loaded_languages[lang] = lang_mod
|
||||
return true
|
||||
end
|
||||
|
||||
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,
|
||||
},
|
||||
c = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success 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 })
|
||||
end
|
||||
if success then
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||
utils.terminal({ run_cmd })
|
||||
end
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("cpp"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("CppRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, _ in pairs(opts.keybinds) do
|
||||
vim.keymap.set("n", key, ":CppRun<CR>", { silent = true })
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local root = utils.get_project_root()
|
||||
local build_dir = root .. "/build"
|
||||
|
||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||
local output = vim.fn.system(cmd)
|
||||
local success = vim.v.shell_error == 0
|
||||
|
||||
if not success 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 })
|
||||
end
|
||||
if success then
|
||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||
utils.terminal({ run_cmd })
|
||||
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,
|
||||
},
|
||||
python = {
|
||||
setup = function(self, user_opts)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {})
|
||||
vim.api.nvim_create_user_command("PythonPip", function()
|
||||
self:install_dependency()
|
||||
end, {})
|
||||
vim.api.nvim_create_user_command("PythonRun", function()
|
||||
self:run()
|
||||
end, {})
|
||||
for key, command in pairs(opts.keybinds) do
|
||||
if command == "PythonRun" then
|
||||
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
|
||||
end
|
||||
if command == "PythonPip" then
|
||||
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
|
||||
end
|
||||
end
|
||||
|
||||
local root = utils.get_project_root()
|
||||
if root then
|
||||
local venv_path = root .. "/venv/bin/activate"
|
||||
if vim.fn.filereadable(venv_path) == 1 then
|
||||
vim.env.VIRTUAL_ENV = venv_path
|
||||
vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH
|
||||
end
|
||||
end
|
||||
end,
|
||||
install_dependency = function()
|
||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||
if not pip_module or pip_module == "" then
|
||||
return print("Pip canceled")
|
||||
end
|
||||
utils.terminal({ "pip install " .. pip_module })
|
||||
end)
|
||||
end,
|
||||
run = function()
|
||||
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||
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
|
||||
@@ -1,487 +0,0 @@
|
||||
local utils = require("Polydev.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function extras(guard, file_type, file_name)
|
||||
if not file_name then
|
||||
return print("Header file creation canceled")
|
||||
end
|
||||
local guard_macro = file_name:upper():gsub("[^A-Z0-9]", "_") .. guard
|
||||
local content = string.format(
|
||||
[[
|
||||
#ifndef %s
|
||||
#define %s
|
||||
|
||||
// Add code here
|
||||
|
||||
#endif
|
||||
]],
|
||||
guard_macro,
|
||||
guard_macro
|
||||
)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "include", file_name .. file_type },
|
||||
content
|
||||
)
|
||||
end
|
||||
|
||||
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,
|
||||
},
|
||||
c = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-format" },
|
||||
[[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
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
|
||||
]]
|
||||
)
|
||||
utils.write_file(
|
||||
{ full_project_root, "src/main.c" },
|
||||
[[
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-tidy" },
|
||||
string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]])
|
||||
)
|
||||
utils.write_file(
|
||||
{ full_project_root, "CMakeLists.txt" },
|
||||
string.format(
|
||||
[[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_C_STANDARD 23)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
include_directories(include)
|
||||
project(%s LANGUAGES C)
|
||||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]],
|
||||
project_name,
|
||||
project_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(
|
||||
string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root
|
||||
)
|
||||
)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.c")
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
run = function(project_name, project_root)
|
||||
local full_project_root = vim.fn.expand(project_root)
|
||||
.. "/"
|
||||
.. project_name
|
||||
for _, path in ipairs({ "/src", "/build", "/include" }) do
|
||||
vim.fn.mkdir(full_project_root .. path, "p")
|
||||
end
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-format" },
|
||||
[[
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
Standard: Latest
|
||||
UseTab: Always
|
||||
TabWidth: 8
|
||||
IndentWidth: 8
|
||||
BreakBeforeBraces: Allman
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SeparateDefinitionBlocks: Always
|
||||
Cpp11BracedListStyle: false
|
||||
BreakAfterReturnType: TopLevel
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
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
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, "src/main.cpp" },
|
||||
[[
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World\n";
|
||||
return 0;
|
||||
}
|
||||
]]
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, ".clang-tidy" },
|
||||
string.format([[
|
||||
---
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
concurrency-*,
|
||||
misc-*,
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
portability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-implicit-bool-conversion
|
||||
|
||||
WarningsAsErrors: ""
|
||||
|
||||
CheckOptions:
|
||||
- key: readability-identifier-naming.VariableCase
|
||||
value: lower_case
|
||||
- key: readability-identifier-naming.FunctionCase
|
||||
value: lower_case
|
||||
---
|
||||
]])
|
||||
)
|
||||
|
||||
utils.write_file(
|
||||
{ full_project_root, "CMakeLists.txt" },
|
||||
string.format(
|
||||
[[
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(%s LANGUAGES CXX)
|
||||
|
||||
|
||||
set(SOURCES
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
add_executable(%s ${SOURCES})
|
||||
]],
|
||||
project_name,
|
||||
project_name
|
||||
)
|
||||
)
|
||||
|
||||
local gitignore = { "build/", ".cache/" }
|
||||
utils.init_git(full_project_root, gitignore)
|
||||
vim.fn.system(
|
||||
string.format(
|
||||
"cd %s/build && cmake -S .. -B . && cmake --build . && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..",
|
||||
full_project_root
|
||||
)
|
||||
)
|
||||
vim.cmd("edit " .. full_project_root .. "/src/main.cpp")
|
||||
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,
|
||||
},
|
||||
c = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".c" },
|
||||
""
|
||||
)
|
||||
end,
|
||||
},
|
||||
cpp = {
|
||||
run = function(file_name)
|
||||
utils.write_file(
|
||||
{ utils.get_project_root(), "src", file_name .. ".cpp" },
|
||||
""
|
||||
)
|
||||
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,
|
||||
},
|
||||
}
|
||||
|
||||
M.extras = {
|
||||
run = function(lang, file_name)
|
||||
if lang == "c" then
|
||||
extras("_H", ".h", file_name)
|
||||
print("Successful creation of " .. file_name .. ".h")
|
||||
elseif lang == "cpp" then
|
||||
extras("_HPP", ".hpp", file_name)
|
||||
print("Successful creation of " .. file_name .. ".hpp")
|
||||
else
|
||||
print("Extras language is not found: enter cpp or c")
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -1,19 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
---@param ft string Filetype of template
|
||||
---@param template string Template in language table
|
||||
---@param name string A string to replace temp values in template
|
||||
---@return string
|
||||
function M.fetch(ft, template, name)
|
||||
ft, template, name = ft or "", template or "", name or ""
|
||||
if ft == "" or template == "" or name == "" then
|
||||
return ""
|
||||
end
|
||||
local ok, mod = pcall(require, "vern.templates." .. ft)
|
||||
if ok and type(mod) == "table" then
|
||||
return (string.gsub(mod[template], "%%s", name))
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user