Update init.lua for automatically loading language based on filetype
This commit is contained in:
+25
-4
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user