Can autocmds be placed inside config? #767
-
I am setting up -- nvim-metals
{
"scalameta/nvim-metals",
name = "metals",
ft = { "scala", "sbt", "java" },
dependencies = {
"nvim-lua/plenary.nvim",
},
-- stylua: ignore
keys = {
{ "<leader>cW", function () require('metals').hover_worksheet() end, desc = "Metals Worksheet" },
{ "<leader>cM", function () require('telescope').extensions.metals.commands() end, desc = "Telescope Metals Commands" },
},
config = function()
local metals_config = require("metals").bare_config()
metals_config.settings = {
showImplicitArguments = true,
showImplicitConversionsAndClasses = true,
showInferredType = true,
superMethodLensesEnabled = true,
}
metals_config.init_options.statusBarProvider = "on"
metals_config.capabilities = require("cmp_nvim_lsp").default_capabilities()
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})
end,
} Every time I open a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @kcaashish I have stumbled into the same issue today. I even used exactly the same config as the one you paste here. The quick solution for me was to make sure all my related config is up-to-date. I am running:
Let us know whether that works for you as well. |
Beta Was this translation helpful? Give feedback.
-
You could put the autocmds into the The trouble is with adding a filetype autocmd (the one you define in config) from within a filetype autocmd handler (the one lazy defined to load the plugin). Whether that's guaranteed to work or not I'm not sure |
Beta Was this translation helpful? Give feedback.
You could put the autocmds into the
init =
function which runs before loading (at neovims startup)The trouble is with adding a filetype autocmd (the one you define in config) from within a filetype autocmd handler (the one lazy defined to load the plugin). Whether that's guaranteed to work or not I'm not sure