From 0aa14ca7e1cd984eed359af6447a2df16e4dd8e1 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 24 Jun 2024 11:10:08 +0200 Subject: [nvim] force attach LSP servers to buffer with filetype set --- .config/nvim/plugins.vim | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to '.config/nvim') diff --git a/.config/nvim/plugins.vim b/.config/nvim/plugins.vim index a333ac1..1be788d 100644 --- a/.config/nvim/plugins.vim +++ b/.config/nvim/plugins.vim @@ -151,6 +151,46 @@ require('lazy').setup({ require('lspconfig')[server_name].setup(lspconfig_setup) end } + + -- fix LSPs not attaching to buffer sometimes + local filetypes = { + { + pattern = '*.php', + filetype = 'php', + }, + { + pattern = '*.js', + filetype = 'javascript', + }, + { + pattern = '*.vue', + filetype = 'vue', + }, + { + pattern = '*.twig', + filetype = 'twig', + }, + { + pattern = '*.lua', + filetype = 'lua', + }, + { + pattern = '*.vim', + filetype = 'vim', + }, + { + pattern = '*.mcfunction', + filetype = 'mcfunction', + }, + } + for _, entry in ipairs(filetypes) do + vim.api.nvim_create_autocmd({ 'BufEnter' }, { + pattern = { entry['pattern'] }, + callback = function(event) + vim.cmd('set filetype=' .. entry['filetype']) + end, + }) + end end, }, -- cgit v1.2.3