Each language had the same boilerplate code to create new projects and new files with minor differences between each language making them difficult to edit and navigate.
123 lines
4.4 KiB
Lua
123 lines
4.4 KiB
Lua
local utils = require("Polydev.utils")
|
|
local configs = require("Polydev.configs")
|
|
local M = {}
|
|
|
|
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, { 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 })
|
|
else
|
|
utils.terminal({ "node " .. root .. "/main.js" })
|
|
end
|
|
end,
|
|
},
|
|
java = {
|
|
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()
|
|
local root = utils.get_project_root()
|
|
|
|
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_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 })
|
|
else
|
|
utils.terminal({ "java -cp " .. root, "build" .. " Main" })
|
|
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" }
|
|
local output = vim.fn.system(table.concat(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_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 })
|
|
else
|
|
utils.terminal({ "cargo run" })
|
|
end
|
|
end,
|
|
},
|
|
}
|
|
|
|
return M
|