MCPcopy Index your code
hub / github.com/dbcli/mycli / get_completions

Method get_completions

mycli/sqlcompleter.py:1403–1728  ·  view source on GitHub ↗
(
        self,
        document: Document,
        complete_event: CompleteEvent | None,
        smart_completion: bool | None = None,
    )

Source from the content-addressed store, hash-verified

1401 return self.apply_casing(completions, casing)
1402
1403 def get_completions(
1404 self,
1405 document: Document,
1406 complete_event: CompleteEvent | None,
1407 smart_completion: bool | None = None,
1408 ) -> Iterable[Completion]:
1409 word_before_cursor = document.get_word_before_cursor(WORD=True)
1410 last_for_len = last_word(word_before_cursor, include="most_punctuations")
1411 text_for_len = last_for_len.lower()
1412 last_for_len_paths = last_word(word_before_cursor, include='alphanum_underscore')
1413
1414 if smart_completion is None:
1415 smart_completion = self.smart_completion
1416
1417 # If smart_completion is off then match any word that starts with
1418 # 'word_before_cursor'.
1419 if not smart_completion:
1420 matches = self.find_matches(
1421 word_before_cursor,
1422 self.all_completions,
1423 start_only=True,
1424 fuzzy=False,
1425 text_before_cursor=document.text_before_cursor,
1426 )
1427 return (Completion(x[0], -len(text_for_len)) for x in matches)
1428
1429 completions: list[tuple[str, int, int]] = []
1430 suggestions = suggest_type(document.text, document.text_before_cursor)
1431 rigid_sort = False
1432 length_based_on_path = False
1433
1434 rank = 0
1435 for suggestion in suggestions:
1436 _logger.debug("Suggestion type: %r", suggestion["type"])
1437 rank += 1
1438
1439 if suggestion["type"] == "column":
1440 tables = suggestion["tables"]
1441 _logger.debug("Completion column scope: %r", tables)
1442 scoped_cols = self.populate_scoped_cols(tables)
1443 if suggestion.get("drop_unique"):
1444 # drop_unique is used for 'tb11 JOIN tbl2 USING (...'
1445 # which should suggest only columns that appear in more than
1446 # one table
1447 scoped_cols = [col for (col, count) in Counter(scoped_cols).items() if count > 1 and col != "*"]
1448 elif not tables:
1449 # if tables was empty, this is a naked SELECT and we are
1450 # showing all columns. So make them unique and sort them.
1451 scoped_cols = sorted(set(scoped_cols), key=lambda s: s.strip('`'))
1452
1453 cols = self.find_matches(
1454 word_before_cursor,
1455 scoped_cols,
1456 text_before_cursor=document.text_before_cursor,
1457 )
1458 completions.extend([(*x, rank) for x in cols])
1459
1460 elif suggestion["type"] == "function":

Calls 15

find_matchesMethod · 0.95
populate_scoped_colsMethod · 0.95
escape_nameMethod · 0.95
_fk_join_conditionsMethod · 0.95
find_filesMethod · 0.95
populate_enum_valuesMethod · 0.95
_quote_sql_stringMethod · 0.95
last_wordFunction · 0.90
suggest_typeFunction · 0.90
extract_tablesFunction · 0.90