Update c.lua
This commit is contained in:
+9
-7
@@ -233,20 +233,19 @@ public class %s {
|
||||
end
|
||||
|
||||
function M.build()
|
||||
-- Get the current file's directory
|
||||
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")
|
||||
|
||||
if not project_root then
|
||||
print("Error: src directory not found.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Define the build directory
|
||||
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 project_name = nil
|
||||
|
||||
-- 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")
|
||||
@@ -254,16 +253,19 @@ function M.build()
|
||||
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
|
||||
if not project_name then
|
||||
print("Error: No valid project name file found in the build directory.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Build command
|
||||
local compile_command = "cd " .. build_dir .. " && cmake .. && make && chmod +x " .. project_name
|
||||
|
||||
-- Open floating terminal to execute the build command
|
||||
local term_buf = M.open_float_terminal(compile_command)
|
||||
vim.api.nvim_buf_set_option(term_buf, "modifiable", true)
|
||||
|
||||
-- Run compile command and capture output
|
||||
-- Run the compile command and capture output
|
||||
local compile_status = vim.fn.system(compile_command)
|
||||
|
||||
-- Set message based on compile result
|
||||
|
||||
Reference in New Issue
Block a user