@@ -10,13 +10,9 @@ local TARGET_BLACKLIST_TYPE_MATCHERS = {
1010 " else" , -- else/elseif statements (lua)
1111 " elif" , -- else/elseif statements (py)
1212 " end_tag" , -- html closing tags
13- " declaration_list" , -- C# class blocks - these are structural containers
13+ " declaration_list" , -- C# class blocks
1414 " compound_statement" , -- C blocks when defined under their fn names like a psycho
15- -- Parent-child patterns: "child_type:parent_type"
16- " block:method_declaration" ,
17- " block:constructor_declaration" ,
18- " block:destructor_declaration" ,
19- " block:class_declaration" ,
15+ " c_sharp:block" , -- C# block nodes (language-specific)
2016}
2117
2218local HIGHLIGHT_BLACKLIST_TYPE_MATCHERS = {
@@ -33,22 +29,38 @@ local AUGMENT_TARGET_TYPE_MATCHERS = {
3329
3430local M = {}
3531
32+ --- Get the parser name for the current buffer
33+ --- @return string | nil
34+ local function get_parser_name ()
35+ local ok , parser = pcall (vim .treesitter .get_parser , 0 )
36+ if not ok or not parser then
37+ return nil
38+ end
39+
40+ local ok_lang , lang = pcall (parser .lang , parser )
41+ if not ok_lang then
42+ return nil
43+ end
44+
45+ return lang
46+ end
47+
3648--- @param node TSNode
3749--- @param matchers string[]
3850--- @return boolean
3951local function is_matched_in (node , matchers )
52+ local parser_name = get_parser_name ()
53+
4054 for _ , matcher in ipairs (matchers ) do
41- -- Check for parent-child pattern: "child_type:parent_type"
55+ -- Check if matcher is language-specific (contains ':')
4256 if matcher :find (" :" ) then
43- local child_type , parent_type = matcher :match (" ^([^:]+):([^:]+)$" )
44- if child_type and parent_type then
45- local parent = node :parent ()
46- if node :type ():match (child_type ) and parent and parent :type ():match (parent_type ) then
47- return true
48- end
57+ local lang , node_type = matcher :match (" ([^:]+):(.+)" )
58+ -- Only apply this matcher if we're in the specified language
59+ if parser_name and lang == parser_name and node :type ():match (node_type ) then
60+ return true
4961 end
5062 else
51- -- Simple type matching
63+ -- Regular matcher, apply to all languages
5264 if node :type ():match (matcher ) then
5365 return true
5466 end
0 commit comments