Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve autocompletion of parameters#996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sebastinas merged 3 commits intobpython:mainfromgpotter2:main
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletionsbpython/autocomplete.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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):
Expand DownExpand Up@@ -742,6 +747,16 @@ def get_completer(
double underscore methods like __len__ in method signatures
"""

def _cmpl_sort(x: str) -> Tuple[bool, ...]:
"""
Function used to sort the matches.
"""
# put parameters above everything in completion
return (
x[-1] != "=",
x,
)

for completer in completers:
try:
matches = completer.matches(
Expand All@@ -760,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

Expand Down
13 changes: 13 additions & 0 deletionsbpython/test/test_autocomplete.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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):
Expand DownExpand Up@@ -435,3 +444,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="},
)

[8]ページ先頭

©2009-2025 Movatter.jp