Skip to content

Commit 4634132

Browse files
committed
Refactor the code
1 parent 714d9c1 commit 4634132

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

init.lua

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -972,20 +972,19 @@ require('lazy').setup({
972972
return
973973
end
974974

975-
-- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter`
976-
if not vim.tbl_contains(available_parsers, language) then
977-
treesitter_try_attach(buf, language)
978-
return
979-
end
980-
981-
-- if a parser is available in `nvim-treesitter` enable it after ensuring it is installed
982975
local installed_parsers = require('nvim-treesitter').get_installed 'parsers'
976+
983977
if vim.tbl_contains(installed_parsers, language) then
978+
-- enable the parser if it is installed
984979
treesitter_try_attach(buf, language)
985-
else
986-
require('nvim-treesitter').install(language):await(function()
980+
elseif vim.tbl_contains(available_parsers, language) then
981+
-- if a parser is available in `nvim-treesitter` enable it after ensuring it is installed
982+
require('nvim-treesitter.install').install(language):await(function()
987983
treesitter_try_attach(buf, language)
988984
end)
985+
else
986+
-- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter`
987+
treesitter_try_attach(buf, language)
989988
end
990989
end,
991990
})

0 commit comments

Comments
 (0)