From b9571902f935f3d62336b0611479732ee84ae3cd Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Mon, 10 Mar 2025 13:23:33 -0400 Subject: [PATCH] Update c.lua --- lua/Polydev/c.lua | 62 +++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/lua/Polydev/c.lua b/lua/Polydev/c.lua index 27eb579..3112514 100644 --- a/lua/Polydev/c.lua +++ b/lua/Polydev/c.lua @@ -225,46 +225,40 @@ end -- Compile Java files function M.build() - local current_dir = vim.fn.expand("%:p:h") + -- local compile_command = "mv " .. legacy_src_dir .. "/* " .. src_dir .. + -- " && mv " .. legacy_out_dir .. "/* " .. build_dir .. + -- " && rm -rd " .. project_root .. "/" .. "root/" - -- Get the project root directory by searching for CMakeLists.txt - local project_root = vim.fn.findfile("CMakeLists.txt", current_dir .. ";") - - if project_root == "" then - print("Could not find CMakeLists.txt. Are you in a project directory?") - return - end + vim.ui.input({ prompt = "Enter project name: " }, function(project_name) + if not project_name or project_name == "" then + print("Project creation canceled.") + return + end - -- Get the root directory where CMakeLists.txt is located - project_root = vim.fn.fnamemodify(project_root, ":h") + local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name + print("Project Root: " .. project_root) - -- Define the build directory path - local build_dir = project_root .. "/build" + local into_build = "cd " .. project_root .. "/build" + local into_build_status = vim.fn.system(into_build) + if vim.v.shell_error ~= 0 then + print("Could not go into build dir:\n" .. into_build_status) + end - -- Check if the build directory exists, create it if it doesn't - if vim.fn.isdirectory(build_dir) == 0 then - print("Build directory does not exist. Creating: " .. build_dir) - vim.fn.mkdir(build_dir, "p") - end + -- local project_root_build = current_dir:match("(.*)/build") + -- if not project_root_build then + -- print("Error: Must be inside the 'build' directory.") + -- return + -- end - -- Change to the build directory - local into_build = "cd " .. build_dir - local into_build_status = vim.fn.system(into_build) + local compile_command = "cmake .. && make" + local compile_status = vim.fn.system(compile_command) - if vim.v.shell_error ~= 0 then - print("Could not change into build dir:\n" .. into_build_status) - return - end - - -- Run cmake and make to build the project - local compile_command = "cmake .. && make" - 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 + if vim.v.shell_error ~= 0 then + print("Error during compilation:\n" .. compile_status) + else + print("Compilation successful!") + end + end) end -- Run Java program in floating terminal