From 7a6dbbaa0240c1cc73b4d31bf2440c778990cfcb Mon Sep 17 00:00:00 2001 From: orip Date: Fri, 12 Dec 2025 13:03:32 +0200 Subject: [PATCH] Refactor the code --- init.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/init.lua b/init.lua index 72d4174b..ca2dd079 100644 --- a/init.lua +++ b/init.lua @@ -972,20 +972,19 @@ require('lazy').setup({ return end - -- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter` - if not vim.tbl_contains(available_parsers, language) then - treesitter_try_attach(buf, language) - return - end - - -- if a parser is available in `nvim-treesitter` enable it after ensuring it is installed local installed_parsers = require('nvim-treesitter').get_installed 'parsers' + if vim.tbl_contains(installed_parsers, language) then + -- enable the parser if it is installed treesitter_try_attach(buf, language) - else + elseif vim.tbl_contains(available_parsers, language) then + -- if a parser is available in `nvim-treesitter` enable it after ensuring it is installed require('nvim-treesitter').install(language):await(function() treesitter_try_attach(buf, language) end) + else + -- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter` + treesitter_try_attach(buf, language) end end, })