当前位置: 首页>>代码示例>>Python>>正文


Python completion.Completion方法代码示例

本文整理汇总了Python中prompt_toolkit.completion.Completion方法的典型用法代码示例。如果您正苦于以下问题:Python completion.Completion方法的具体用法?Python completion.Completion怎么用?Python completion.Completion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prompt_toolkit.completion的用法示例。


在下文中一共展示了completion.Completion方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_completions

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def get_completions(self, document, complete_event):
        roll_names = list(rolls.keys())
        word = document.get_word_before_cursor()
        complete_all = not word if not word.strip() else word == '.'
        completions = []

        for roll in roll_names:
            is_substring = word in roll
            if complete_all or is_substring:

                completion = Completion(
                    roll,
                    start_position=-len(word),
                    style="fg:white bg:darkgreen",
                    selected_style="fg:yellow bg:green")

                completions.append(completion)

        return completions 
开发者ID:talkpython,项目名称:python-for-absolute-beginners-course,代码行数:21,代码来源:rpsgame.py

示例2: test_alter_well_known_keywords_completion

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_alter_well_known_keywords_completion(completer, complete_event):
    text = "ALTER "
    position = len(text)
    result = completions_to_set(
        completer.get_completions(
            Document(text=text, cursor_position=position),
            complete_event,
            smart_completion=True,
        )
    )
    assert result > completions_to_set(
        [
            Completion(text="DATABASE", display_meta="keyword"),
            Completion(text="TABLE", display_meta="keyword"),
            Completion(text="SYSTEM", display_meta="keyword"),
        ]
    )
    assert (
        completions_to_set([Completion(text="CREATE", display_meta="keyword")])
        not in result
    ) 
开发者ID:dbcli,项目名称:pgcli,代码行数:23,代码来源:test_naive_completion.py

示例3: get_completions

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def get_completions(self, document, complete_event):
        try:
            base, current = _parse_document(self.locals, document.text)

            if isinstance(base, dict):
                completions = sorted(base)
            else:
                completions = dir(base)
            if current:
                completions = [i for i in completions if i.startswith(current)]
            else:
                completions = [i for i in completions if not i.startswith("_")]
            for key in completions:
                yield Completion(key, start_position=-len(current))

        except Exception:
            return 
开发者ID:eth-brownie,项目名称:brownie,代码行数:19,代码来源:console.py

示例4: get_option_value_completion

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def get_option_value_completion(self, option, word_before_cursor):
        logger.debug('Complete option value')
        # complete choices
        if option.kwargs.get('choices'):
            logger.debug('Complete using choices %s' % option.kwargs['choices'])
            for choice in option.kwargs['choices']:
                yield Completion(choice,
                                 -len(word_before_cursor))
        # complete resources
        elif option.complete is not None:
            logger.debug('Complete using option matcher %s' % option.complete)
            completer_name = option.complete.split(':')[0]
            if completer_name in self.completers:
                for c in self.completers[completer_name].get_completions(word_before_cursor, self.context, option):
                    yield c
            else:
                logger.warning('No completer found for %s' % completer_name) 
开发者ID:eonpatapon,项目名称:contrail-api-cli,代码行数:19,代码来源:completer.py

示例5: get_completions

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def get_completions(self, document, complete_event):
        """Yield completions"""
        # Detect a file handle
        m = HSYM_RE.match(document.text_before_cursor)
        if m:
            text = m.group(1)
            doc = Document(text, len(text))
            for c in self.path_completer.get_completions(doc, complete_event):
                yield c
        else:
            # Get word/text before cursor.
            word_before_cursor = document.get_word_before_cursor(False)
            for words, meta in self.words_info:
                for a in words:
                    if a.startswith(word_before_cursor):
                        yield Completion(a, -len(word_before_cursor),
                                         display_meta=meta) 
开发者ID:KxSystems,项目名称:pyq,代码行数:19,代码来源:ptk.py

