@@ -92,21 +92,36 @@ def get_line_at_linenr(
9292 return None
9393
9494
95- def is_direct_match (
95+ def is_partial_direct_match (
9696 line : NginxLineConfig , filters : List [DirectiveFilter ]
9797) -> Optional [DirectiveFilter ]:
98+ """
99+ Check if the line matches any of the filters. If it does, return the
100+ filter. If it doesn't, return None."""
98101 for dfilter in filters :
99102 if dfilter .match (line ):
100- logger .debug (f"Direct match: { line } " )
103+ logger .debug (f"Direct match on filter { dfilter } : { line } " )
101104 return dfilter
102105 return None
103106
104107
105108def find_matches_in_children (
106109 line : NginxLineConfig , filters : List [DirectiveFilter ]
107110) -> Tuple [List [NginxLineConfig ], List [DirectiveFilter ]]:
108- matched_filter = is_direct_match (line , filters )
111+ """
112+ Check if the line matches filters. If it matches, return the line,
113+ the line's neighbours and all children. If it doesn't match, check
114+ if any of the children match the filters. If they do, return all
115+ descendants of the line that match the filters, including the current
116+ line.
117+ We also return a list of filters that matched, so we can check if
118+ all filters were matched eventually.
119+ If there are no matches, return an empty list for both the matching
120+ lines and the matched filters.
121+ """
122+ matched_filter = is_partial_direct_match (line , filters )
109123 if matched_filter :
124+ logger .debug (f"Found match in children: { line } " )
110125 all_matched_filters = set ([matched_filter ])
111126 # Search for remaining filters in children, as the parent
112127 # might still be looking for other filters
@@ -116,7 +131,9 @@ def find_matches_in_children(
116131 child , remaining_filters
117132 )
118133 all_matched_filters .update (child_matched_filters )
119- return [line , * get_children_recursive (line )], list (all_matched_filters )
134+ return [line , * line .neighbours , * get_children_recursive (line )], list (
135+ all_matched_filters
136+ )
120137
121138 # All filters must match at least one child
122139 matched_filters = set ()
0 commit comments