LANG: javascript - lets see if this works

This commit is contained in:
Andrew Haynes
2026-03-29 00:47:50 -04:00
parent d99dc30dcd
commit 2ca6c62cd8
2 changed files with 269 additions and 231 deletions
+6
View File
@@ -10,6 +10,12 @@ local function default_languages(project_root)
["<leader>pr"] = "RustRun",
},
},
javascript = {
project_root = project_root .. "/Javascript",
keybinds = {
["<leader>pr"] = "JavascriptRun",
},
},
java = {
project_root = project_root .. "/Java",
keybinds = {
+56 -24
View File
@@ -22,15 +22,42 @@ function M.load_language_module(lang, opts)
end
M.languages = {
javascript = {
setup = function(self, user_opts)
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 })
end
end,
run = function()
local root = utils.get_project_root()
local cmd = string.format("node " .. root .. "/main.js")
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, { win = 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, { win = term_buf })
else
utils.terminal({ "node " .. root .. "/main.js" })
end
end
},
java = {
setup = function (self, user_opts)
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
vim.api.nvim_create_user_command("JavaRun", function() self:run() end, {})
for key, _ in pairs(opts.keybinds) do
vim.keymap.set("n", key, ":JavaRun<CR>", { silent = true })
end
end,
run = function ()
run = function()
local root = utils.get_project_root()
local cmd = string.format("javac -d %s %s", root .. "/build", root .. "/src/*.java")
@@ -40,7 +67,8 @@ M.languages = {
local term_buf = utils.terminal({ cmd })
vim.api.nvim_set_option_value("modifiable", true, { win = 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.list_extend({ "Error during compilation:" },
vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
else
@@ -49,14 +77,14 @@ M.languages = {
end
},
c = {
setup = function (self, user_opts)
setup = function(self, user_opts)
local opts = vim.tbl_deep_extend("force", {}, configs.get("c"), user_opts or {})
vim.api.nvim_create_user_command("CRun", function () self:run() end, {})
vim.api.nvim_create_user_command("CRun", function() self:run() end, {})
for key, _ in pairs(opts.keybinds) do
vim.keymap.set("n", key, ":CRun<CR>", { silent = true })
end
end,
run = function ()
run = function()
local root = utils.get_project_root()
local build_dir = root .. "/build"
@@ -68,7 +96,8 @@ M.languages = {
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.list_extend({ "Error during compilation:" },
vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
end
@@ -79,14 +108,14 @@ M.languages = {
end
},
cpp = {
setup = function (self, user_opts)
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, {})
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 ()
run = function()
local root = utils.get_project_root()
local build_dir = root .. "/build"
@@ -99,7 +128,8 @@ M.languages = {
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.list_extend({ "Error during compilation:" },
vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_set_option_value("modifiable", false, { buf = term_buf })
end
@@ -110,19 +140,19 @@ M.languages = {
end
},
html = {
setup = function (user_opts)
setup = function(user_opts)
vim.tbl_deep_extend("force", {}, configs.get("html"), user_opts or {})
end
},
rust = {
setup = function (self, user_opts)
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, {})
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 ()
run = function()
local root = utils.get_project_root()
if not root then return print("Error: Project root not found.") end
@@ -133,7 +163,8 @@ M.languages = {
local term_buf = utils.terminal(cmd)
vim.api.nvim_set_option_value("modifiable", true, { win = 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.list_extend({ "Error during compilation:" },
vim.split(output, "\n", { trimempty = true }))
)
vim.api.nvim_set_option_value("modifiable", false, { win = term_buf })
else
@@ -144,8 +175,8 @@ M.languages = {
python = {
setup = function(self, user_opts)
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, {})
vim.api.nvim_create_user_command("PythonRun", function () self:run() end, {})
vim.api.nvim_create_user_command("PythonPip", function() self:install_dependency() end, {})
vim.api.nvim_create_user_command("PythonRun", function() self:run() end, {})
for key, command in pairs(opts.keybinds) do
if command == "PythonRun" then
vim.keymap.set("n", key, ":PythonRun<CR>", { silent = true })
@@ -164,26 +195,27 @@ M.languages = {
end
end
end,
install_dependency = function ()
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 ()
run = function()
utils.terminal({ "python3 " .. utils.get_project_root(), "main.py" })
end
},
lua = {
setup = function (self, user_opts)
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, {})
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"
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