Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-10 13:13:50 -04:00
parent 4bf20a1eb7
commit f91293e2ff
+30 -32
View File
@@ -227,44 +227,42 @@ end
function M.build()
local current_dir = vim.fn.expand("%:p:h")
-- Try to find CMakeLists.txt or another specific file within the current directory or its parents
local project_root = vim.fn.findfile("CMakeLists.txt", current_dir .. ";")
-- Prompt the user to input the project name
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
if not project_name or project_name == "" then
print("Project creation canceled.")
return
end
if project_root == "" then
print("Could not find CMakeLists.txt. Are you in a project directory?")
return
end
-- Define the project root path based on the entered project name
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
local build_dir = project_root .. "/build"
-- Get the directory of CMakeLists.txt, which is the root of the project
project_root = vim.fn.fnamemodify(project_root, ":h")
-- Check if the build directory exists, and 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
-- Define the build directory path
local build_dir = project_root .. "/build"
-- Change to the build directory
local into_build = "cd " .. build_dir
local into_build_status = vim.fn.system(into_build)
-- 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
if vim.v.shell_error ~= 0 then
print("Could not change into build dir:\n" .. into_build_status)
return
end
-- Change to the build directory
local into_build = "cd " .. build_dir
local into_build_status = vim.fn.system(into_build)
-- 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("Could not go 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