REFACTOR: I spent all day on it but I am heavily refactoring the API and

organization because it was terrible before and hard to maintain. Now it
should be much easier and there is still of a design decisions to figure
out
This commit is contained in:
2026-10-15 02:07:14 -04:00
parent 2b30e36fad
commit 4bcac5d09b
27 changed files with 875 additions and 480 deletions
+25
View File
@@ -0,0 +1,25 @@
local M = {}
function M.buf(bufnr, user_opts)
bufnr = (bufnr == nil or bufnr == 0) and vim.api.nvim_get_current_buf()
or bufnr
local ft = vim.bo[bufnr].filetype
if not ft or ft == "" then
return
end
user_opts = user_opts or {}
local default = require("vern.configs.default")
local lang_opts = (user_opts or {})[ft] or {}
local final_opts =
vim.tbl_deep_extend("force", {}, default, user_opts, lang_opts)
final_opts[ft] = nil
local ok, lang_attach = pcall(require, "vern.attach." .. ft) --- like a try / catch block in c++
if ok and type(lang_attach) == "function" then
lang_attach(bufnr, final_opts)
end
end
return M
+43
View File
@@ -0,0 +1,43 @@
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 actions.run 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.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").get_project_root()
if root then
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
end