Update c.lua
This commit is contained in:
+10
-12
@@ -227,21 +227,18 @@ end
|
|||||||
function M.build()
|
function M.build()
|
||||||
local current_dir = vim.fn.expand("%:p:h")
|
local current_dir = vim.fn.expand("%:p:h")
|
||||||
|
|
||||||
-- Try to find CMakeLists.txt or another specific file within the current directory or its parents
|
-- Prompt the user to input the project name
|
||||||
local project_root = vim.fn.findfile("CMakeLists.txt", current_dir .. ";")
|
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
||||||
|
if not project_name or project_name == "" then
|
||||||
if project_root == "" then
|
print("Project creation canceled.")
|
||||||
print("Could not find CMakeLists.txt. Are you in a project directory?")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the directory of CMakeLists.txt, which is the root of the project
|
-- Define the project root path based on the entered project name
|
||||||
project_root = vim.fn.fnamemodify(project_root, ":h")
|
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
||||||
|
|
||||||
-- Define the build directory path
|
|
||||||
local build_dir = project_root .. "/build"
|
local build_dir = project_root .. "/build"
|
||||||
|
|
||||||
-- Check if the build directory exists, create it if it doesn't
|
-- Check if the build directory exists, and create it if it doesn't
|
||||||
if vim.fn.isdirectory(build_dir) == 0 then
|
if vim.fn.isdirectory(build_dir) == 0 then
|
||||||
print("Build directory does not exist. Creating: " .. build_dir)
|
print("Build directory does not exist. Creating: " .. build_dir)
|
||||||
vim.fn.mkdir(build_dir, "p")
|
vim.fn.mkdir(build_dir, "p")
|
||||||
@@ -252,11 +249,11 @@ function M.build()
|
|||||||
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 go into build dir:\n" .. into_build_status)
|
print("Could not change into build dir:\n" .. into_build_status)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run CMake and Make to build the project
|
-- Run cmake and make to build the project
|
||||||
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 +262,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