Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-10 14:36:36 -04:00
parent c3ba889aa0
commit 79fd4378e0
+11 -15
View File
@@ -233,39 +233,35 @@ public class %s {
end end
function M.build() function M.build()
-- Get the current file's directory
local current_dir = vim.fn.expand("%:p:h") local current_dir = vim.fn.expand("%:p:h")
-- Try to find the root of the project by matching the path
local project_root = current_dir:match("(.*)/src") local project_root = current_dir:match("(.*)/src")
if not project_root then if not project_root then
print("Error: src directory not found.") print("Error: src directory not found.")
return return
end end
-- Define the build directory
local build_dir = project_root .. "/build" local build_dir = project_root .. "/build"
-- List files in the build directory and find the .txt file
local files = vim.fn.glob(build_dir .. "/*.txt", true, true) local files = vim.fn.glob(build_dir .. "/*.txt", true, true)
local project_name = nil if #files == 0 then
print("Error: No .txt file found in the build directory.")
-- Look for the project name by checking for files in the build directory
for _, file in ipairs(files) do
if vim.fn.match(file, "CMakeCache.txt") == -1 then
project_name = vim.fn.fnamemodify(file, ":r")
break
end
end
if not project_name then
print("Error: No valid project name file found in the build directory.")
return return
end end
-- Extract the project name from the .txt file's name (without the .txt extension)
local project_name = vim.fn.fnamemodify(files[1], ":r") -- :r removes the file extension
-- Build command -- Build command
local compile_command = "cd " .. build_dir .. " && cmake .. && make && chmod +x " .. project_name local compile_command = "cd " .. build_dir .. " && cmake .. && make && chmod +x " .. project_name
-- Open floating terminal to execute the build command -- Open floating terminal to execute the build command
local term_buf = M.open_float_terminal(compile_command) local term_buf = M.open_float_terminal(compile_command)
vim.api.nvim_buf_set_option(term_buf, "modifiable", true) vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
-- Run the compile command and capture output -- Run compile command and capture output
local compile_status = vim.fn.system(compile_command) local compile_status = vim.fn.system(compile_command)
-- Set message based on compile result -- Set message based on compile result