Exemplo n.º 1
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        cursor_pos = cursor_pos is None and len(code) or cursor_pos
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset
        needle = re.split(r"\s{2,}|\t| \| ", line[:line_cursor])[-1].lstrip()
        needle = needle.strip().lower()

        reply_content = {
            "status": "ok",
            "data": self.robot_inspect_data,
            "metadata": {},
            "found": bool(self.robot_inspect_data),
        }

        results = []
        if needle and lunr_query(needle):
            query = lunr_query(needle)
            results = self.robot_catalog["index"].search(query)
            results += self.robot_catalog["index"].search(query.strip("*"))
        for result in results:
            keyword = self.robot_catalog["keywords"][result["ref"]]
            if needle not in [keyword.name.lower(), result["ref"].lower()]:
                continue
            self.robot_inspect_data.update(get_keyword_doc(keyword))
            reply_content["found"] = True
            break

        return reply_content
Exemplo n.º 2
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        cursor_pos = cursor_pos is None and len(code) or cursor_pos
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset
        needle = re.split(r'\s{2,}|\t| \| ', line[:line_cursor])[-1].lstrip()
        needle = needle.strip().lower()

        reply_content = {
            'status': 'ok',
            'data': self.robot_inspect_data,
            'metadata': {},
            'found': bool(self.robot_inspect_data),
        }

        results = []
        if needle and lunr_query(needle):
            query = lunr_query(needle)
            results = self.robot_catalog['index'].search(query)
            results += self.robot_catalog['index'].search(query.strip('*'))
        for result in results:
            keyword = self.robot_catalog['keywords'][result['ref']]
            if needle not in [keyword.name.lower(), result['ref'].lower()]:
                continue
            self.robot_inspect_data.update(get_keyword_doc(keyword))
            reply_content['found'] = True
            break

        return reply_content
Exemplo n.º 3
0
def test_line_at_cursor():
    cell = ""
    (line, offset) = line_at_cursor(cell, cursor_pos=11)
    nt.assert_equal(line, "")
    nt.assert_equal(offset, 0)

    # The position after a newline should be the start of the following line.
    cell = "One\nTwo\n"
    (line, offset) = line_at_cursor(cell, cursor_pos=4)
    nt.assert_equal(line, "Two\n")
    nt.assert_equal(offset, 4)

    # The end of a cell should be on the last line
    cell = "pri\npri"
    (line, offset) = line_at_cursor(cell, cursor_pos=7)
    nt.assert_equal(line, "pri")
    nt.assert_equal(offset, 4)
Exemplo n.º 4
0
def test_line_at_cursor():
    cell = ""
    (line, offset) = line_at_cursor(cell, cursor_pos=11)
    nt.assert_equal(line, "")
    nt.assert_equal(offset, 0)

    # The position after a newline should be the start of the following line.
    cell = "One\nTwo\n"
    (line, offset) = line_at_cursor(cell, cursor_pos=4)
    nt.assert_equal(line, "Two\n")
    nt.assert_equal(offset, 4)

    # The end of a cell should be on the last line
    cell = "pri\npri"
    (line, offset) = line_at_cursor(cell, cursor_pos=7)
    nt.assert_equal(line, "pri")
    nt.assert_equal(offset, 4)
Exemplo n.º 5
0
def test_line_at_cursor():
    cell = ""
    (line, offset) = line_at_cursor(cell, cursor_pos=11)
    assert line == ""
    assert offset == 0

    # The position after a newline should be the start of the following line.
    cell = "One\nTwo\n"
    (line, offset) = line_at_cursor(cell, cursor_pos=4)
    assert line == "Two\n"
    assert offset == 4

    # The end of a cell should be on the last line
    cell = "pri\npri"
    (line, offset) = line_at_cursor(cell, cursor_pos=7)
    assert line == "pri"
    assert offset == 4
Exemplo n.º 6
0
def find_line(code: str, cursor_pos: int) -> Tuple[str, int, int]:
    """ What is the full line, line_cursor and offset at the cursor position
        in a multi-line string?
    """
    if cursor_pos is None:
        cursor_pos = len(code)
    line, offset = line_at_cursor(code, cursor_pos)
    line_cursor = cursor_pos - offset
    return line, line_cursor, offset
Exemplo n.º 7
0
def calculate_text_length(code, cursor_pos):
    # get length of word for completion
    line, offset = line_at_cursor(code, cursor_pos)
    line_cursor = cursor_pos - offset
    line_up_to_cursor = line[:line_cursor]
    if line_up_to_cursor.endswith(' '):
        return 0
    text = line_up_to_cursor.split()[-1]
    # print("Text: " + text + ", code: " + code, file=open('dbg.log', 'a')) # dbg
    text_length = len(text)
    return text_length
Exemplo n.º 8
0
    def do_complete(self, code, cursor_pos):
        # FIXME: IPython completers currently assume single line,
        # but completion messages give multi-line context
        # For now, extract line from cell, based on cursor_pos:
        if cursor_pos is None:
            cursor_pos = len(code)
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset

        txt, matches = self.shell.complete('', line, line_cursor)
        return {'matches': matches,
                'cursor_end': cursor_pos,
                'cursor_start': cursor_pos - len(txt),
                'metadata': {},
                'status': 'ok'}
