Find completion matches for the given text. Given the user's input text and a collection of available completions, find completions matching the last word of the text. If `start_only` is True, the text will match an available completion only at the beginning
(
self,
orig_text: str,
collection: Collection,
start_only: bool = False,
fuzzy: bool = True,
casing: str | None = None,
text_before_cursor: str = '',
)
| 1367 | return (apply_case(completion) for completion in completions) |
| 1368 | |
| 1369 | def find_matches( |
| 1370 | self, |
| 1371 | orig_text: str, |
| 1372 | collection: Collection, |
| 1373 | start_only: bool = False, |
| 1374 | fuzzy: bool = True, |
| 1375 | casing: str | None = None, |
| 1376 | text_before_cursor: str = '', |
| 1377 | ) -> Generator[tuple[str, int], None, None]: |
| 1378 | """Find completion matches for the given text. |
| 1379 | |
| 1380 | Given the user's input text and a collection of available |
| 1381 | completions, find completions matching the last word of the |
| 1382 | text. |
| 1383 | |
| 1384 | If `start_only` is True, the text will match an available |
| 1385 | completion only at the beginning. Otherwise, a completion is |
| 1386 | considered a match if the text appears anywhere within it. |
| 1387 | |
| 1388 | yields prompt_toolkit Completion instances for any matches found |
| 1389 | in the collection of available completions. |
| 1390 | """ |
| 1391 | last = last_word(orig_text, include='most_punctuations') |
| 1392 | text = last.lower() |
| 1393 | quoted_collection = self.quote_collection_if_needed(text, collection, text_before_cursor) |
| 1394 | |
| 1395 | if fuzzy: |
| 1396 | completions = self.find_fuzzy_matches(last, text, quoted_collection) |
| 1397 | else: |
| 1398 | completions = self.find_perfect_matches(text, quoted_collection, start_only) |
| 1399 | |
| 1400 | casing = self.resolve_casing(casing, last) |
| 1401 | return self.apply_casing(completions, casing) |
| 1402 | |
| 1403 | def get_completions( |
| 1404 | self, |