4 Commits
16 changed files with 750 additions and 644 deletions
+7 -11
View File
@@ -15,27 +15,25 @@ NOTE: The plugin may not work well with lazy or any other package manager other
## Features
* Create and manage projects directly from Neovim
* Create projects directly from Neovim
* Generate new files quickly
* Build your code with customizable build systems
* Run programs without leaving the editor
* Integrated terminal for flexible command execution
* Lightweight, fast project manager UI
* Minimal configuration with extensibility in mind
* Built-in diagnostics with `:checkhealth Vern.nvim`
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/polydev/wiki/Home$0) for setup, configuration, and usage details.
> 📚 [View the full documentation](https://git.moomancer.xyz/DarthMooMancer/vern.nvim/wiki/Home$0) for setup, configuration, and usage details.
## Supported Languages
Vern.nvim currently supports the following languages:
* Java
* Python
* C / C++
* Lua
* Rust
* HTML
<!-- * Java -->
<!-- * C / C++ -->
<!-- * Lua -->
<!-- * Rust -->
<!-- * HTML -->
Additional language support is planned for future releases.
@@ -44,8 +42,6 @@ Additional language support is planned for future releases.
Current focus:
* **Refactoring and internal cleanup.**
* **Remaking it not in nui to make tabs, mainly for recent projects as the main page**
## Contributing
+44 -8
View File
@@ -1,16 +1,52 @@
local M = {}
M.create_project = function(opts, args)
M.create_project = function(opts)
opts = opts or {}
local test = nil
if opts and opts.terminal then
test = opts.terminal.mode
end
if args and args.args and args ~= "" then
print(string.format("Opts: %s, Args: %s", test, args.args))
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
M.create_file = function(opts, args) end
return M
+58 -14
View File
@@ -1,29 +1,76 @@
local M = {}
local utils = require("vern.utils")
local templates = require("vern.templates")
function M.create_project(opts) end
function M.create_file(opts) end
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.get_project_root() or "."
local project_name = vim.fs.basename(root)
local root = utils.proj_root() or "."
local pname = vim.fs.basename(root)
local exe = opts.python.templates.project.executable.target
or "src/%s/main.py"
local rel_path = exe:find("%%s") and string.format(exe, project_name) or exe
local full_path = root .. "/" .. rel_path
utils.terminal({ "python3 " .. full_path }, opts.terminal or {})
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.terminal({ "pip install " .. args }, opts.terminal or {})
utils.term({ "pip install " .. args }, opts.terminal or {})
return
end
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
@@ -31,10 +78,7 @@ function M.pip_install(opts, cmd_args)
vim.notify("Pip Cancelled", vim.log.levels.WARN)
return
end
utils.terminal(
{ "pip install " .. vim.trim(pip_module) },
opts.terminal or {}
)
utils.term({ "pip install " .. vim.trim(pip_module) }, opts.terminal or {})
end)
end
+4 -3
View File
@@ -27,8 +27,10 @@ return function(bufnr, user_opts)
end
end
local root = require("vern.utils").get_project_root()
if root then
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"
@@ -39,5 +41,4 @@ return function(bufnr, user_opts)
vim.env.VIRTUAL_ENV = venv_dir
vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH
end
end
end
+10 -15
View File
@@ -1,37 +1,32 @@
local actions = require("vern.actions.python")
return {
python = {
root = "Python", --- later will concat the project_root to the front
root = "Python",
source_root = "src/{project_name}",
keybinds = {
["<leader>pr"] = {
desc = "Executes python code",
action = actions.run,
action = require("vern.actions.python").run,
},
["<leader>pb"] = {
desc = "Asks for what python package to install",
action = actions.pip_install,
action = require("vern.actions.python").pip_install,
},
},
templates = {
project = {
["executable"] = {
template = { "vern.templates.python", "main" },
target = "src/%s/main.py",
["bin"] = {
target = "src/{project_name}/main.py",
},
["init"] = {
template = { "vern.templates.python", "__init__" },
target = "src/%s/__init__.py",
["pkg"] = {
target = "src/{project_name}/__init__.py",
},
["manifest"] = {
template = { "vern.templates.python", "pyproject" },
["spec"] = {
target = "pyproject.toml",
},
},
file = {
["module"] = {
template = { "vern.templates.python", "module" },
target = "src/%s.py",
target = "src/{project_name}/{name}.py",
},
},
extras = {
+10 -4
View File
@@ -1,5 +1,11 @@
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 = {}
@@ -20,15 +26,15 @@ function M.setup(user_opts)
end
--- Load project cmdline commands
vim.api.nvim_create_user_command("VernCreateProject", function(args)
vim.api.nvim_create_user_command("VernCreateProject", function()
if actions.create_project then
actions.create_project(M.opts, args)
actions.create_project(M.opts)
end
end, { nargs = "*", desc = "Create a new project" })
vim.api.nvim_create_user_command("VernCreateFile", function(args)
vim.api.nvim_create_user_command("VernCreateFile", function()
if type(actions.create_file) == "function" then
actions.create_file(M.opts, args)
actions.create_file(M.opts)
end
end, { nargs = "*", desc = "Creates a new file for project" })
@@ -30,22 +30,13 @@ end
M.languages = {
javascript = {
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend(
"force",
{},
configs.get("javascript"),
user_opts or {}
)
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 }
)
vim.keymap.set("n", key, ":JavascriptRun<CR>", { silent = true })
end
end,
run = function()
@@ -56,11 +47,7 @@ M.languages = {
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_set_option_value("modifiable", true, { buf = term_buf })
vim.api.nvim_buf_set_lines(
term_buf,
0,
@@ -71,11 +58,7 @@ M.languages = {
vim.split(output, "\n", { trimempty = true })
)
)
vim.api.nvim_set_option_value(
"modifiable",
false,
{ buf = term_buf }
)
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
else
utils.terminal({ "node " .. root .. "/main.js" })
end
@@ -83,12 +66,7 @@ M.languages = {
},
java = {
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend(
"force",
{},
configs.get("java"),
user_opts or {}
)
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
vim.api.nvim_create_user_command("JavaRun", function()
self:run()
end, {})
@@ -99,20 +77,12 @@ M.languages = {
run = function()
local root = utils.get_project_root()
local cmd = string.format(
"javac -d %s %s",
root .. "/build",
root .. "/src/*.java"
)
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_set_option_value("modifiable", true, { buf = term_buf })
vim.api.nvim_buf_set_lines(
term_buf,
0,
@@ -123,11 +93,7 @@ M.languages = {
vim.split(output, "\n", { trimempty = true })
)
)
vim.api.nvim_set_option_value(
"modifiable",
false,
{ buf = term_buf }
)
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
else
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
end
@@ -135,12 +101,7 @@ M.languages = {
},
c = {
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend(
"force",
{},
configs.get("c"),
user_opts or {}
)
local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {})
vim.api.nvim_create_user_command("CRun", function()
self:run()
end, {})
@@ -158,11 +119,7 @@ M.languages = {
if not success then
local term_buf = utils.terminal({ cmd })
vim.api.nvim_set_option_value(
"modifiable",
true,
{ buf = term_buf }
)
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
vim.api.nvim_buf_set_lines(
term_buf,
0,
@@ -173,29 +130,17 @@ M.languages = {
vim.split(output, "\n", { trimempty = true })
)
)
vim.api.nvim_set_option_value(
"modifiable",
false,
{ buf = term_buf }
)
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()
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 {}
)
local opts = vim.tbl_deep_extend("force", {}, configs.get("cpp"), user_opts or {})
vim.api.nvim_create_user_command("CppRun", function()
self:run()
end, {})
@@ -214,11 +159,7 @@ M.languages = {
if not success then
local term_buf = utils.terminal({ cmd })
vim.api.nvim_set_option_value(
"modifiable",
true,
{ buf = term_buf }
)
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
vim.api.nvim_buf_set_lines(
term_buf,
0,
@@ -229,39 +170,22 @@ M.languages = {
vim.split(output, "\n", { trimempty = true })
)
)
vim.api.nvim_set_option_value(
"modifiable",
false,
{ buf = term_buf }
)
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()
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 {}
)
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 {}
)
local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {})
vim.api.nvim_create_user_command("RustRun", function()
self:run()
end, {})
@@ -280,11 +204,7 @@ M.languages = {
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_set_option_value("modifiable", true, { buf = term_buf })
vim.api.nvim_buf_set_lines(
term_buf,
0,
@@ -295,11 +215,7 @@ M.languages = {
vim.split(output, "\n", { trimempty = true })
)
)
vim.api.nvim_set_option_value(
"modifiable",
false,
{ buf = term_buf }
)
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
else
utils.terminal({ "cargo run" })
end
@@ -307,12 +223,7 @@ M.languages = {
},
python = {
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend(
"force",
{},
configs.get("python"),
user_opts or {}
)
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, {})
@@ -321,20 +232,10 @@ M.languages = {
end, {})
for key, command in pairs(opts.keybinds) do
if command == "PythonRun" then
vim.keymap.set(
"n",
key,
":PythonRun<CR>",
{ silent = true }
)
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
end
if command == "PythonPip" then
vim.keymap.set(
"n",
key,
":PythonPip<CR>",
{ silent = true }
)
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
end
end
@@ -361,12 +262,7 @@ M.languages = {
},
lua = {
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend(
"force",
{},
configs.get("lua"),
user_opts or {}
)
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
vim.api.nvim_create_user_command("LuaRun", function()
self:run()
end, {})
+487
View File
@@ -0,0 +1,487 @@
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
-371
View File
@@ -1,371 +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
+5 -5
View File
@@ -1,7 +1,7 @@
local M = {}
---@param opts table
M.template = function(opts)
---@param lang string
M.template = function(lang)
local base = [=[
.DS_Store
@@ -13,7 +13,7 @@ M.template = function(opts)
]=]
local lang_block = {
python = [=[
python = vim.trim([=[
__pycache__/
build/
dist/
@@ -21,10 +21,10 @@ dist/
env/
venv/
.pytest_cache/
]=],
]=]),
}
local extra = (opts and opts and lang_block[opts.lang]) or ""
local extra = (lang and lang_block[lang]) or ""
return base .. extra
end
+19
View File
@@ -0,0 +1,19 @@
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
+34 -28
View File
@@ -1,28 +1,35 @@
local M = {}
M.main = function(opts)
local template = [=[
return {
--[[ =====================================================================
TEMPLATE: MAIN (Entrypoint)
File: main.py
Target: src/{project_name}/main.py
===================================================================== --]]
main = vim.trim([=[
def main() -> None:
printf("Hello from %s!")
print("Hello from %s!")
if __name__ == "__main__":
main()
]=]
return string.format(template, opts.project_name)
end
]=]) .. "\n",
M.__init__ = function(opts)
local template = [=[
# %s
--[[ =====================================================================
TEMPLATE: INIT (Package Anchor)
File: __init__.py
Target: src/{project_name}/__init__.py
===================================================================== --]]
__init__ = vim.trim([=[
# %s init
__all__: list[str] = []
]=]
return string.format(template, opts.project_name)
end
]=]) .. "\n",
M.pyproject = function(opts)
local n = opts.project_name
local template = [=[
--[[ =====================================================================
TEMPLATE: PYPROJECT (Spec / Build Manifest)
File: pyproject.toml
Target: pyproject.toml
===================================================================== --]]
pyproject = vim.trim([=[
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
@@ -37,17 +44,16 @@ dependencies = []
[project.scripts]
%s = "%s.main:main"
]=]
return string.format(template, n, n, n, n)
end
]=]) .. "\n",
M.module = function(opts)
local template = [=[
--[[ =====================================================================
TEMPLATE: MODULE (Standalone File)
File: {name}.py
Target: src/{project_name}/{name}.py
===================================================================== --]]
module = vim.trim([=[
"""
%s module
Module: %s
"""
]=]
return string.format(template, opts.project_name)
end
return M
]=]) .. "\n",
}
+35 -44
View File
@@ -1,8 +1,19 @@
local M = {}
---@param path string
---@param content string
function M.dump(path, content)
local file = assert(io.open(path, "w"), "Error creating file: " .. path)
file:write(content)
file:close()
end
function M.fmt(str, ctx)
return (str:gsub("{([^}]+)}", ctx))
end
---@param bufnr? integer Default is 0 (current buffer)
---@return string|nil
function M.get_project_root(bufnr)
function M.proj_root(bufnr)
bufnr = bufnr or 0
local root_markers = {
".git",
@@ -14,10 +25,28 @@ function M.get_project_root(bufnr)
}
return vim.fs.root(bufnr, root_markers) or vim.uv.cwd()
end
---
---@return string
function M.proj_name()
return vim.fn.fnamemodify(M.proj_root(), ":t")
end
---@param path string
---@param ft string
function M.init_git(path, ft)
ft = ft and vim.trim(ft)
if not ft or ft == "" then
return
end
local gitignore = require("vern.templates.extras.gitignore").template(ft)
vim.fn.system({ "git", "-C", path, "init" })
M.dump(vim.fs.joinpath(path, ".gitignore"), gitignore)
end
---@param cmd table
---@return integer, integer?
function M.terminal(cmd, opts)
function M.term(cmd, opts)
opts = opts or {}
local buf, win
if opts.mode.type == "float" then
@@ -40,12 +69,7 @@ function M.terminal(cmd, opts)
local pos = {
row = math.floor(
(
ui.height
- (vim.o.laststatus == 3 and 1 or 0)
- vim.o.cmdheight
- dim.height
) / 2
(ui.height - (vim.o.laststatus == 3 and 1 or 0) - vim.o.cmdheight - dim.height) / 2
),
col = math.floor((ui.width - dim.width) / 2),
}
@@ -58,9 +82,7 @@ function M.terminal(cmd, opts)
row = pos.row,
col = pos.col,
style = "minimal",
border = opts.mode.win.float.border.enabled
and opts.mode.win.float.border.type
or nil,
border = opts.mode.win.float.border.enabled and opts.mode.win.float.border.type or nil,
})
end
if opts.mode.type == "split" then
@@ -95,42 +117,11 @@ end
return M
-- M.opts = {}
--
-- function M.setup(opts)
-- M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
-- end
--
-- function M.exists(path)
-- return (io.open(path, "r") ~= nil)
-- end
--
--
-- ---@return string
-- function M.get_project_name()
-- return vim.fn.fnamemodify(M.get_project_root(), ":t")
-- end
--
-- ---@param path_segments table
-- ---@param content string
-- function M.write_file(path_segments, content)
-- local path = table.concat(path_segments, "/")
-- local file = assert(io.open(path, "w"), "Error creating file: " .. path)
-- file:write(content)
-- file:close()
-- vim.cmd("edit " .. path)
-- end
--
-- ---@param path string
-- ---@param gitignore_lines table
-- function M.init_git(path, gitignore_lines)
-- vim.fn.mkdir(path, "p")
-- vim.fn.system({ "git", "-C", path, "init" })
--
-- if gitignore_lines and #gitignore_lines > 0 then
-- local contents = table.concat(gitignore_lines, "\n")
-- M.write_file({ path, ".gitignore" }, contents)
-- end
-- end
----
-- return M
+1 -1
View File
@@ -1,7 +1,7 @@
# stylua.toml
# How many characters per line before wrapping
column_width = 80
column_width = 100
# Indentation style: "Tabs" or "Spaces"
line_endings = "Unix"