From 06eb74e13ffc5b7f37736870ae2a017b74db9b2b Mon Sep 17 00:00:00 2001
From: Andrew Haynes
Date: Fri, 16 Oct 2026 10:38:06 -0400
Subject: [PATCH] REFACTOR: Cleaning up project and removing more deprecated
code
---
README.md | 3 +
lua/vern/actions/python.lua | 28 ++-
lua/vern/attach/python.lua | 4 +-
lua/vern/configs/default.lua | 26 ---
lua/vern/configs/init.lua | 38 ++++
lua/vern/configs/python.lua | 66 +++---
lua/vern/init.lua | 6 +-
.../templates/{python/init.lua => python.lua} | 0
lua/vern/ui.lua | 189 ------------------
lua/vern/utils.lua | 113 +++++------
plugin/vern.lua | 1 -
11 files changed, 142 insertions(+), 332 deletions(-)
delete mode 100644 lua/vern/configs/default.lua
create mode 100644 lua/vern/configs/init.lua
rename lua/vern/templates/{python/init.lua => python.lua} (100%)
delete mode 100644 lua/vern/ui.lua
delete mode 100644 plugin/vern.lua
diff --git a/README.md b/README.md
index 7e747cf..6e31131 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,9 @@
+NOTE: The plugin may not work well with lazy or any other package manager other than vim.pack. I dont understand enough about nvim api and lua to handle these other things right now
+
+
## Features
* Create and manage projects directly from Neovim
diff --git a/lua/vern/actions/python.lua b/lua/vern/actions/python.lua
index ec52308..9ec09a4 100644
--- a/lua/vern/actions/python.lua
+++ b/lua/vern/actions/python.lua
@@ -1,7 +1,6 @@
local M = {}
local utils = require("vern.utils")
-M.default_target_file = "main.py"
function M.create_project(opts) end
function M.create_file(opts) end
@@ -13,32 +12,29 @@ function M.run(opts)
local root = utils.get_project_root() or "."
local project_name = vim.fs.basename(root)
- local pattern = vim.tbl_get(
- opts,
- "templates",
- "project",
- "executable",
- "target"
- ) or "src/%s/main.py"
- local rel_path = pattern:find("%%s")
- and string.format(pattern, project_name)
- or pattern
+ 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)
+ utils.terminal({ "python3 " .. full_path }, opts.terminal or {})
end
---@param cmd_args? table Takes a table for the runtime
function M.pip_install(opts, cmd_args)
- if cmd_args and cmd_args.args and cmd_args ~= "" then
- utils.terminal({ "pip install " .. cmd_args.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 {})
return
end
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
- if not pip_module or pip_module == "" then
+ if not pip_module or vim.trim(pip_module) == "" then
vim.notify("Pip Cancelled", vim.log.levels.WARN)
return
end
- utils.terminal({ "pip install " .. pip_module }, opts or {})
+ utils.terminal(
+ { "pip install " .. vim.trim(pip_module) },
+ opts.terminal or {}
+ )
end)
end
diff --git a/lua/vern/attach/python.lua b/lua/vern/attach/python.lua
index b1a1f08..e76fe31 100644
--- a/lua/vern/attach/python.lua
+++ b/lua/vern/attach/python.lua
@@ -4,7 +4,7 @@ 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 actions.run then
+ if type(actions.run) == "function" then
actions.run(opts)
end
end, { desc = "Run python project" })
@@ -15,7 +15,7 @@ return function(bufnr, user_opts)
end
end, { nargs = "*", desc = "Install python packages" })
- for key, def in pairs(opts.keybinds or {}) do
+ 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)
diff --git a/lua/vern/configs/default.lua b/lua/vern/configs/default.lua
deleted file mode 100644
index cdb1fe7..0000000
--- a/lua/vern/configs/default.lua
+++ /dev/null
@@ -1,26 +0,0 @@
-local actions = require("vern.actions")
-return {
- workspace_root = "~/personal/Projects",
- keybinds = {
- ["pc"] = {
- desc = "Creates a new project",
- action = actions.create_project,
- },
- ["pf"] = {
- desc = "Creates a new project file",
- action = actions.create_file,
- },
- },
- terminal = {
- mode = "split",
- win = {
- type = "horizontal",
- anchor = "bottom",
- size = "20",
- },
- border = {
- enabled = true,
- type = "rounded",
- },
- },
-}
diff --git a/lua/vern/configs/init.lua b/lua/vern/configs/init.lua
new file mode 100644
index 0000000..d329020
--- /dev/null
+++ b/lua/vern/configs/init.lua
@@ -0,0 +1,38 @@
+local actions = require("vern.actions")
+return {
+ workspace_root = "~/personal/Projects",
+ keybinds = {
+ ["pc"] = {
+ desc = "Creates a new project",
+ action = actions.create_project,
+ },
+ ["pf"] = {
+ desc = "Creates a new project file",
+ action = actions.create_file,
+ },
+ },
+ terminal = {
+ mode = {
+ type = "split", --- can be split or float
+ win = {
+ float = {
+ padding = {
+ left = 0,
+ right = 0,
+ top = 0,
+ bottom = 0,
+ },
+ border = {
+ enabled = true,
+ type = vim.o.winborder,
+ },
+ },
+ split = {
+ type = "horizontal", --- can be vertical or horizontal
+ anchor = "bottom", --- can be right or bottom
+ size = "20",
+ },
+ },
+ },
+ },
+}
diff --git a/lua/vern/configs/python.lua b/lua/vern/configs/python.lua
index ead7035..56de2b1 100644
--- a/lua/vern/configs/python.lua
+++ b/lua/vern/configs/python.lua
@@ -1,42 +1,44 @@
local actions = require("vern.actions.python")
return {
- root = "Python", --- later will concat the project_root to the front
- keybinds = {
- ["pr"] = {
- desc = "Executes python code",
- action = actions.run,
- },
- ["pb"] = {
- desc = "Asks for what python package to install",
- action = actions.pip_install,
- },
- },
- templates = {
- project = {
- ["executable"] = {
- template = { "vern.templates.python", "main" },
- target = "src/%s/main.py",
+ python = {
+ root = "Python", --- later will concat the project_root to the front
+ keybinds = {
+ ["pr"] = {
+ desc = "Executes python code",
+ action = actions.run,
},
- ["init"] = {
- template = { "vern.templates.python", "__init__" },
- target = "src/%s/__init__.py",
- },
- ["manifest"] = {
- template = { "vern.templates.python", "pyproject" },
- target = "pyproject.toml",
+ ["pb"] = {
+ desc = "Asks for what python package to install",
+ action = actions.pip_install,
},
},
- file = {
- ["module"] = {
- template = { "vern.templates.python", "module" },
- target = "src/%s.py",
+ templates = {
+ project = {
+ ["executable"] = {
+ template = { "vern.templates.python", "main" },
+ target = "src/%s/main.py",
+ },
+ ["init"] = {
+ template = { "vern.templates.python", "__init__" },
+ target = "src/%s/__init__.py",
+ },
+ ["manifest"] = {
+ template = { "vern.templates.python", "pyproject" },
+ target = "pyproject.toml",
+ },
},
- },
- extras = {
- ["gitignore"] = {
- template = "vern.templates.extras.gitignore", --- needs to call the function in file
- target = ".gitignore",
+ file = {
+ ["module"] = {
+ template = { "vern.templates.python", "module" },
+ target = "src/%s.py",
+ },
+ },
+ extras = {
+ ["gitignore"] = {
+ template = "vern.templates.extras.gitignore", --- needs to call the function in file
+ target = ".gitignore",
+ },
},
},
},
diff --git a/lua/vern/init.lua b/lua/vern/init.lua
index 2f8ef16..2a7b104 100644
--- a/lua/vern/init.lua
+++ b/lua/vern/init.lua
@@ -1,11 +1,11 @@
local M = {}
-local global_opts = require("vern.configs.default")
+local configs = require("vern.configs")
local actions = require("vern.actions")
M.opts = {}
function M.setup(user_opts)
- M.opts = vim.tbl_deep_extend("force", {}, global_opts, user_opts or {})
+ M.opts = vim.tbl_deep_extend("force", {}, configs, user_opts or {})
--- Bind global keybinds
for key, def in pairs(M.opts.keybinds or {}) do
@@ -43,7 +43,7 @@ function M.setup(user_opts)
local ft = vim.bo[args.buf].filetype
local ok, attach = pcall(require, "vern.attach." .. ft)
if ok and type(attach) == "function" then
- attach(args.buf, M.user_opts)
+ attach(args.buf, M.opts)
end
end,
desc = "Attach languages to buffer",
diff --git a/lua/vern/templates/python/init.lua b/lua/vern/templates/python.lua
similarity index 100%
rename from lua/vern/templates/python/init.lua
rename to lua/vern/templates/python.lua
diff --git a/lua/vern/ui.lua b/lua/vern/ui.lua
deleted file mode 100644
index 38d0b57..0000000
--- a/lua/vern/ui.lua
+++ /dev/null
@@ -1,189 +0,0 @@
-local M = {}
-
----@param path string
----@return table
-local function get_entries(path)
- local result = {}
- local handle = vim.uv.fs_scandir(path)
- if not handle then return result end
- while true do
- local name, type = vim.uv.fs_scandir_next(handle)
- if not name then break end
- table.insert(result, {
- name = name .. (type == "directory" and "/" or ""),
- type = type,
- full_path = path .. "/" .. name,
- })
- end
- table.sort(result, function(a, b)
- if a.type == "directory" and b.type ~= "directory" then return true end
- if b.type == "directory" and a.type ~= "directory" then return false end
- return a.name < b.name
- end)
- return result
-end
-
----@param project_root string
-function M.manager(project_root)
- local templates = require("Polydev.templates")
- local width, height = math.floor(vim.o.columns * 0.40), math.floor(vim.o.lines * 0.4)
- local row, col = math.floor((vim.o.lines - height) / 3), math.floor((vim.o.columns - width) / 2)
- local content_row = row + 2
- local content_height = height - 3
-
- local cwd = vim.fn.getcwd()
- local current_view = {}
-
- local content_buf = vim.api.nvim_create_buf(false, true)
- local content_win = vim.api.nvim_open_win(content_buf, true, {
- relative = "editor",
- width = width,
- height = content_height,
- row = content_row,
- col = col,
- style = "minimal",
- border = "rounded",
- })
-
- local function close_all_windows()
- if vim.api.nvim_win_is_valid(content_win) then
- pcall(vim.api.nvim_win_close, content_win, true)
- end
- end
-
- local function update_screen()
- local root = vim.fn.expand(project_root)
- if vim.fn.isdirectory(root) == 0 then
- vim.fn.mkdir(root, "p")
- end
- local entries = get_entries(cwd)
- if not cwd:find(root, 1, true) then
- cwd = root
- entries = get_entries(cwd)
- end
- if cwd ~= root then
- table.insert(entries, 1, {
- name = "../",
- type = "directory",
- full_path = vim.fn.fnamemodify(cwd, ":h"),
- is_up = true,
- })
- end
- current_view = vim.deepcopy(entries)
-
- local lines = {}
- if #current_view == 0 then
- table.insert(lines, "No projects found in " .. cwd)
- table.insert(lines, "Press d to create a project, or a to add a folder.")
- else
- for i, item in ipairs(current_view) do
- table.insert(lines, string.format("%-2d | %-27s | %-6s", i, item.name, item.type))
- end
- end
- vim.api.nvim_buf_set_lines(content_buf, 0, -1, false, lines)
- end
-
- local function get_selected_entry()
- local win = content_win
- if not win or not vim.api.nvim_win_is_valid(win) then return end
- local row = vim.api.nvim_win_get_cursor(win)[1]
- return current_view[row], row
- end
-
- ---@param type string
- ---@param callback fun(lang: string, name: string)
- local function get_inputs(type, callback)
- vim.ui.input({ prompt = "Enter language for new " .. type .. ": " }, function(lang)
- if not lang or lang == "" then return end
- vim.ui.input({ prompt = "Enter " .. type .. " name: " }, function(name)
- if not name or name == "" then return end
- callback(lang, name)
- end)
- end)
- end
-
- update_screen()
-
- local buf = content_buf
- vim.keymap.set("n", "", function()
- if vim.api.nvim_win_is_valid(content_win) then
- pcall(vim.api.nvim_win_close, content_win, true)
- end
- end, { buffer = buf })
- vim.keymap.set("n", "a", function ()
- vim.ui.input({ prompt = "New folder name: " }, function(input)
- if input then
- vim.fn.mkdir(cwd .. "/" .. input, "p")
- update_screen()
- end
- end)
- end, { buffer = buf })
- vim.keymap.set("n", "R", function ()
- local entry = get_selected_entry()
- if entry ~= nil and not entry.is_up then
- vim.ui.input({ prompt = "Rename: ", default = entry.name }, function(input)
- if input then
- local new_path = cwd .. "/" .. input
- vim.fn.rename(entry.full_path, new_path)
- update_screen()
- end
- end)
- end
- end, { buffer = buf })
- vim.keymap.set("n", "D", function()
- local entry = get_selected_entry()
- if entry ~= nil and not entry.is_up then
- vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
- if input == "y" or input == "Y" then
- vim.fn.delete(entry.full_path, "rf")
- update_screen()
- end
- end)
- end
- end, { buffer = buf })
- vim.keymap.set("n", "%", function()
- get_inputs("file", function(lang, name)
- local file = templates.files[lang]
- if not file or not file.run then
- return print("Error: No file creation method for " .. lang)
- end
- close_all_windows()
- file.run(name)
- end)
- end, { buffer = buf })
- vim.keymap.set("n", "x", function()
- get_inputs("aux file", function(lang, name)
- close_all_windows()
- templates.extras.run(lang, name)
- end)
- end, { buffer = buf })
- vim.keymap.set("n", "d", function()
- get_inputs("project", function(lang, name)
- local project = templates.projects[lang]
- if not project or not project.run then
- return print("Error: No project creation method for " .. lang)
- end
- local opts = require("Polydev.configs").get(lang)
- local run_root = opts.project_root or project_root
- close_all_windows()
- project.run(name, run_root)
- end)
- end, { buffer = buf })
- vim.keymap.set("n", "", function()
- local entry = get_selected_entry()
- if not entry then return end
-
- if entry.type == "file" then
- close_all_windows()
- vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
- elseif entry.type == "directory" then
- cwd = entry.full_path
- vim.cmd("cd " .. cwd)
- update_screen()
- else
- print("Error")
- end
- end, { buffer = buf })
-end
-
-return M
diff --git a/lua/vern/utils.lua b/lua/vern/utils.lua
index 97d47c3..c429371 100644
--- a/lua/vern/utils.lua
+++ b/lua/vern/utils.lua
@@ -19,91 +19,78 @@ end
---@return integer, integer?
function M.terminal(cmd, opts)
opts = opts or {}
- if opts.terminal.mode == "floating" then
+ local buf, win
+ if opts.mode.type == "float" then
local ui = vim.api.nvim_list_uis()[1]
- local width, height, row, col
- if opts.terminal ~= nil then
+ local dim = {
width = math.max(
1,
math.floor(ui.width * 0.9)
- - opts.terminal.left
- - opts.terminal.right
- )
+ - opts.mode.win.float.padding.left
+ - opts.mode.win.float.padding.right
+ ),
height = math.max(
1,
math.floor(ui.height * 0.9)
- - opts.terminal.top
- - opts.terminal.bottom
- )
- row = math.floor((ui.height - height) / 2) + opts.terminal.top
- col = math.floor((ui.width - width) / 2) + opts.terminal.left
- end
- if opts.terminal == nil then
- width = math.max(1, math.floor(ui.width * 0.9))
- height = math.max(1, math.floor(ui.height * 0.9))
- row = math.floor((ui.height - height) / 2)
- col = math.floor((ui.width - width) / 2)
- end
- local buf = vim.api.nvim_create_buf(false, true)
- local win = vim.api.nvim_open_win(buf, true, {
+ - opts.mode.win.float.padding.top
+ - opts.mode.win.float.padding.bottom
+ ),
+ }
+
+ local pos = {
+ row = math.floor(
+ (
+ ui.height
+ - (vim.o.laststatus == 3 and 1 or 0)
+ - vim.o.cmdheight
+ - dim.height
+ ) / 2
+ ),
+ col = math.floor((ui.width - dim.width) / 2),
+ }
+
+ buf = vim.api.nvim_create_buf(false, true)
+ win = vim.api.nvim_open_win(buf, true, {
relative = "editor",
- width = width,
- height = height,
- row = row,
- col = col,
+ width = dim.width,
+ height = dim.height,
+ row = pos.row,
+ col = pos.col,
style = "minimal",
- border = opts.terminal.border.enabled and opts.terminal.border.type,
+ border = opts.mode.win.float.border.enabled
+ and opts.mode.win.float.border.type
+ or nil,
})
- vim.api.nvim_set_option_value(
- "winhighlight",
- "Normal:PolydevNormal,FloatBorder:PolydevBorder",
- { win = win }
- )
- vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
- vim.api.nvim_buf_set_keymap(
- buf,
- "n",
- "",
- "i:q",
- { noremap = true, silent = true }
- )
- return buf, win
end
- if opts.terminal.mode == "split" then
- if opts.terminal.win.type == "vertical" then
- if opts.terminal.win.anchor == "right" then
+ if opts.mode.type == "split" then
+ if opts.mode.win.split.type == "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.terminal.win.type == "horizontal" then
- if opts.terminal.win.anchor == "bottom" then
+ if opts.mode.win.split.type == "horizontal" then
+ if opts.mode.win.split.anchor == "bottom" then
vim.cmd("set splitbelow")
end
+ vim.cmd(opts.mode.win.split.size .. " split")
end
- if opts.terminal.win.type == "vertical" then
- vim.cmd(opts.terminal.win.size .. " vsplit")
- end
- if opts.terminal.win.type == "horizontal" then
- vim.cmd(opts.terminal.win.size .. " split")
- end
- local buf = vim.api.nvim_create_buf(false, true)
- local win = vim.api.nvim_get_current_win()
+ buf = vim.api.nvim_create_buf(false, true)
+ win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(0, buf)
-
- vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
- vim.api.nvim_buf_set_keymap(
- buf,
- "n",
- "",
- "i:q",
- { noremap = true, silent = true }
- )
- return buf, win
end
- return 0
+ vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
+ vim.api.nvim_buf_set_keymap(
+ buf,
+ "n",
+ "",
+ "i:q",
+ { noremap = true, silent = true }
+ )
+ return buf, win
end
return M
diff --git a/plugin/vern.lua b/plugin/vern.lua
deleted file mode 100644
index c4f770e..0000000
--- a/plugin/vern.lua
+++ /dev/null
@@ -1 +0,0 @@
-require("vern").setup()