@@ -555,11 +555,10 @@ def matches(
555
555
if r is None :
556
556
return None
557
557
558
- matches = set ()
559
558
n = len (r .word )
560
- for word in KEYWORDS :
561
- if self .method_match (word , n , r .word ):
562
- matches . add ( word )
559
+ matches = {
560
+ word for word in KEYWORDS if self .method_match (word , n , r .word )
561
+ }
563
562
for nspace in (builtins .__dict__ , locals_ ):
564
563
for word , val in nspace .items ():
565
564
# if identifier isn't ascii, don't complete (syntax error)
@@ -652,27 +651,36 @@ def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]:
652
651
653
652
else :
654
653
655
- class JediCompletion (BaseCompletionType ):
654
+ class MultilineJediCompletion (BaseCompletionType ): # type: ignore [no-redef]
656
655
_orig_start : Optional [int ]
657
656
658
657
def matches (
659
658
self ,
660
659
cursor_offset : int ,
661
660
line : str ,
662
661
* ,
662
+ current_block : Optional [str ] = None ,
663
663
history : Optional [List [str ]] = None ,
664
664
** kwargs : Any ,
665
665
) -> Optional [Set [str ]]:
666
- if history is None :
667
- return None
668
- if not lineparts .current_word (cursor_offset , line ):
666
+ if (
667
+ current_block is None
668
+ or history is None
669
+ or "\n " not in current_block
670
+ or not lineparts .current_word (cursor_offset , line )
671
+ ):
669
672
return None
670
673
674
+ assert cursor_offset <= len (line ), "{!r} {!r}" .format (
675
+ cursor_offset ,
676
+ line ,
677
+ )
678
+
671
679
combined_history = "\n " .join (itertools .chain (history , (line ,)))
672
680
try :
673
681
script = jedi .Script (combined_history , path = "fake.py" )
674
682
completions = script .complete (
675
- len ( combined_history .splitlines ()) , cursor_offset
683
+ combined_history .count ( " \n " ) + 1 , cursor_offset
676
684
)
677
685
except (jedi .NotFoundError , IndexError , KeyError ):
678
686
# IndexError for #483
@@ -688,8 +696,6 @@ def matches(
688
696
return None
689
697
assert isinstance (self ._orig_start , int )
690
698
691
- first_letter = line [self ._orig_start : self ._orig_start + 1 ]
692
-
693
699
matches = [c .name for c in completions ]
694
700
if any (
695
701
not m .lower ().startswith (matches [0 ][0 ].lower ()) for m in matches
@@ -699,35 +705,15 @@ def matches(
699
705
return None
700
706
else :
701
707
# case-sensitive matches only
708
+ first_letter = line [self ._orig_start ]
702
709
return {m for m in matches if m .startswith (first_letter )}
703
710
704
711
def locate (self , cursor_offset : int , line : str ) -> LinePart :
705
- assert isinstance ( self ._orig_start , int )
712
+ assert self ._orig_start is not None
706
713
start = self ._orig_start
707
714
end = cursor_offset
708
715
return LinePart (start , end , line [start :end ])
709
716
710
- class MultilineJediCompletion (JediCompletion ): # type: ignore [no-redef]
711
- def matches (
712
- self ,
713
- cursor_offset : int ,
714
- line : str ,
715
- * ,
716
- current_block : Optional [str ] = None ,
717
- history : Optional [List [str ]] = None ,
718
- ** kwargs : Any ,
719
- ) -> Optional [Set [str ]]:
720
- if current_block is None or history is None :
721
- return None
722
- if "\n " not in current_block :
723
- return None
724
-
725
- assert cursor_offset <= len (line ), "{!r} {!r}" .format (
726
- cursor_offset ,
727
- line ,
728
- )
729
- return super ().matches (cursor_offset , line , history = history )
730
-
731
717
732
718
def get_completer (
733
719
completers : Sequence [BaseCompletionType ],
0 commit comments