Update init.lua

This commit is contained in:
DarthMooMancer
2025-02-19 18:32:31 -05:00
committed by GitHub
parent 28cffd0480
commit 60c60d3697
+35 -37
View File
@@ -18,38 +18,34 @@ end
-- Create a new Java project -- Create a new Java project
function M.create_project() function M.create_project()
-- Ensure the prompt is a string (to avoid invalid arguments) -- Use vim.ui.input for better handling of input
local prompt = "Enter project name: " vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
-- Debugging: Output the input received
print("Input received: " .. (project_name or "nil"))
-- Use vim.fn.input to capture the input -- Check if the project name is valid
local project_name = vim.fn.input(prompt) if not project_name or project_name == "" then
print("Project creation canceled.")
return
end
-- Debugging: Output the input received -- Paths for the project
print("Input received: " .. (project_name or "nil")) local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name
local src_dir = project_root .. "/root/src"
local out_dir = project_root .. "/root/out"
-- Check if the project name is valid -- Debugging: Print the paths
if not project_name or project_name == "" then print("Project root: " .. project_root)
print("Project creation canceled.") print("Source directory: " .. src_dir)
return print("Output directory: " .. out_dir)
end
-- Paths for the project -- Create directories
local project_root = vim.fn.expand(M.config.project_root) .. "/" .. project_name vim.fn.mkdir(src_dir, "p")
local src_dir = project_root .. "/root/src" vim.fn.mkdir(out_dir, "p")
local out_dir = project_root .. "/root/out"
-- Debugging: Print the paths -- Write the Main.java file
print("Project root: " .. project_root) local main_java_path = src_dir .. "/Main.java"
print("Source directory: " .. src_dir) local main_java_content = [[
print("Output directory: " .. out_dir)
-- Create directories
vim.fn.mkdir(src_dir, "p")
vim.fn.mkdir(out_dir, "p")
-- Write the Main.java file
local main_java_path = src_dir .. "/Main.java"
local main_java_content = [[
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello, World!"); System.out.println("Hello, World!");
@@ -57,19 +53,21 @@ public class Main {
} }
]] ]]
-- Create the file and write content -- Create the file and write content
local file = io.open(main_java_path, "w") local file = io.open(main_java_path, "w")
if file then if file then
file:write(main_java_content) file:write(main_java_content)
file:close() file:close()
vim.cmd("edit " .. main_java_path) vim.cmd("edit " .. main_java_path)
print("Project '" .. project_name .. "' created at " .. project_root) print("Project '" .. project_name .. "' created at " .. project_root)
else else
print("Error creating Main.java") print("Error creating Main.java")
end end
end)
end end
-- Create a new Java file -- Create a new Java file
function M.create_new_file() function M.create_new_file()
vim.ui.input({ prompt = "Enter class name: " }, function(class_name) vim.ui.input({ prompt = "Enter class name: " }, function(class_name)