@@ -14,7 +14,9 @@ conds.is_endwise_node = function(nodes)
1414 if nodes == nil then return true end
1515 if # nodes == 0 then return true end
1616
17- vim .treesitter .get_parser ():parse ()
17+ local parser = vim .treesitter .get_parser (nil , nil , { error = false })
18+ if parser == nil then return end
19+ parser :parse ()
1820 local target = vim .treesitter .get_node ({ ignore_injections = false })
1921 if target ~= nil and utils .is_in_table (nodes , target :type ()) then
2022 local text = ts_get_node_text (target ) or {" " }
@@ -56,11 +58,6 @@ conds.is_in_range = function(callback, position)
5658 )
5759 return function (opts )
5860 log .debug (' is_in_range' )
59- -- `parser` will be a table (on success) or a string (error message)
60- local _ , parser = pcall (vim .treesitter .get_parser )
61- if not type (parser ) == ' string' then
62- return
63- end
6461 local cursor = position ()
6562 assert (
6663 type (cursor ) == ' table' and # cursor == 2 ,
@@ -70,7 +67,8 @@ conds.is_in_range = function(callback, position)
7067 local col = cursor [2 ]
7168
7269 local bufnr = 0
73- local root_lang_tree = vim .treesitter .get_parser (bufnr )
70+ local root_lang_tree = vim .treesitter .get_parser (bufnr , nil , { error = false })
71+ if root_lang_tree == nil then return end
7472 local lang_tree = root_lang_tree :language_for_range ({ line , col , line , col })
7573
7674 local result
@@ -109,7 +107,9 @@ conds.is_ts_node = function(nodes)
109107 log .debug (' is_ts_node' )
110108 if # nodes == 0 then return end
111109
112- vim .treesitter .get_parser ():parse ()
110+ local parser = vim .treesitter .get_parser (nil , nil , { error = false })
111+ if parser == nil then return end
112+ parser :parse ()
113113 local target = vim .treesitter .get_node ({ ignore_injections = false })
114114 if target ~= nil and utils .is_in_table (nodes , target :type ()) then
115115 return true
@@ -125,7 +125,9 @@ conds.is_not_ts_node = function(nodes)
125125 log .debug (' is_not_ts_node' )
126126 if # nodes == 0 then return end
127127
128- vim .treesitter .get_parser ():parse ()
128+ local parser = vim .treesitter .get_parser (nil , nil , { error = false })
129+ if parser == nil then return end
130+ parser :parse ()
129131 local target = vim .treesitter .get_node ({ ignore_injections = false })
130132 if target ~= nil and utils .is_in_table (nodes , target :type ()) then
131133 return false
@@ -138,7 +140,9 @@ conds.is_not_ts_node_comment = function()
138140 log .debug (' not_in_ts_node_comment' )
139141 if not opts .ts_node then return end
140142
141- vim .treesitter .get_parser ():parse ()
143+ local parser = vim .treesitter .get_parser (nil , nil , { error = false })
144+ if parser == nil then return end
145+ parser :parse ()
142146 local target = vim .treesitter .get_node ({ ignore_injections = false })
143147 if target ~= nil and utils .is_in_table (opts .ts_node , target :type ()) then
144148 return false
@@ -150,6 +154,7 @@ conds.is_not_in_context = function()
150154 return function (opts )
151155 local context = require (" nvim-autopairs.ts-utils" )
152156 .get_language_tree_at_position ({ utils .get_cursor () })
157+ if context == nil then return end
153158 if not vim .tbl_contains (opts .rule .filetypes , context :lang ()) then
154159 return false
155160 end
0 commit comments