Update c.lua
This commit is contained in:
+18
-6
@@ -98,7 +98,6 @@ local function write_file(path, content)
|
|||||||
print(path .. " created successfully!")
|
print(path .. " created successfully!")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create a new Java project
|
|
||||||
function M.create_project()
|
function M.create_project()
|
||||||
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
vim.ui.input({ prompt = "Enter project name: " }, function(project_name)
|
||||||
if not project_name or project_name == "" then
|
if not project_name or project_name == "" then
|
||||||
@@ -137,11 +136,24 @@ end
|
|||||||
|
|
||||||
function M.create_new_file()
|
function M.create_new_file()
|
||||||
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
|
vim.ui.input({ prompt = "Enter file name: " }, function(class_name)
|
||||||
if not class_name then return print("File creation canceled.") end
|
if not class_name or class_name == "" then
|
||||||
local root_dir = vim.fn.expand("%:p:h"):match("(.*)/src")
|
return print("File creation canceled.")
|
||||||
if not root_dir then return print("Error: src directory not found.") end
|
end
|
||||||
local c_content = [[]]
|
|
||||||
write_file(root_dir .. "/src/" .. class_name .. ".c", c_content)
|
local root_dir = M.get_project_root() -- Use a function to reliably find the project root
|
||||||
|
if not root_dir then
|
||||||
|
return print("Error: Project root not found.")
|
||||||
|
end
|
||||||
|
|
||||||
|
local file_path = root_dir .. "/src/" .. class_name .. ".c"
|
||||||
|
local file = io.open(file_path, "w")
|
||||||
|
if file then
|
||||||
|
file:close()
|
||||||
|
vim.cmd("edit " .. file_path)
|
||||||
|
print(class_name .. ".c created successfully!")
|
||||||
|
else
|
||||||
|
print("Error creating " .. class_name .. ".c")
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user