now you can create a project no matter what
This commit is contained in:
+31
-11
@@ -1,29 +1,49 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Store loaded language modules
|
|
||||||
M.loaded_languages = {}
|
M.loaded_languages = {}
|
||||||
|
M.java = require("Polydev.java")
|
||||||
|
M.c = require("Polydev.c")
|
||||||
|
|
||||||
-- Function to load the appropriate language module
|
-- Load language module dynamically
|
||||||
function M.load_language_module()
|
function M.load_language_module(lang)
|
||||||
local filetype = vim.bo.filetype
|
if M.loaded_languages[lang] then return true end -- Prevent redundant loading
|
||||||
if M.loaded_languages[filetype] then return end -- Prevent redundant loading
|
|
||||||
|
|
||||||
local ok, lang_module = pcall(require, "Polydev." .. filetype)
|
local ok, lang_module = pcall(require, "Polydev." .. lang)
|
||||||
if ok and lang_module.setup then
|
if ok and lang_module.setup then
|
||||||
lang_module.setup()
|
lang_module.setup()
|
||||||
M.loaded_languages[filetype] = true
|
M.loaded_languages[lang] = lang_module
|
||||||
end
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Setup function to initialize the plugin
|
print("Error: Unsupported language '" .. lang .. "'")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create a new project by specifying a language
|
||||||
|
function M.create_project()
|
||||||
|
vim.ui.input({ prompt = "Enter language for project: " }, function(lang)
|
||||||
|
if not lang or lang == "" then return print("Project creation canceled.") end
|
||||||
|
|
||||||
|
if M.load_language_module(lang) and M.loaded_languages[lang].create_project then
|
||||||
|
M.loaded_languages[lang].create_project()
|
||||||
|
else
|
||||||
|
print("Error: No project creation method for " .. lang)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Auto-load language module based on file type
|
||||||
function M.setup()
|
function M.setup()
|
||||||
-- Auto-load the correct module when opening a file
|
vim.api.nvim_create_user_command("NewProject", M.run, {})
|
||||||
|
vim.keymap.set("n", "<leader>np", ":NewProject<CR>", { silent = true })
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
M.load_language_module()
|
local filetype = vim.bo.filetype
|
||||||
|
M.load_language_module(filetype)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user