@@ -174,7 +174,7 @@ async def resolve(self, sender: Any, completion_item: CompletionItem) -> Complet
174
174
175
175
176
176
_CompleteMethod = Callable [
177
- [ast .AST , List [ast .AST ], Position , Optional [CompletionContext ]],
177
+ [Any , ast .AST , List [ast .AST ], Position , Optional [CompletionContext ]],
178
178
Awaitable [Optional [Optional [List [CompletionItem ]]]],
179
179
]
180
180
@@ -287,27 +287,29 @@ def __init__(
287
287
288
288
_method_cache : Dict [Type [Any ], List [_CompleteMethod ]] = {}
289
289
290
- async def _find_methods (self , cls : Type [Any ]) -> AsyncIterator [_CompleteMethod ]:
291
- if cls in self ._method_cache :
292
- for m in self ._method_cache [cls ]:
290
+ @classmethod
291
+ def _find_methods (cls , visitor_cls : Type [Any ]) -> Iterator [_CompleteMethod ]:
292
+ if visitor_cls in cls ._method_cache :
293
+ for m in cls ._method_cache [visitor_cls ]:
293
294
yield m
295
+ return
294
296
295
297
methods = []
296
- if cls is ast .AST :
298
+ if visitor_cls is ast .AST :
297
299
return
298
300
299
- method_name = "complete_" + cls .__name__
300
- if hasattr (self , method_name ):
301
- method = getattr (self , method_name )
301
+ method_name = "complete_" + visitor_cls .__name__
302
+ if hasattr (cls , method_name ):
303
+ method = getattr (cls , method_name )
302
304
if callable (method ):
303
305
methods .append (method )
304
306
yield cast (_CompleteMethod , method )
305
- for base in cls .__bases__ :
306
- async for m in self ._find_methods (base ):
307
+ for base in visitor_cls .__bases__ :
308
+ for m in cls ._find_methods (base ):
307
309
methods .append (m )
308
310
yield m
309
311
310
- self ._method_cache [cls ] = methods
312
+ cls ._method_cache [visitor_cls ] = methods
311
313
312
314
async def collect (
313
315
self , position : Position , context : Optional [CompletionContext ]
@@ -320,8 +322,8 @@ async def collect(
320
322
321
323
async def iter_results () -> AsyncIterator [List [CompletionItem ]]:
322
324
for result_node in result_nodes :
323
- async for method in self ._find_methods (type (result_node )):
324
- r = await method (result_node , result_nodes , position , context )
325
+ for method in self ._find_methods (type (result_node )):
326
+ r = await method (self , result_node , result_nodes , position , context )
325
327
if r is not None :
326
328
yield r
327
329
@@ -721,20 +723,23 @@ def get_keyword_snipped_text(self, kw: KeywordDoc, in_template: bool) -> str:
721
723
722
724
else :
723
725
for index , match in enumerate (VariableMatches (kw .name , identifiers = "$" , ignore_errors = True )):
724
- var_name = variable [ 2 : - 1 ]. split (":" , 1 )[0 ]
726
+ var_name = match . base . split (":" , 1 )[0 ] if match . base else ""
725
727
result += match .before
726
- result += "${" + str (index + 1 ) + ":"
727
- if in_template :
728
- result += "\\ ${"
728
+ result += "${" + str (index + 1 )
729
729
730
- result += var_name
730
+ if var_name :
731
+ result += ":"
732
+ if in_template :
733
+ result += "\\ ${"
731
734
732
- if in_template :
733
- result += "\\ }"
735
+ result += var_name
736
+
737
+ if in_template :
738
+ result += "\\ }"
734
739
735
740
result += "}"
736
741
737
- if after :
742
+ if match . after :
738
743
result += match .after
739
744
740
745
return result
0 commit comments