PYTHON: added venv creation

This commit is contained in:
2026-10-20 17:42:25 -04:00
parent 0f542d56ef
commit 57e8eb0248
4 changed files with 53 additions and 160 deletions
+25 -129
View File
@@ -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, {})