PYTHON: added venv creation
This commit is contained in:
+18
-20
@@ -2,33 +2,31 @@ local M = {}
|
||||
|
||||
M.create_project = function(opts)
|
||||
opts = opts or {}
|
||||
vim.ui.input({
|
||||
prompt = "Project language (e.g. python): ",
|
||||
default = "",
|
||||
completion = "filetype",
|
||||
}, function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
if not ft or vim.trim(ft) == "" then
|
||||
return
|
||||
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
|
||||
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): ",
|
||||
default = "",
|
||||
completion = "filetype",
|
||||
}, function(ft)
|
||||
ft = ft and vim.trim(ft)
|
||||
|
||||
@@ -33,6 +33,9 @@ function M.create_project(opts)
|
||||
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
|
||||
|
||||
@@ -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, {})
|
||||
|
||||
Reference in New Issue
Block a user