Update c.lua
This commit is contained in:
+9
-7
@@ -233,20 +233,19 @@ 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
|
local project_name = nil
|
||||||
|
|
||||||
|
-- Look for the project name by checking for files in the build directory
|
||||||
for _, file in ipairs(files) do
|
for _, file in ipairs(files) do
|
||||||
if vim.fn.match(file, "CMakeCache.txt") == -1 then
|
if vim.fn.match(file, "CMakeCache.txt") == -1 then
|
||||||
project_name = vim.fn.fnamemodify(file, ":r")
|
project_name = vim.fn.fnamemodify(file, ":r")
|
||||||
@@ -254,16 +253,19 @@ function M.build()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Extract the project name from the .txt file's name (without the .txt extension)
|
if not project_name then
|
||||||
local project_name = vim.fn.fnamemodify(files[1], ":r") -- :r removes the file extension
|
print("Error: No valid project name file found in the build directory.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- 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 compile command and capture output
|
-- Run the 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
|
||||||
|
|||||||
Reference in New Issue
Block a user