Update c.lua
This commit is contained in:
+10
-8
@@ -227,18 +227,21 @@ end
|
||||
function M.build()
|
||||
local current_dir = vim.fn.expand("%:p:h")
|
||||
|
||||
-- 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.")
|
||||
-- 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?")
|
||||
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
|
||||
-- Get the root directory where CMakeLists.txt is located
|
||||
project_root = vim.fn.fnamemodify(project_root, ":h")
|
||||
|
||||
-- Define the build directory path
|
||||
local build_dir = project_root .. "/build"
|
||||
|
||||
-- Check if the build directory exists, and create it if it doesn't
|
||||
-- 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")
|
||||
@@ -262,7 +265,6 @@ function M.build()
|
||||
else
|
||||
print("Compilation successful!")
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Run Java program in floating terminal
|
||||
|
||||
Reference in New Issue
Block a user