MCPcopy Index your code
hub / github.com/dbcli/pgcli / find_matches

Method find_matches

pgcli/pgcompleter.py:317–452  ·  view source on GitHub ↗

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. `collection` can be either a list of strings or a list of Candidate namedtuples. `

(self, text, collection, mode="fuzzy", meta=None)

Source from the content-addressed store, hash-verified

315 self.all_completions = set(self.keywords + self.functions)
316
317 def find_matches(self, text, collection, mode="fuzzy", meta=None):
318 """Find completion matches for the given text.
319
320 Given the user's input text and a collection of available
321 completions, find completions matching the last word of the
322 text.
323
324 `collection` can be either a list of strings or a list of Candidate
325 namedtuples.
326 `mode` can be either 'fuzzy', or 'strict'
327 'fuzzy': fuzzy matching, ties broken by name prevalance
328 `keyword`: start only matching, ties broken by keyword prevalance
329
330 yields prompt_toolkit Completion instances for any matches found
331 in the collection of available completions.
332
333 """
334 if not collection:
335 return []
336 prio_order = [
337 "keyword",
338 "function",
339 "view",
340 "table",
341 "datatype",
342 "database",
343 "schema",
344 "column",
345 "table alias",
346 "join",
347 "name join",
348 "fk join",
349 "table format",
350 ]
351 type_priority = prio_order.index(meta) if meta in prio_order else -1
352 text = last_word(text, include="most_punctuations").lower()
353 text_len = len(text)
354
355 if text and text[0] == '"':
356 # text starts with double quote; user is manually escaping a name
357 # Match on everything that follows the double-quote. Note that
358 # text_len is calculated before removing the quote, so the
359 # Completion.position value is correct
360 text = text[1:]
361
362 if mode == "fuzzy":
363 fuzzy = True
364 priority_func = self.prioritizer.name_count
365 else:
366 fuzzy = False
367 priority_func = self.prioritizer.keyword_count
368
369 # Construct a `_match` function for either fuzzy or non-fuzzy matching
370 # The match function returns a 2-tuple used for sorting the matches,
371 # or None if the item doesn't match
372 # Note: higher priority values mean more important, so use negative
373 # signs to flip the direction of the tuple
374 if fuzzy:

Callers 15

get_completionsMethod · 0.95
get_column_matchesMethod · 0.95
get_join_matchesMethod · 0.95
get_function_matchesMethod · 0.95
get_schema_matchesMethod · 0.95
get_table_matchesMethod · 0.95
get_table_formatsMethod · 0.95
get_view_matchesMethod · 0.95
get_alias_matchesMethod · 0.95
get_database_matchesMethod · 0.95
get_keyword_matchesMethod · 0.95

Calls 3

unescape_nameMethod · 0.95
caseMethod · 0.95
last_wordFunction · 0.85