mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Merge pull request #26 from kyazdani42/fix/config-isenabled
fix: config is enabled also checks parser existence
This commit is contained in:
commit
2ca0c348f7
2 changed files with 8 additions and 7 deletions
|
|
@ -1,5 +1,4 @@
|
|||
local api = vim.api
|
||||
local parsers = require'nvim-treesitter.parsers'
|
||||
local install = require'nvim-treesitter.install'
|
||||
local locals = require'nvim-treesitter.locals'
|
||||
local utils = require'nvim-treesitter.utils'
|
||||
|
|
@ -17,7 +16,7 @@ function M.setup(lang)
|
|||
|
||||
for _, ft in pairs(configs.available_parsers()) do
|
||||
for _, mod in pairs(configs.available_modules()) do
|
||||
if parsers.has_parser(ft) and configs.is_enabled(mod, ft) then
|
||||
if configs.is_enabled(mod, ft) then
|
||||
local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod)
|
||||
api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -206,7 +206,9 @@ local function enable_all(mod, ft)
|
|||
end
|
||||
end
|
||||
if ft then
|
||||
enable_mod_conf_autocmd(mod, ft)
|
||||
if parser_utils.has_parser(ft) then
|
||||
enable_mod_conf_autocmd(mod, ft)
|
||||
end
|
||||
else
|
||||
for _, ft in pairs(M.available_parsers()) do
|
||||
if parser_utils.has_parser(ft) then
|
||||
|
|
@ -245,9 +247,7 @@ local function disable_all(mod, ft)
|
|||
disable_mod_conf_autocmd(mod, ft)
|
||||
else
|
||||
for _, ft in pairs(M.available_parsers()) do
|
||||
if parser_utils.has_parser(ft) then
|
||||
disable_mod_conf_autocmd(mod, ft)
|
||||
end
|
||||
disable_mod_conf_autocmd(mod, ft)
|
||||
end
|
||||
config[mod].enable = false
|
||||
end
|
||||
|
|
@ -291,7 +291,9 @@ M.commands = {
|
|||
-- @param mod: module (string)
|
||||
-- @param ft: filetype (string)
|
||||
function M.is_enabled(mod, ft)
|
||||
if not M.get_parser_configs()[ft] then return false end
|
||||
if not M.get_parser_configs()[ft] or not parser_utils.has_parser(ft) then
|
||||
return false
|
||||
end
|
||||
|
||||
local module_config = M.get_config()[mod]
|
||||
if not module_config then return false end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue