Exemple #1
0
    def complete(self, tab=False):
        """Construct a full list of possible completions and
        display them in a window. Also check if there's an available argspec
        (via the inspect module) and bang that on top of the completions too.
        The return value is whether the list_win is visible or not.

        If no matches are found, just return whether there's an argspec to show
        If any matches are found, save them and select the first one.

        If tab is True exactly one match found, make the replacement and return
          the result of running complete() again on the new line.
        """

        self.set_docstring()

        matches, completer = autocomplete.get_completer(
            self.completers,
            cursor_offset=self.cursor_offset,
            line=self.current_line,
            locals_=self.interp.locals,
            argspec=self.argspec,
            current_block='\n'.join(self.buffer + [self.current_line]),
            complete_magic_methods=self.config.complete_magic_methods,
            history=self.history)
        # TODO implement completer.shown_before_tab == False (filenames
        # shouldn't fill screen)

        if len(matches) == 0:
            self.matches_iter.clear()
            return bool(self.argspec)

        self.matches_iter.update(self.cursor_offset,
                                 self.current_line, matches, completer)

        if len(matches) == 1:
            if tab:
                # if this complete is being run for a tab key press, substitute
                # common sequence
                self._cursor_offset, self._current_line = \
                    self.matches_iter.substitute_cseq()
                return Repl.complete(self)  # again for
            elif self.matches_iter.current_word == matches[0]:
                self.matches_iter.clear()
                return False
            return completer.shown_before_tab

        else:
            assert len(matches) > 1
            return tab or completer.shown_before_tab
Exemple #2
0
    def complete(self, tab=False):
        """Construct a full list of possible completions and construct and
        display them in a window. Also check if there's an available argspec
        (via the inspect module) and bang that on top of the completions too.
        The return value is whether the list_win is visible or not.

        If no matches are found, just return whether there's an argspec to show
        If any matches are found, save them and select the first one.

        If tab is True exactly one match found, make the replacement and return
          the result of running complete() again on the new line.
        """

        self.set_docstring()

        matches, completer = autocomplete.get_completer(
                self.cursor_offset,
                self.current_line,
                self.interp.locals,
                self.argspec,
                '\n'.join(self.buffer + [self.current_line]),
                self.config.autocomplete_mode if hasattr(self.config, 'autocomplete_mode') else autocomplete.SIMPLE,
                self.config.complete_magic_methods)
        #TODO implement completer.shown_before_tab == False (filenames shouldn't fill screen)

        if (matches is None            # no completion is relevant
                or len(matches) == 0): # a target for completion was found
                                       #   but no matches were found
            self.matches_iter.clear()
            return bool(self.argspec)

        self.matches_iter.update(self.cursor_offset,
                                 self.current_line, matches, completer)

        if len(matches) == 1:
                self.matches_iter.next()
                if tab: # if this complete is being run for a tab key press, tab() to do the swap

                    self.cursor_offset, self.current_line = self.matches_iter.substitute_cseq()
                    return Repl.complete(self)
                elif self.matches_iter.current_word == matches[0]:
                    self.matches_iter.clear()
                    return False
                return completer.shown_before_tab

        else:
            assert len(matches) > 1
            return tab or completer.shown_before_tab
Exemple #3
0
    def complete(self, tab=False):
        """Construct a full list of possible completions and construct and
        display them in a window. Also check if there's an available argspec
        (via the inspect module) and bang that on top of the completions too.
        The return value is whether the list_win is visible or not.

        If no matches are found, just return whether there's an argspec to show
        If any matches are found, save them and select the first one.

        If tab is True exactly one match found, make the replacement and return
          the result of running complete() again on the new line.
        """

        self.set_docstring()

        matches, completer = autocomplete.get_completer(
            self.cursor_offset, self.current_line, self.interp.locals,
            self.argspec, '\n'.join(self.buffer + [self.current_line]),
            self.config.autocomplete_mode if hasattr(
                self.config, 'autocomplete_mode') else autocomplete.SIMPLE,
            self.config.complete_magic_methods)
        #TODO implement completer.shown_before_tab == False (filenames shouldn't fill screen)

        if (matches is None  # no completion is relevant
                or len(matches) == 0):  # a target for completion was found
            #   but no matches were found
            self.matches_iter.clear()
            return bool(self.argspec)

        self.matches_iter.update(self.cursor_offset, self.current_line,
                                 matches, completer)

        if len(matches) == 1:
            self.matches_iter.next()
            if tab:  # if this complete is being run for a tab key press, tab() to do the swap

                self.cursor_offset, self.current_line = self.matches_iter.substitute_cseq(
                )
                return Repl.complete(self)
            elif self.matches_iter.current_word == matches[0]:
                self.matches_iter.clear()
                return False
            return completer.shown_before_tab

        else:
            assert len(matches) > 1
            return tab or completer.shown_before_tab
 def test_first_completer_returns_None(self):
     a = completer(None)
     b = completer(["a"])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ""), (["a"], b))
 def test_first_completer_returns_None(self):
     a = completer(None)
     b = completer(['a'])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ''), (['a'], b))
 def test_only_completer_returns_None(self):
     a = completer(None)
     self.assertEqual(autocomplete.get_completer([a], 0, ''), ([], None))
 def test_first_non_none_completer_matches_are_returned(self):
     a = completer([])
     b = completer(['a'])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ''), ([], None))
 def test_two_completers_with_matches_returns_first_matches(self):
     a = completer(['a'])
     b = completer(['b'])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ''), (['a'], a))
 def test_one_completer_returns_matches_and_completer(self):
     a = completer(['a'])
     self.assertTupleEqual(autocomplete.get_completer([a], 0, ''),
                           (['a'], a))
 def test_one_completer_without_matches_returns_empty_list_and_none(self):
     a = completer([])
     self.assertTupleEqual(autocomplete.get_completer([a], 0, ''),
                           ([], None))
 def test_no_completers(self):
     self.assertTupleEqual(autocomplete.get_completer([], 0, ''),
                           ([], None))
 def test_first_non_none_completer_matches_are_returned(self):
     a = completer([])
     b = completer(["a"])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ""), ([], None))
 def test_only_completer_returns_None(self):
     a = completer(None)
     self.assertEqual(autocomplete.get_completer([a], 0, ""), ([], None))
 def test_two_completers_with_matches_returns_first_matches(self):
     a = completer(["a"])
     b = completer(["b"])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ""), (["a"], a))
 def test_one_completer_returns_matches_and_completer(self):
     a = completer(["a"])
     self.assertTupleEqual(autocomplete.get_completer([a], 0, ""),
                           (["a"], a))
 def test_one_completer_without_matches_returns_empty_list_and_none(self):
     a = completer([])
     self.assertTupleEqual(autocomplete.get_completer([a], 0, ""),
                           ([], None))
 def test_no_completers(self):
     self.assertTupleEqual(autocomplete.get_completer([], 0, ""),
                           ([], None))
 def test_two_completers_with_matches_returns_first_matches(self):
     a = completer(['a'])
     b = completer(['b'])
     self.assertEqual(autocomplete.get_completer([a, b], 0, ''), (['a'], a))