From db6c9bdf6d9a1d128f04ffd053591b2e1289b08a Mon Sep 17 00:00:00 2001 From: gpotter2 <10530980+gpotter2@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:48:00 +0200 Subject: [PATCH 1/3] Complete parameters without input --- bpython/autocomplete.py | 7 ++++++- bpython/test/test_autocomplete.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bpython/autocomplete.py b/bpython/autocomplete.py index e0849c6d..10f039d2 100644 --- a/bpython/autocomplete.py +++ b/bpython/autocomplete.py @@ -604,7 +604,12 @@ def matches( return matches if matches else None def locate(self, cursor_offset: int, line: str) -> Optional[LinePart]: - return lineparts.current_word(cursor_offset, line) + r = lineparts.current_word(cursor_offset, line) + if r and r.word[-1] == "(": + # if the word ends with a (, it's the parent word with an empty + # param. Return an empty word + return lineparts.LinePart(r.stop, r.stop, "") + return r class ExpressionAttributeCompletion(AttrCompletion): diff --git a/bpython/test/test_autocomplete.py b/bpython/test/test_autocomplete.py index 0000b0b6..2bbd90b3 100644 --- a/bpython/test/test_autocomplete.py +++ b/bpython/test/test_autocomplete.py @@ -435,3 +435,7 @@ def func(apple, apricot, banana, carrot): self.assertSetEqual( com.matches(3, "car", funcprops=funcspec), {"carrot="} ) + self.assertSetEqual( + com.matches(5, "func(", funcprops=funcspec), + {"apple=", "apricot=", "banana=", "carrot="}, + ) From de333118a7dc89925c7e3d1f246271b814a4e37c Mon Sep 17 00:00:00 2001 From: gpotter2 <10530980+gpotter2@users.noreply.github.com> Date: Sat, 22 Jul 2023 16:49:55 +0200 Subject: [PATCH 2/3] Better completion results order --- bpython/autocomplete.py | 14 +++++++++++++- bpython/test/test_autocomplete.py | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bpython/autocomplete.py b/bpython/autocomplete.py index 10f039d2..73759992 100644 --- a/bpython/autocomplete.py +++ b/bpython/autocomplete.py @@ -747,6 +747,16 @@ def get_completer( double underscore methods like __len__ in method signatures """ + def _cmpl_sort(x: str) -> Tuple[Any, ...]: + """ + Function used to sort the matches. + """ + # put parameters above everything in completion + return ( + x[-1] != "=", + x, + ) + for completer in completers: try: matches = completer.matches( @@ -765,7 +775,9 @@ def get_completer( ) continue if matches is not None: - return sorted(matches), (completer if matches else None) + return sorted(matches, key=_cmpl_sort), ( + completer if matches else None + ) return [], None diff --git a/bpython/test/test_autocomplete.py b/bpython/test/test_autocomplete.py index 2bbd90b3..da32fbb8 100644 --- a/bpython/test/test_autocomplete.py +++ b/bpython/test/test_autocomplete.py @@ -106,6 +106,15 @@ def test_two_completers_get_both(self): cumulative = autocomplete.CumulativeCompleter([a, b]) self.assertEqual(cumulative.matches(3, "abc"), {"a", "b"}) + def test_order_completer(self): + a = self.completer(["ax", "ab="]) + b = self.completer(["aa"]) + cumulative = autocomplete.CumulativeCompleter([a, b]) + self.assertEqual( + autocomplete.get_completer([cumulative], 1, "a"), + (["ab=", "aa", "ax"], cumulative), + ) + class TestFilenameCompletion(unittest.TestCase): def setUp(self): From 77bed91c9ed6b242f1efeb68047ffb43172133d3 Mon Sep 17 00:00:00 2001 From: gpotter2 <10530980+gpotter2@users.noreply.github.com> Date: Wed, 26 Jul 2023 09:31:46 +0200 Subject: [PATCH 3/3] Apply suggestion --- bpython/autocomplete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpython/autocomplete.py b/bpython/autocomplete.py index 73759992..a36c7beb 100644 --- a/bpython/autocomplete.py +++ b/bpython/autocomplete.py @@ -747,7 +747,7 @@ def get_completer( double underscore methods like __len__ in method signatures """ - def _cmpl_sort(x: str) -> Tuple[Any, ...]: + def _cmpl_sort(x: str) -> Tuple[bool, ...]: """ Function used to sort the matches. """
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: