@@ -94,10 +94,10 @@ impl Tree {
9494 rest,
9595 ) ;
9696 } else if before_dot. is_type ( Nonterminal ( name_def) )
97- && matches ! (
98- before_dot . parent( ) . unwrap ( ) . type_ ( ) ,
99- Nonterminal ( dotted_as_name ) | ErrorNonterminal ( dotted_as_name )
100- )
97+ && before_dot
98+ . parent ( )
99+ . unwrap ( )
100+ . is_type_or_error_thereof ( Nonterminal ( dotted_as_name ) )
101101 {
102102 return (
103103 scope,
@@ -106,10 +106,11 @@ impl Tree {
106106 } ,
107107 rest,
108108 ) ;
109- } else if matches ! (
110- previous. parent( ) . unwrap( ) . type_( ) ,
111- Nonterminal ( import_from) | ErrorNonterminal ( import_from)
112- ) {
109+ } else if previous
110+ . parent ( )
111+ . unwrap ( )
112+ . is_type_or_error_thereof ( Nonterminal ( import_from) )
113+ {
113114 return (
114115 scope,
115116 CompletionNode :: ImportFromFirstPart {
@@ -125,10 +126,11 @@ impl Tree {
125126 }
126127 }
127128 "from" | "..." => {
128- if matches ! (
129- previous. parent( ) . unwrap( ) . type_( ) ,
130- Nonterminal ( import_from) | ErrorNonterminal ( import_from)
131- ) {
129+ if previous
130+ . parent ( )
131+ . unwrap ( )
132+ . is_type_or_error_thereof ( Nonterminal ( import_from) )
133+ {
132134 return (
133135 scope,
134136 CompletionNode :: ImportFromFirstPart {
@@ -238,12 +240,9 @@ fn context(node: PyNode) -> Option<CompletionContext> {
238240 "(" => node. parent ( ) ?,
239241 "," => {
240242 let parent = node. parent ( ) ?;
241- if parent. is_type ( Nonterminal ( arguments) ) || parent. is_type ( ErrorNonterminal ( arguments) )
242- {
243+ if parent. is_type_or_error_thereof ( Nonterminal ( arguments) ) {
243244 parent. parent ( ) ?
244- } else if parent. is_type ( Nonterminal ( kwargs) )
245- || parent. is_type ( ErrorNonterminal ( kwargs) )
246- {
245+ } else if parent. is_type_or_error_thereof ( Nonterminal ( kwargs) ) {
247246 parent. parent ( ) ?. parent ( ) ?
248247 } else {
249248 return None ;
@@ -301,7 +300,7 @@ fn call_args(node: PyNode) -> Option<CallArgs> {
301300 Nonterminal ( stmt) ,
302301 ErrorNonterminal ( stmt) ,
303302 ] ) ?;
304- ( args. is_type ( Nonterminal ( arguments) ) || args . is_type ( ErrorNonterminal ( arguments ) ) )
303+ args. is_type_or_error_thereof ( Nonterminal ( arguments) )
305304 . then_some ( CallArgs ( args) )
306305}
307306
@@ -318,8 +317,7 @@ impl<'db> CallArgs<'db> {
318317 }
319318 if child. is_type ( Nonterminal ( named_expression) ) {
320319 positional_args += 1 ;
321- } else if child. is_type ( Nonterminal ( kwargs) ) || child. is_type ( ErrorNonterminal ( kwargs) )
322- {
320+ } else if child. is_type_or_error_thereof ( Nonterminal ( kwargs) ) {
323321 for in_kwargs in child. iter_children ( ) {
324322 if in_kwargs. start ( ) >= until. node . start ( ) {
325323 break ' outer;
@@ -355,10 +353,7 @@ fn from_import_dots_before_node(leaf: PyNode) -> usize {
355353
356354fn import_from_target_node ( node : PyNode ) -> CompletionNode {
357355 debug_assert ! (
358- matches!(
359- node. type_( ) ,
360- Nonterminal ( import_from) | ErrorNonterminal ( import_from) ,
361- ) ,
356+ node. is_type_or_error_thereof( Nonterminal ( import_from) ) ,
362357 "{:?}" ,
363358 node. type_( )
364359 ) ;
0 commit comments