Update c.lua
This commit is contained in:
+9
-40
@@ -150,12 +150,12 @@ function M.create_project()
|
|||||||
vim.fn.mkdir(include_dir, "p")
|
vim.fn.mkdir(include_dir, "p")
|
||||||
|
|
||||||
-- Write project name to file
|
-- Write project name to file
|
||||||
local project_name_file = io.open(build_dir .. "/project_name.txt", "w")
|
local project_name_file = io.open(build_dir .. "/project_name.polydev", "w")
|
||||||
if project_name_file then
|
if project_name_file then
|
||||||
project_name_file:write(project_name)
|
project_name_file:write(project_name)
|
||||||
project_name_file:close()
|
project_name_file:close()
|
||||||
else
|
else
|
||||||
print("Error creating project_name.txt")
|
print("Error creating project_name.polydev")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Write the Main.java file
|
-- Write the Main.java file
|
||||||
@@ -289,9 +289,9 @@ function M.build()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local build_dir = project_root .. "/build"
|
local build_dir = project_root .. "/build"
|
||||||
local files = vim.fn.glob(build_dir .. "/*.txt", true, true)
|
local files = vim.fn.glob(build_dir .. "/*.polydev", true, true)
|
||||||
if #files == 0 then
|
if #files == 0 then
|
||||||
print("Error: No .txt file found in the build directory.")
|
print("Error: No .polydev file found in the build directory.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -326,52 +326,21 @@ function M.run()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local build_dir = project_root .. "/build"
|
local build_dir = project_root .. "/build"
|
||||||
|
local files = vim.fn.glob(build_dir .. "/*.polydev", true, true)
|
||||||
-- Find an executable file
|
|
||||||
local files = vim.fn.glob(build_dir .. "/*", true, true)
|
|
||||||
local project_name = nil
|
local project_name = nil
|
||||||
for _, file in ipairs(files) do
|
for _, file in ipairs(files) do
|
||||||
-- Check if file is executable and not a directory
|
if vim.fn.match(file, "CMakeCache.txt") == -1 then
|
||||||
if vim.fn.filereadable(file) == 1 and vim.fn.match(file, "CMakeCache.txt") == -1 then
|
project_name = vim.fn.fnamemodify(file, ":r")
|
||||||
project_name = file
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not project_name then
|
if not project_name then
|
||||||
print("Error: No valid executable found in the build directory.")
|
print("Error: No valid project name file found in the build directory.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
M.open_float_terminal("cd " .. build_dir .. " && ./" .. vim.fn.fnamemodify(project_name, ":t"))
|
M.open_float_terminal("cd " .. build_dir .. " && ./" .. project_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- function M.run()
|
|
||||||
-- local current_dir = vim.fn.expand("%:p:h")
|
|
||||||
-- local project_root = current_dir:match("(.*)/src")
|
|
||||||
--
|
|
||||||
-- if not project_root then
|
|
||||||
-- print("Error: src directory not found.")
|
|
||||||
-- return
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- local build_dir = project_root .. "/build"
|
|
||||||
-- local files = vim.fn.glob(build_dir .. "/*.txt", true, true)
|
|
||||||
-- local project_name = nil
|
|
||||||
-- 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
|
|
||||||
-- end
|
|
||||||
--
|
|
||||||
-- M.open_float_terminal("cd " .. build_dir .. " && ./" .. project_name)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user