Beispiel #1
0
    def get_r_completions(self, document, complete_event):
        text_before = document.current_line_before_cursor
        completion_requested = complete_event.completion_requested

        # somehow completion while typing is very slow in "print("
        # so we manually disable it
        if not completion_requested and "print(" in text_before and \
                re.match(r".*print\([^\)]*$", remove_nested_paren(text_before)):
            token = rcompletion.assign_line_buffer(text_before)
            text_before = token

        with suppress_stderr():
            try:
                token = rcompletion.assign_line_buffer(text_before)
                # do not timeout package::func
                if "::" in token or completion_requested:
                    timeout = 0
                else:
                    timeout = self.timeout
                rcompletion.complete_token(timeout)
                completions = rcompletion.retrieve_completions()
            except Exception:
                completions = []

        for c in completions:
            if c.startswith(token) and c != token:
                if c.endswith("="):
                    c = c[:-1] + " = "
                if c.endswith("::"):
                    # let get_package_completions handles it
                    continue
                yield Completion(c, -len(token))
Beispiel #2
0
    def get_r_completions(self, document, complete_event):
        text_before = document.current_line_before_cursor
        completion_requested = complete_event.completion_requested

        with native_read_console():
            try:
                token = rcompletion.assign_line_buffer(text_before)
                rcompletion.complete_token(
                    0 if completion_requested else self.timeout)
                completions = rcompletion.retrieve_completions()
            except Exception:
                completions = []

        for c in completions:
            if c.startswith(token):
                if c.endswith("="):
                    c = c[:-1] + " = "
                if c.endswith("::"):
                    # let get_package_completions handles it
                    continue
                yield Completion(c, -len(token))
Beispiel #3
0
def test_completion(gctorture):
    completion.assign_line_buffer("lib")
    completion.complete_token()
    assert "library" in completion.retrieve_completions()