Update c.lua
This commit is contained in:
+17
-23
@@ -225,38 +225,31 @@ end
|
|||||||
|
|
||||||
-- Compile Java files
|
-- Compile Java files
|
||||||
function M.build()
|
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
|
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
|
|
||||||
print("Could not find CMakeLists.txt. Are you in a project directory?")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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")
|
print("Project Root: " .. project_root)
|
||||||
|
|
||||||
-- Define the build directory path
|
local into_build = "cd " .. project_root .. "/build"
|
||||||
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_status = vim.fn.system(into_build)
|
local into_build_status = vim.fn.system(into_build)
|
||||||
|
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
print("Could not change into build dir:\n" .. into_build_status)
|
print("Could not go into build dir:\n" .. into_build_status)
|
||||||
return
|
|
||||||
end
|
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_command = "cmake .. && make"
|
||||||
local compile_status = vim.fn.system(compile_command)
|
local compile_status = vim.fn.system(compile_command)
|
||||||
|
|
||||||
@@ -265,6 +258,7 @@ function M.build()
|
|||||||
else
|
else
|
||||||
print("Compilation successful!")
|
print("Compilation successful!")
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run Java program in floating terminal
|
-- Run Java program in floating terminal
|
||||||
|
|||||||
Reference in New Issue
Block a user