LANG: javascript - lets see if this works
This commit is contained in:
+72
-66
@@ -3,85 +3,91 @@ local M = {}
|
|||||||
---@param project_root string
|
---@param project_root string
|
||||||
---@return table
|
---@return table
|
||||||
local function default_languages(project_root)
|
local function default_languages(project_root)
|
||||||
return {
|
return {
|
||||||
rust = {
|
rust = {
|
||||||
project_root = project_root .. "/Rust",
|
project_root = project_root .. "/Rust",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "RustRun",
|
["<leader>pr"] = "RustRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
java = {
|
javascript = {
|
||||||
project_root = project_root .. "/Java",
|
project_root = project_root .. "/Javascript",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "JavaRun",
|
["<leader>pr"] = "JavascriptRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lua = {
|
java = {
|
||||||
project_root = project_root .. "/Lua",
|
project_root = project_root .. "/Java",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "LuaRun",
|
["<leader>pr"] = "JavaRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
c = {
|
lua = {
|
||||||
project_root = project_root .. "/C",
|
project_root = project_root .. "/Lua",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "CRun",
|
["<leader>pr"] = "LuaRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
cpp = {
|
c = {
|
||||||
project_root = project_root .. "/CPP",
|
project_root = project_root .. "/C",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "CppRun",
|
["<leader>pr"] = "CRun",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
python = {
|
cpp = {
|
||||||
project_root = project_root .. "/Python",
|
project_root = project_root .. "/CPP",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>pr"] = "PythonRun",
|
["<leader>pr"] = "CppRun",
|
||||||
["<leader>pb"] = "PythonPip",
|
},
|
||||||
},
|
},
|
||||||
},
|
python = {
|
||||||
html = {
|
project_root = project_root .. "/Python",
|
||||||
project_root = project_root .. "/Html",
|
keybinds = {
|
||||||
},
|
["<leader>pr"] = "PythonRun",
|
||||||
}
|
["<leader>pb"] = "PythonPip",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
html = {
|
||||||
|
project_root = project_root .. "/Html",
|
||||||
|
},
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
M.user_config = {}
|
M.user_config = {}
|
||||||
|
|
||||||
---@param user_opts table
|
---@param user_opts table
|
||||||
function M.setup(user_opts)
|
function M.setup(user_opts)
|
||||||
local defaults = {
|
local defaults = {
|
||||||
globals = {
|
globals = {
|
||||||
project_root = "~/personal/Projects",
|
project_root = "~/personal/Projects",
|
||||||
keybinds = {
|
keybinds = {
|
||||||
["<leader>po"] = "PolydevManager",
|
["<leader>po"] = "PolydevManager",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
terminal = {
|
terminal = {
|
||||||
mode = "split",
|
mode = "split",
|
||||||
win = {
|
win = {
|
||||||
type = "horizontal", anchor = "bottom", size = "20"
|
type = "horizontal", anchor = "bottom", size = "20"
|
||||||
},
|
},
|
||||||
border = {
|
border = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
type = "rounded",
|
type = "rounded",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
M.user_config = vim.tbl_deep_extend("force", {}, defaults, user_opts or {})
|
M.user_config = vim.tbl_deep_extend("force", {}, defaults, user_opts or {})
|
||||||
local langs = default_languages(M.user_config.globals.project_root)
|
local langs = default_languages(M.user_config.globals.project_root)
|
||||||
|
|
||||||
for lang, conf in pairs(langs) do
|
for lang, conf in pairs(langs) do
|
||||||
M.user_config[lang] = vim.tbl_deep_extend("force", conf, M.user_config[lang] or {})
|
M.user_config[lang] = vim.tbl_deep_extend("force", conf, M.user_config[lang] or {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param lang string
|
---@param lang string
|
||||||
---@return table
|
---@return table
|
||||||
function M.get(lang)
|
function M.get(lang)
|
||||||
return M.user_config[lang] or {}
|
return M.user_config[lang] or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
+197
-165
@@ -8,187 +8,219 @@ local loaded_languages = {}
|
|||||||
---@param opts? table
|
---@param opts? table
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.load_language_module(lang, opts)
|
function M.load_language_module(lang, opts)
|
||||||
if loaded_languages[lang] then return true end
|
if loaded_languages[lang] then return true end
|
||||||
|
|
||||||
local ok, mod = pcall(require, "Polydev.languages")
|
local ok, mod = pcall(require, "Polydev.languages")
|
||||||
if not ok or type(mod.languages) ~= "table" then return false end
|
if not ok or type(mod.languages) ~= "table" then return false end
|
||||||
|
|
||||||
local lang_mod = mod.languages[lang]
|
local lang_mod = mod.languages[lang]
|
||||||
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then return false end
|
if type(lang_mod) ~= "table" or type(lang_mod.setup) ~= "function" then return false end
|
||||||
|
|
||||||
lang_mod:setup(opts and opts[lang] or {})
|
lang_mod:setup(opts and opts[lang] or {})
|
||||||
loaded_languages[lang] = lang_mod
|
loaded_languages[lang] = lang_mod
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
M.languages = {
|
M.languages = {
|
||||||
java = {
|
javascript = {
|
||||||
setup = function (self, user_opts)
|
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("javascript"), user_opts or {})
|
||||||
vim.api.nvim_create_user_command("JavaRun", function() self:run() end, {})
|
vim.api.nvim_create_user_command("JavascriptRun", function() self:run() end, {})
|
||||||
for key, _ in pairs(opts.keybinds) do
|
for key, _ in pairs(opts.keybinds) do
|
||||||
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
|
vim.keymap.set("n", key, ":JavascriptRun<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
run = function ()
|
run = function()
|
||||||
local root = utils.get_project_root()
|
local root = utils.get_project_root()
|
||||||
|
|
||||||
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
|
local cmd = string.format("node " .. root .. "/main.js")
|
||||||
local output = vim.fn.system(cmd)
|
local output = vim.fn.system(cmd)
|
||||||
|
|
||||||
if not vim.v.shell_error == 0 then
|
if not vim.v.shell_error == 0 then
|
||||||
local term_buf = utils.terminal({ cmd })
|
local term_buf = utils.terminal({ cmd })
|
||||||
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
|
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
vim.list_extend({ "Error during compilation:" },
|
||||||
)
|
vim.split(output, "\n", { trimempty = true }))
|
||||||
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
|
)
|
||||||
else
|
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
|
||||||
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
else
|
||||||
end
|
utils.terminal({ "node " .. root .. "/main.js" })
|
||||||
end
|
end
|
||||||
},
|
end
|
||||||
c = {
|
},
|
||||||
setup = function (self, user_opts)
|
java = {
|
||||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {})
|
setup = function(self, user_opts)
|
||||||
vim.api.nvim_create_user_command("CRun", function () self:run() end, {})
|
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
|
||||||
for key, _ in pairs(opts.keybinds) do
|
vim.api.nvim_create_user_command("JavaRun", function() self:run() end, {})
|
||||||
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
|
for key, _ in pairs(opts.keybinds) do
|
||||||
end
|
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
|
||||||
end,
|
end
|
||||||
run = function ()
|
end,
|
||||||
local root = utils.get_project_root()
|
run = function()
|
||||||
local build_dir = root .. "/build"
|
local root = utils.get_project_root()
|
||||||
|
|
||||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
|
||||||
local output = vim.fn.system(cmd)
|
local output = vim.fn.system(cmd)
|
||||||
local success = vim.v.shell_error == 0
|
|
||||||
|
|
||||||
if not success then
|
if not vim.v.shell_error == 0 then
|
||||||
local term_buf = utils.terminal({ cmd })
|
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, { win = term_buf })
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
vim.list_extend({ "Error during compilation:" },
|
||||||
)
|
vim.split(output, "\n", { trimempty = true }))
|
||||||
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
|
)
|
||||||
end
|
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
|
||||||
if success then
|
else
|
||||||
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
||||||
utils.terminal({ run_cmd })
|
end
|
||||||
end
|
end
|
||||||
end
|
},
|
||||||
},
|
c = {
|
||||||
cpp = {
|
setup = function(self, user_opts)
|
||||||
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("cpp"), user_opts or {})
|
vim.api.nvim_create_user_command("CRun", function() self:run() end, {})
|
||||||
vim.api.nvim_create_user_command("CppRun", function () self:run() end, {})
|
for key, _ in pairs(opts.keybinds) do
|
||||||
for key, _ in pairs(opts.keybinds) do
|
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
|
||||||
vim.keymap.set("n", key, ":CppRun<CR>", { silent = true })
|
end
|
||||||
end
|
end,
|
||||||
end,
|
run = function()
|
||||||
run = function ()
|
local root = utils.get_project_root()
|
||||||
local root = utils.get_project_root()
|
local build_dir = root .. "/build"
|
||||||
local build_dir = root .. "/build"
|
|
||||||
|
|
||||||
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||||
local output = vim.fn.system(cmd)
|
local output = vim.fn.system(cmd)
|
||||||
local success = vim.v.shell_error == 0
|
local success = vim.v.shell_error == 0
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
local term_buf = utils.terminal({ cmd })
|
local term_buf = utils.terminal({ cmd })
|
||||||
|
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||||
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
|
vim.list_extend({ "Error during compilation:" },
|
||||||
|
vim.split(output, "\n", { trimempty = true }))
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
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 {})
|
||||||
|
vim.api.nvim_create_user_command("CppRun", function() self:run() end, {})
|
||||||
|
for key, _ in pairs(opts.keybinds) do
|
||||||
|
vim.keymap.set("n", key, ":CppRun<CR>", { silent = true })
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
run = function()
|
||||||
|
local root = utils.get_project_root()
|
||||||
|
local build_dir = root .. "/build"
|
||||||
|
|
||||||
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
local cmd = "cd '" .. build_dir .. "' && cmake --build ."
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
local output = vim.fn.system(cmd)
|
||||||
vim.list_extend({ "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))
|
local success = vim.v.shell_error == 0
|
||||||
)
|
|
||||||
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()
|
|
||||||
utils.terminal({ run_cmd })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
},
|
|
||||||
html = {
|
|
||||||
setup = function (user_opts)
|
|
||||||
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 {})
|
|
||||||
vim.api.nvim_create_user_command("RustRun", function () self:run() end, {})
|
|
||||||
for key, _ in pairs(opts.keybinds) do
|
|
||||||
vim.keymap.set("n", key, ":RustRun<CR>", { silent = true })
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
run = function ()
|
|
||||||
local root = utils.get_project_root()
|
|
||||||
if not root then return print("Error: Project root not found.") end
|
|
||||||
|
|
||||||
local cmd = { "cargo build" }
|
if not success then
|
||||||
local output = vim.fn.system(table.concat(cmd))
|
local term_buf = utils.terminal({ cmd })
|
||||||
|
|
||||||
if not vim.v.shell_error == 0 then
|
vim.api.nvim_set_option_value("modifiable", true, { buf = term_buf })
|
||||||
local term_buf = utils.terminal(cmd)
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
|
vim.list_extend({ "Error during compilation:" },
|
||||||
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
vim.split(output, "\n", { trimempty = true }))
|
||||||
vim.list_extend({ "Error during compilation:" }, 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, { win = term_buf })
|
end
|
||||||
else
|
if success then
|
||||||
utils.terminal({ "cargo run" })
|
local run_cmd = "cd '" .. build_dir .. "' && ./" .. utils.get_project_name()
|
||||||
end
|
utils.terminal({ run_cmd })
|
||||||
end
|
end
|
||||||
},
|
end
|
||||||
python = {
|
},
|
||||||
setup = function(self, user_opts)
|
html = {
|
||||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {})
|
setup = function(user_opts)
|
||||||
vim.api.nvim_create_user_command("PythonPip", function () self:install_dependency() end, {})
|
vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {})
|
||||||
vim.api.nvim_create_user_command("PythonRun", function () self:run() end, {})
|
end
|
||||||
for key, command in pairs(opts.keybinds) do
|
},
|
||||||
if command == "PythonRun" then
|
rust = {
|
||||||
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
|
setup = function(self, user_opts)
|
||||||
end
|
local opts = vim.tbl_deep_extend("force", {}, configs.get("rust"), user_opts or {})
|
||||||
if command == "PythonPip" then
|
vim.api.nvim_create_user_command("RustRun", function() self:run() end, {})
|
||||||
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
|
for key, _ in pairs(opts.keybinds) do
|
||||||
end
|
vim.keymap.set("n", key, ":RustRun<CR>", { silent = true })
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
|
run = function()
|
||||||
|
local root = utils.get_project_root()
|
||||||
|
if not root then return print("Error: Project root not found.") end
|
||||||
|
|
||||||
local root = utils.get_project_root()
|
local cmd = { "cargo build" }
|
||||||
if root then
|
local output = vim.fn.system(table.concat(cmd))
|
||||||
local venv_path = root .. "/venv/bin/activate"
|
|
||||||
if vim.fn.filereadable(venv_path) == 1 then
|
if not vim.v.shell_error == 0 then
|
||||||
vim.env.VIRTUAL_ENV = venv_path
|
local term_buf = utils.terminal(cmd)
|
||||||
vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH
|
vim.api.nvim_set_option_value("modifiable", true, { win = term_buf })
|
||||||
end
|
vim.api.nvim_buf_set_lines(term_buf, 0, -1, false,
|
||||||
end
|
vim.list_extend({ "Error during compilation:" },
|
||||||
end,
|
vim.split(output, "\n", { trimempty = true }))
|
||||||
install_dependency = function ()
|
)
|
||||||
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
|
||||||
if not pip_module or pip_module == "" then return print("Pip canceled") end
|
else
|
||||||
utils.terminal({ "pip install " .. pip_module })
|
utils.terminal({ "cargo run" })
|
||||||
end)
|
end
|
||||||
end,
|
end
|
||||||
run = function ()
|
},
|
||||||
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
python = {
|
||||||
end
|
setup = function(self, user_opts)
|
||||||
},
|
local opts = vim.tbl_deep_extend("force", {}, configs.get("python"), user_opts or {})
|
||||||
lua = {
|
vim.api.nvim_create_user_command("PythonPip", function() self:install_dependency() end, {})
|
||||||
setup = function (self, user_opts)
|
vim.api.nvim_create_user_command("PythonRun", function() self:run() end, {})
|
||||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
|
for key, command in pairs(opts.keybinds) do
|
||||||
vim.api.nvim_create_user_command("LuaRun", function () self:run() end, {})
|
if command == "PythonRun" then
|
||||||
for key, _ in pairs(opts.keybinds) do
|
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
|
||||||
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
|
end
|
||||||
end
|
if command == "PythonPip" then
|
||||||
end,
|
vim.keymap.set("n", key, ":PythonPip<CR>", { silent = true })
|
||||||
run = function ()
|
end
|
||||||
local init_lua_path = utils.get_project_root() .. "/lua/" .. utils.get_project_name() .. "/init.lua"
|
end
|
||||||
if vim.fn.filereadable(init_lua_path) == 1 then
|
|
||||||
utils.terminal({ "lua " .. init_lua_path })
|
local root = utils.get_project_root()
|
||||||
end
|
if root then
|
||||||
end
|
local venv_path = root .. "/venv/bin/activate"
|
||||||
},
|
if vim.fn.filereadable(venv_path) == 1 then
|
||||||
|
vim.env.VIRTUAL_ENV = venv_path
|
||||||
|
vim.env.PATH = root .. "/venv/bin:" .. vim.env.PATH
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
install_dependency = function()
|
||||||
|
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
|
||||||
|
if not pip_module or pip_module == "" then return print("Pip canceled") end
|
||||||
|
utils.terminal({ "pip install " .. pip_module })
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
run = function()
|
||||||
|
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
|
||||||
|
end
|
||||||
|
},
|
||||||
|
lua = {
|
||||||
|
setup = function(self, user_opts)
|
||||||
|
local opts = vim.tbl_deep_extend("force", {}, configs.get("lua"), user_opts or {})
|
||||||
|
vim.api.nvim_create_user_command("LuaRun", function() self:run() end, {})
|
||||||
|
for key, _ in pairs(opts.keybinds) do
|
||||||
|
vim.keymap.set("n", key, ":LuaRun<CR>", { silent = true })
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
run = function()
|
||||||
|
local init_lua_path = utils.get_project_root() ..
|
||||||
|
"/lua/" .. utils.get_project_name() .. "/init.lua"
|
||||||
|
if vim.fn.filereadable(init_lua_path) == 1 then
|
||||||
|
utils.terminal({ "lua " .. init_lua_path })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user