Update c.lua
This commit is contained in:
+10
-8
@@ -227,18 +227,21 @@ end
|
|||||||
function M.build()
|
function M.build()
|
||||||
local current_dir = vim.fn.expand("%:p:h")
|
local current_dir = vim.fn.expand("%:p:h")
|
||||||
|
|
||||||
-- Prompt the user to input the project name
|
-- 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
|
||||||
|
|
||||||
-- Define the project root path based on the entered project name
|
-- 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")
|
||||||
|
|
||||||
|
-- Define the build directory path
|
||||||
local build_dir = project_root .. "/build"
|
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
|
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")
|
||||||
@@ -262,7 +265,6 @@ 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