Refactor the code
This commit is contained in:
parent
714d9c1825
commit
7a6dbbaa02
15
init.lua
15
init.lua
|
|
@ -972,20 +972,19 @@ require('lazy').setup({
|
||||||
return
|
return
|
||||||
end
|
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'
|
local installed_parsers = require('nvim-treesitter').get_installed 'parsers'
|
||||||
|
|
||||||
if vim.tbl_contains(installed_parsers, language) then
|
if vim.tbl_contains(installed_parsers, language) then
|
||||||
|
-- enable the parser if it is installed
|
||||||
treesitter_try_attach(buf, language)
|
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()
|
require('nvim-treesitter').install(language):await(function()
|
||||||
treesitter_try_attach(buf, language)
|
treesitter_try_attach(buf, language)
|
||||||
end)
|
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
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue