From 52c835a87cdf2c6e0aa9676e924742017febaec5 Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Fri, 14 Mar 2025 00:36:36 -0400 Subject: [PATCH] Update java.lua --- lua/Polydev/java.lua | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/lua/Polydev/java.lua b/lua/Polydev/java.lua index d461762..c60e989 100644 --- a/lua/Polydev/java.lua +++ b/lua/Polydev/java.lua @@ -155,40 +155,29 @@ public class %s { end) end --- Compile Java files function M.build() local current_dir = vim.fn.expand("%:p:h") local project_root = current_dir:match("(.*)/src") - if not project_root then - print("Error: Must be inside the 'src' directory.") - return - end + if not project_root then return print("Error: Must be inside the 'src' directory.") end local src_dir = project_root .. "/src" local out_dir = project_root .. "/build" - vim.fn.mkdir(out_dir, "p") - local compile_command = string.format("javac -d %s %s/*.java", out_dir, src_dir) - local compile_status = vim.fn.system(compile_command) - if vim.v.shell_error ~= 0 then - print("Error during compilation:\n" .. compile_status) - else - print("Compilation successful!") - end + local compile_command = string.format("javac -d %s %s/*.java", out_dir, src_dir) + local term_buf = M.open_float_terminal(compile_command) + + local output = vim.fn.system(compile_command) + local success = vim.v.shell_error == 0 + + vim.api.nvim_buf_set_lines(term_buf, 0, -1, false, vim.list_extend({ success and "Compilation successful!" or "Error during compilation:" }, vim.split(output, "\n", { trimempty = true }))) + vim.api.nvim_buf_set_option(term_buf, "modifiable", false) end --- Run Java program in floating terminal function M.run() - local current_dir = vim.fn.expand("%:p:h") - local project_root = current_dir:match("(.*)/src") - if not project_root then - print("Error: Must be inside the 'src' directory.") - return - end - - local out_dir = project_root .. "/build" - M.open_float_terminal("java -cp " .. out_dir .. " Main") + local project_root = vim.fn.expand("%:p:h"):match("(.*)/src") + if not project_root then return print("Error: Must be inside the 'src' directory.") end + M.open_float_terminal("java -cp " .. project_root .. "/build" .. " Main") end return M