REFACTOR: Completely changed how project creation is done so I can make
other languages easier and hopefully faster
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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
|
||||
Reference in New Issue
Block a user