Update init.lua
This commit is contained in:
+26
-12
@@ -24,15 +24,25 @@ function M.create_project()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Expand and sanitize the project root path
|
||||||
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
|
||||||
local src_dir = project_root .. "/root/src"
|
local src_dir = project_root .. "/root/src"
|
||||||
local out_dir = project_root .. "/root/out"
|
local out_dir = project_root .. "/root/out"
|
||||||
|
|
||||||
-- Create directories
|
-- Debugging: Print paths
|
||||||
vim.fn.mkdir(src_dir, "p")
|
print("Creating project at:", project_root)
|
||||||
vim.fn.mkdir(out_dir, "p")
|
|
||||||
|
|
||||||
-- Write Main.java
|
-- Create directories
|
||||||
|
local mkdir_status1 = vim.fn.mkdir(src_dir, "p")
|
||||||
|
local mkdir_status2 = vim.fn.mkdir(out_dir, "p")
|
||||||
|
|
||||||
|
-- Debugging: Check if directories were created
|
||||||
|
if not vim.loop.fs_stat(src_dir) or not vim.loop.fs_stat(out_dir) then
|
||||||
|
print("Error: Failed to create project directories.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Path for Main.java
|
||||||
local main_java_path = src_dir .. "/Main.java"
|
local main_java_path = src_dir .. "/Main.java"
|
||||||
local main_java_content = [[
|
local main_java_content = [[
|
||||||
public class Main {
|
public class Main {
|
||||||
@@ -41,15 +51,19 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]
|
]]
|
||||||
local file = io.open(main_java_path, "w")
|
|
||||||
if file then
|
-- Attempt to write to the file
|
||||||
file:write(main_java_content)
|
local file, err = io.open(main_java_path, "w")
|
||||||
file:close()
|
if not file then
|
||||||
vim.cmd("edit " .. main_java_path)
|
print("Error creating Main.java:", err)
|
||||||
print("Project '" .. project_name .. "' created at " .. project_root)
|
return
|
||||||
else
|
|
||||||
print("Error creating Main.java")
|
|
||||||
end
|
end
|
||||||
|
file:write(main_java_content)
|
||||||
|
file:close()
|
||||||
|
|
||||||
|
-- Open the new Java file
|
||||||
|
vim.cmd("edit " .. main_java_path)
|
||||||
|
print("Project '" .. project_name .. "' created at " .. project_root)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user