Update init.lua for automatically loading language based on filetype

This commit is contained in:
DarthMooMancer
2025-03-13 23:44:58 -04:00
parent 293c2df3b4
commit 91e69efe03
3 changed files with 338 additions and 317 deletions
+25 -4
View File
@@ -1,8 +1,29 @@
-- init.lua
local M = {}
M.java = require("Polydev.java")
M.c = require("Polydev.c")
-- Store loaded language modules
M.loaded_languages = {}
-- Function to load the appropriate language module
function M.load_language_module()
local filetype = vim.bo.filetype
if M.loaded_languages[filetype] then return end -- Prevent redundant loading
local ok, lang_module = pcall(require, "Polydev." .. filetype)
if ok and lang_module.setup then
lang_module.setup()
M.loaded_languages[filetype] = true
end
end
-- Setup function to initialize the plugin
function M.setup()
-- Auto-load the correct module when opening a file
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
callback = function()
M.load_language_module()
end,
})
end
return M