Exemplo n.º 9
0
    def do_complete(self, code, cursor_pos):
        # FIXME: IPython completers currently assume single line,
        # but completion messages give multi-line context
        # For now, extract line from cell, based on cursor_pos:
        if cursor_pos is None:
            cursor_pos = len(code)
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset

        txt, matches = self.shell.complete('', line, line_cursor)
        return {'matches' : matches,
                'cursor_end' : cursor_pos,
                'cursor_start' : cursor_pos - len(txt),
                'metadata' : {},
                'status' : 'ok'}
Exemplo n.º 10
0
    def do_complete(self, code, cursor_pos):
        cursor_pos = cursor_pos is None and len(code) or cursor_pos
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset
        needle = re.split(r"\s{2,}|\t| \| ", line[:line_cursor])[-1].lstrip()

        if needle and needle[0] in "$@&%":  # is variable completion
            matches = [
                m["ref"] for m in scored_results(
                    needle,
                    [
                        dict(ref=v) for v in (self.robot_variables +
                                              VARIABLE_REGEXP.findall(code))
                    ],
                ) if needle.lower() in m["ref"].lower()
            ]
            if len(line) > line_cursor and line[line_cursor] == "}":
                cursor_pos += 1
                needle += "}"
        elif is_selector(needle):
            matches = []
            for driver in yield_current_connection(self.robot_connections,
                                                   ["selenium", "appium"]):
                matches = get_selector_completions(needle.rstrip(), driver)
        elif is_autoit_selector(needle):
            matches = get_autoit_selector_completions(needle)
        elif is_white_selector(needle):
            matches = get_white_selector_completions(needle)
        else:
            # Clear selector completion highlights
            for driver in yield_current_connection(self.robot_connections,
                                                   ["selenium"]):
                clear_selector_highlights(driver)
            context = detect_robot_context(code, cursor_pos)
            matches = get_lunr_completions(
                needle,
                self.robot_catalog["index"],
                self.robot_catalog["keywords"],
                context,
            )

        return {
            "matches": matches,
            "cursor_end": cursor_pos,
            "cursor_start": cursor_pos - len(needle),
            "metadata": {},
            "status": "ok",
        }
Exemplo n.º 11
0
    def do_complete(self, code, cursor_pos):
        cursor_pos = cursor_pos is None and len(code) or cursor_pos
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset
        needle = re.split(r'\s{2,}|\t| \| ', line[:line_cursor])[-1].lstrip()

        if needle and needle[0] in '$@&%':  # is variable completion
            matches = [
                m['ref'] for m in scored_results(
                    needle,
                    [
                        dict(ref=v) for v in (self.robot_variables +
                                              VARIABLE_REGEXP.findall(code))
                    ],
                ) if needle.lower() in m['ref'].lower()
            ]
            if len(line) > line_cursor and line[line_cursor] == '}':
                cursor_pos += 1
                needle += '}'
        elif is_selector(needle):
            matches = []
            for driver in yield_current_connection(self.robot_connections,
                                                   ['selenium', 'appium']):
                matches = get_selector_completions(needle.rstrip(), driver)
        elif is_autoit_selector(needle):
            matches = get_autoit_selector_completions(needle)
        elif is_white_selector(needle):
            matches = get_white_selector_completions(needle)
        else:
            # Clear selector completion highlights
            for driver in yield_current_connection(self.robot_connections,
                                                   ['selenium']):
                clear_selector_highlights(driver)
            context = detect_robot_context(code, cursor_pos)
            matches = get_lunr_completions(
                needle,
                self.robot_catalog['index'],
                self.robot_catalog['keywords'],
                context,
            )

        return {
            'matches': matches,
            'cursor_end': cursor_pos,
            'cursor_start': cursor_pos - len(needle),
            'metadata': {},
            'status': 'ok',
        }
Exemplo n.º 12
0
    def do_complete(self, code, cursor_pos):
        # FIXME: IPython completers currently assume single line,
        # but completion messages give multi-line context
        # For now, extract line from cell, based on cursor_pos:
        if cursor_pos is None:
            cursor_pos = len(code)
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset

        txt, matches = self.shell.complete("", line, line_cursor)
        return {
            "matches": matches,
            "cursor_end": cursor_pos,
            "cursor_start": cursor_pos - len(txt),
            "metadata": {},
            "status": "ok",
        }
Exemplo n.º 13
0
    def do_complete(self, code, cursor_pos):
        if _use_experimental_60_completion and self.use_experimental_completions:
            return self._experimental_do_complete(code, cursor_pos)

        # FIXME: IPython completers currently assume single line,
        # but completion messages give multi-line context
        # For now, extract line from cell, based on cursor_pos:
        if cursor_pos is None:
            cursor_pos = len(code)
        line, offset = line_at_cursor(code, cursor_pos)
        line_cursor = cursor_pos - offset

        txt, matches = self.shell.complete("", line, line_cursor)
        return {
            "matches": matches,
            "cursor_end": cursor_pos,
            "cursor_start": cursor_pos - len(txt),
            "metadata": {},
            "status": "ok",
        }
Exemplo n.º 14
0
def test_line_at_cursor():
    cell = ""
    (line, offset) = line_at_cursor(cell, cursor_pos=11)
    assert line == "", ("Expected '', got %r" % line)
    assert offset == 0, ("Expected '', got %r" % line)
Exemplo n.º 15
0
def test_line_at_cursor():
    cell = ""
    (line, offset) = line_at_cursor(cell, cursor_pos=11)
    assert line == "", ("Expected '', got %r" % line)
    assert offset == 0, ("Expected '', got %r" % line)