Skip to content

Commit 8d504ee

Browse files
committed
Fuzzy search autocomplete arguments
1 parent b514450 commit 8d504ee

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

awsshell/autocomplete.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from awsshell.fuzzy import fuzzy_search
2+
13
EMPTY = {'arguments': [], 'commands': [], 'children': {}}
24
import logging
35
logging.basicConfig(filename='/tmp/completions', level=logging.DEBUG)
@@ -92,25 +94,8 @@ def autocomplete(self, line):
9294
# in either of the above two cases.
9395
return self._current['commands'][:]
9496
elif last_word.startswith('-'):
95-
return self._autocomplete_options(last_word)
96-
return self._score(last_word, self._current['commands'])
97-
98-
def _score(self, word, corpus):
99-
# This is a set of heuristics for what makes the
100-
# most sense to autocomplete.
101-
# The first thing are straight prefixes. If anything
102-
# you specify is an actual prefix, then we'll just
103-
# stick with that.
104-
# Note: I have a feeling I'll be messing with this
105-
# algorithm for a while. It might make sense to refactor
106-
# this out.
107-
prefix = [c for c in corpus if c.startswith(word)]
108-
if prefix:
109-
return prefix
110-
subsequence = [c for c in corpus if is_subsequence(word, c)]
111-
if subsequence:
112-
return subsequence
113-
return []
97+
return fuzzy_search(last_word, self._current['arguments'])
98+
return fuzzy_search(last_word, self._current['commands'])
11499

115100
def _handle_backspace(self):
116101
return self._complete_from_full_parse()

0 commit comments

Comments
 (0)