Update c.lua
This commit is contained in:
+17
-23
@@ -225,38 +225,31 @@ 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?")
|
||||
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"
|
||||
|
||||
-- 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
|
||||
|
||||
-- Change to the build directory
|
||||
local into_build = "cd " .. build_dir
|
||||
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 change into build dir:\n" .. into_build_status)
|
||||
return
|
||||
print("Could not go into build dir:\n" .. into_build_status)
|
||||
end
|
||||
|
||||
-- Run cmake and make to build the project
|
||||
-- local project_root_build = current_dir:match("(.*)/build")
|
||||
-- if not project_root_build then
|
||||
-- print("Error: Must be inside the 'build' directory.")
|
||||
-- return
|
||||
-- end
|
||||
|
||||
local compile_command = "cmake .. && make"
|
||||
local compile_status = vim.fn.system(compile_command)
|
||||
|
||||
@@ -265,6 +258,7 @@ function M.build()
|
||||
else
|
||||
print("Compilation successful!")
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Run Java program in floating terminal
|
||||
|
||||
Reference in New Issue
Block a user