示例6: test_suggested_column_names_in_function

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_suggested_column_names_in_function(completer, complete_event):
    """Suggest column and function names when selecting multiple columns from
    table.

    :param completer:
    :param complete_event:
    :return:

    """
    text = "SELECT MAX( from users"
    position = len("SELECT MAX(")
    result = completer.get_completions(
        Document(text=text, cursor_position=position), complete_event
    )
    assert list(result) == list(
        [
            Completion(text="*", start_position=0),
            Completion(text="email", start_position=0),
            Completion(text="first_name", start_position=0),
            Completion(text="id", start_position=0),
            Completion(text="last_name", start_position=0),
        ]
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:25,代码来源:test_smart_completion_public_schema_only.py

示例7: test_suggested_column_names_with_table_dot

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_suggested_column_names_with_table_dot(completer, complete_event):
    """Suggest column names on table name and dot.

    :param completer:
    :param complete_event:
    :return:

    """
    text = "SELECT users. from users"
    position = len("SELECT users.")
    result = list(
        completer.get_completions(
            Document(text=text, cursor_position=position), complete_event
        )
    )
    assert result == list(
        [
            Completion(text="*", start_position=0),
            Completion(text="email", start_position=0),
            Completion(text="first_name", start_position=0),
            Completion(text="id", start_position=0),
            Completion(text="last_name", start_position=0),
        ]
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:26,代码来源:test_smart_completion_public_schema_only.py

示例8: test_suggested_column_names_with_alias

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_suggested_column_names_with_alias(completer, complete_event):
    """Suggest column names on table alias and dot.

    :param completer:
    :param complete_event:
    :return:

    """
    text = "SELECT u. from users u"
    position = len("SELECT u.")
    result = list(
        completer.get_completions(
            Document(text=text, cursor_position=position), complete_event
        )
    )
    assert result == list(
        [
            Completion(text="*", start_position=0),
            Completion(text="email", start_position=0),
            Completion(text="first_name", start_position=0),
            Completion(text="id", start_position=0),
            Completion(text="last_name", start_position=0),
        ]
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:26,代码来源:test_smart_completion_public_schema_only.py

示例9: test_suggested_multiple_column_names_with_dot

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_suggested_multiple_column_names_with_dot(completer, complete_event):
    """Suggest column names on table names and dot when selecting multiple
    columns from table.

    :param completer:
    :param complete_event:
    :return:

    """
    text = "SELECT users.id, users. from users u"
    position = len("SELECT users.id, users.")
    result = list(
        completer.get_completions(
            Document(text=text, cursor_position=position), complete_event
        )
    )
    assert result == list(
        [
            Completion(text="*", start_position=0),
            Completion(text="email", start_position=0),
            Completion(text="first_name", start_position=0),
            Completion(text="id", start_position=0),
            Completion(text="last_name", start_position=0),
        ]
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:27,代码来源:test_smart_completion_public_schema_only.py

示例10: test_suggested_tables_after_on_right_side

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_suggested_tables_after_on_right_side(completer, complete_event):
    text = "SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = "
    position = len(
        "SELECT users.name, orders.id FROM users JOIN orders ON orders.user_id = "
    )
    result = list(
        completer.get_completions(
            Document(text=text, cursor_position=position), complete_event
        )
    )
    assert list(result) == list(
        [
            Completion(text="orders", start_position=0),
            Completion(text="users", start_position=0),
        ]
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:18,代码来源:test_smart_completion_public_schema_only.py

示例11: test_auto_escaped_col_names

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_auto_escaped_col_names(completer, complete_event):
    text = "SELECT  from `select`"
    position = len("SELECT ")
    result = list(
        completer.get_completions(
            Document(text=text, cursor_position=position), complete_event
        )
    )
    assert result == [
        Completion(text="*", start_position=0),
        Completion(text="`ABC`", start_position=0),
        Completion(text="`insert`", start_position=0),
        Completion(text="id", start_position=0),
    ] + list(map(Completion, completer.functions)) + [
        Completion(text="`select`", start_position=0)
    ] + list(
        map(Completion, sorted(completer.keywords))
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:20,代码来源:test_smart_completion_public_schema_only.py

示例12: test_un_escaped_table_names

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_un_escaped_table_names(completer, complete_event):
    text = "SELECT  from réveillé"
    position = len("SELECT ")
    result = list(
        completer.get_completions(
            Document(text=text, cursor_position=position), complete_event
        )
    )
    assert result == list(
        [
            Completion(text="*", start_position=0),
            Completion(text="`ABC`", start_position=0),
            Completion(text="`insert`", start_position=0),
            Completion(text="id", start_position=0),
        ]
        + list(map(Completion, completer.functions))
        + [Completion(text="réveillé", start_position=0)]
        + list(map(Completion, sorted(completer.keywords)))
    ) 
开发者ID:dbcli,项目名称:litecli,代码行数:21,代码来源:test_smart_completion_public_schema_only.py

示例13: get_completions

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def get_completions(self, document, complete_event):
    text_before_cursor = document.text_before_cursor

    if currently_inside_quotes(text_before_cursor):
      return
    elif typing_label(text_before_cursor):
      choices = self.labels
      lookup = everything_after_last(":", text_before_cursor)
    elif typing_relationship(text_before_cursor):
      choices = self.relationship_types
      lookup = everything_after_last(":", text_before_cursor)
    elif typing_property(text_before_cursor):
      period_loc = text_before_cursor.rfind(".")
      variable_start_loc = max(text_before_cursor.rfind("(", 0, period_loc), text_before_cursor.rfind(" ", 0, period_loc))
      variable = text_before_cursor[variable_start_loc + 1:period_loc]

      if variable.isalnum() and any(c.isalpha() for c in variable):
        choices = self.properties
        lookup = everything_after_last(".", text_before_cursor)
      else:
        return
    elif text_before_cursor and text_before_cursor[-1].isalpha():
      last_cypher_word = self.most_recent_cypher_word(text_before_cursor)
      choices = self.cypher.most_probable_next_keyword(last_cypher_word)
      lookup = last_alphabetic_chunk(text_before_cursor)
    else:
      return

    completions = find_matches(lookup, choices)

    for completion in completions:
      yield Completion(completion, -len(lookup)) 
开发者ID:nicolewhite,项目名称:cycli,代码行数:34,代码来源:completer.py

示例14: test_label_completion

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_label_completion(completer, complete_event):
  text = "MATCH (p:P"
  result = get_completions(completer, complete_event, text)
  assert result == [Completion(text="Person", start_position=-1)] 
开发者ID:nicolewhite,项目名称:cycli,代码行数:6,代码来源:test_completer.py

示例15: test_label_completion_after_rel

# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import Completion [as 别名]
def test_label_completion_after_rel(completer, complete_event):
  text = "MATCH (p:Person)-[:ACTED_IN]->(m:M"
  result = get_completions(completer, complete_event, text)
  assert result == [Completion(text="Movie", start_position=-1)] 
开发者ID:nicolewhite,项目名称:cycli,代码行数:6,代码来源:test_completer.py


注:本文中的prompt_toolkit.completion.Completion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。