Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-10 13:17:35 -04:00
parent f91293e2ff
commit eb12eee9cb
+32 -30
View File
@@ -227,42 +227,44 @@ end
function M.build() function M.build()
local current_dir = vim.fn.expand("%:p:h") local current_dir = vim.fn.expand("%:p:h")
-- Prompt the user to input the project name -- Get the project root directory by searching for CMakeLists.txt
vim.ui.input({ prompt = "Enter project name: " }, function(project_name) local project_root = vim.fn.findfile("CMakeLists.txt", current_dir .. ";")
if not project_name or project_name == "" then
print("Project creation canceled.") if project_root == "" then
return print("Could not find CMakeLists.txt. Are you in a project directory?")
end return
end
-- Define the project root path based on the entered project name -- Get the root directory where CMakeLists.txt is located
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name project_root = vim.fn.fnamemodify(project_root, ":h")
local build_dir = project_root .. "/build"
-- Check if the build directory exists, and create it if it doesn't -- Define the build directory path
if vim.fn.isdirectory(build_dir) == 0 then local build_dir = project_root .. "/build"
print("Build directory does not exist. Creating: " .. build_dir)
vim.fn.mkdir(build_dir, "p")
end
-- Change to the build directory -- Check if the build directory exists, create it if it doesn't
local into_build = "cd " .. build_dir if vim.fn.isdirectory(build_dir) == 0 then
local into_build_status = vim.fn.system(into_build) print("Build directory does not exist. Creating: " .. build_dir)
vim.fn.mkdir(build_dir, "p")
end
if vim.v.shell_error ~= 0 then -- Change to the build directory
print("Could not change into build dir:\n" .. into_build_status) local into_build = "cd " .. build_dir
return local into_build_status = vim.fn.system(into_build)
end
-- Run cmake and make to build the project if vim.v.shell_error ~= 0 then
local compile_command = "cmake .. && make" print("Could not change into build dir:\n" .. into_build_status)
local compile_status = vim.fn.system(compile_command) return
end
if vim.v.shell_error ~= 0 then -- Run cmake and make to build the project
print("Error during compilation:\n" .. compile_status) local compile_command = "cmake .. && make"
else local compile_status = vim.fn.system(compile_command)
print("Compilation successful!")
end if vim.v.shell_error ~= 0 then
end) print("Error during compilation:\n" .. compile_status)
else
print("Compilation successful!")
end
end end
-- Run Java program in floating terminal -- Run Java program in floating terminal