LANG: javascript - lets see if this works
This commit is contained in:
@@ -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 = {
|
||||
|
||||
@@ -22,6 +22,33 @@ 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)
|
||||
local opts = vim.tbl_deep_extend("force", {}, configs.get("java"), user_opts or {})
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -183,7 +214,8 @@ M.languages = {
|
||||
end
|
||||
end,
|
||||
run = function()
|
||||
local init_lua_path = utils.get_project_root() .. "/lua/" .. utils.get_project_name() .. "/init.lua"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user