Esempio n. 1
0
def sql_completions(document: Document) -> List[Completion]:
    meta = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="META Command") for i in sql_meta
    ]
    keywords = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="keyword") for i in sql_keywords
    ]
    tables = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="table") for i in sql_tables
    ]
    functions = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="function") for i in sql_functions
    ]
    dtypes = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="data type") for i in sql_dtypes
    ]
    numeric = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="numeric (alias)") for i in sql_numeric
    ]
    text = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="text (alias)") for i in sql_text
    ]
    real = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="real (alias)") for i in sql_real
    ]
    integer = [
        Completion(i,
                   start_position=document.find_boundaries_of_current_word(
                       WORD=True)[0],
                   display_meta="integer (alias)") for i in sql_integer
    ]
    return meta + keywords + tables + functions + integer + numeric + real + text + dtypes
Esempio n. 2
0
    def get_completions(self, document: Document, complete_event):

        word_start, word_end = document.find_boundaries_of_current_word()
        # print('%d %d' % (word_start, word_end))

        if word_start == 0 and word_end != 0:
            for command in misc:
                yield prompt_toolkit.completion.Completion(command)
            for command in object_types:
                yield prompt_toolkit.completion.Completion(command)
Esempio n. 3
0
    def get_completions(self,
                        document: Document,
                        _complete_event: CompleteEvent = None) -> Sequence[Completion]:
        """
        Returns a sequence of completions for given command line.
        """
        incomplete_cmd = ''
        if document.text.strip():
            incomplete_cmd = document.text.strip().split(maxsplit=1)[0]

        start, end = document.find_boundaries_of_current_word(WORD=True)
        start += document.cursor_position
        end += document.cursor_position
        current_word = document.text[start:end]

        current_word_is_command = (document.text[:start].strip() == '')
        if current_word_is_command:
            return self._complete_commands(incomplete_cmd)

        try:
            cmd = self._cmds.choose(incomplete_cmd)
        except ValueError:
            # invalid command
            return []

        incomplete_param = current_word
        if '=' not in incomplete_param:
            return self._complete_params(cmd, incomplete_param)

        param_name, incomplete_value = incomplete_param.split('=', maxsplit=1)
        param = cmd.parameters.get(param_name)
        if not param:
            return []

        # TODO: would be cool to exclude existing params
        return self._complete_value(param.type, incomplete_value)