Ejemplo n.º 1
0
def test_quotes_matcher():
    assert get_brackets(r'foo(")(\")")', 4) == ('(', 4, 12)
    assert get_brackets(r'foo(")(\")")', 11) == ('(', 4, 12)

    assert get_brackets(r'foo(")(\")")', 5) == ('"', 5, 11)
    assert get_brackets(r'foo(")(\")")', 6) == ('"', 5, 11)
    assert get_brackets(r"foo(')(\')')", 10) == ("'", 5, 11)
Ejemplo n.º 2
0
    def show_calltips(self):
        project = self.project_manager.project
        project.validate()

        current_resource = self.get_rope_resource(project)

        from rope.contrib import codeassist
        from snaked.util.pairs_parser import get_brackets

        source, offset = self.get_source_and_offset()

        # make foo.bar.baz( equivalent to foo.bar.baz
        if source[offset-1] in '(.':
            offset -= 1

        brackets = get_brackets(source, offset)
        if brackets:
            br, spos, epos = brackets
            if br == '(':
                offset = spos - 1

        try:
            doc = codeassist.get_doc(project, source, offset, resource=current_resource, maxfixes=3)
        except Exception, e:
            import traceback
            traceback.print_exc()
            self.editor.message(str(e), 5000)
            return
Ejemplo n.º 3
0
def line_smart_extend(has_selection, start, end):
    from snaked.util import pairs_parser

    def ahtung():
        start.set_line(start.get_line())
        if not end.starts_line():
            end.set_line(end.get_line() + 1)

        return start, end

    left = start.copy()
    left.backward_chars(3)
    lchars = left.get_text(start).decode('utf-8')

    right = end.copy()
    right.forward_chars(3)
    rchars = end.get_text(right).decode('utf-8')

    if not rchars:
        rchars = [None]

    if not lchars:
        lchars = [None]

    text = start.get_buffer().get_text(*start.get_buffer().get_bounds()).decode('utf8')
    br, spos, epos = pairs_parser.get_brackets(text, start.get_offset())
    in_quotes = br in ('"', "'", '"""', "'''")
    #print br, spos, epos, start.get_offset()

    if not in_quotes and rchars[0] in (u'(', u'[', "'", '"'):
        try:
            br, spos, epos = pairs_parser.get_brackets(text, end.get_offset() + 1)
            #print br, spos, epos, end.get_offset() + 1
        except TypeError:
            br = None

        if not br: return ahtung()

        end.set_offset(epos)
    elif char_is_word(lchars[-1]) or char_is_word(rchars[0]):
        start = backward_word_start(start, in_quotes)
        end = forward_word_end(end, in_quotes)
    elif lchars[-1] == u'.' or rchars[0] == u'.':
        if lchars[-1] == u'.':
            start.backward_char()
            start = backward_word_start(start)
        if rchars[0] == u'.':
            end.forward_char()
            end = forward_word_end(end)
    else:
        if not br: return ahtung()

        ostart = start.copy()
        oend = end.copy()

        start.set_offset(spos)
        end.set_offset(epos - 1)

        if ostart.equal(start) and oend.equal(end):
            start.backward_chars(len(br))
            end.forward_chars(len(br))

    return start, end
Ejemplo n.º 4
0
def test_triple_quotes_matcher():
    assert get_brackets(r'foo("""()""")', 4) == ('(', 4, 13)
    assert get_brackets(r'foo("""()""")', 7) == ('"""', 7, 12)
    assert get_brackets(r"foo('''()''')", 9) == ("'''", 7, 12)
Ejemplo n.º 5
0
def test_parentheses_matcher():
    assert get_brackets('foo()\nboo()', 4) == ('(', 4, 5)

    assert get_brackets('foo(1,2, boo(a, b))', 13) == ('(', 13, 18)
    assert get_brackets('foo(1,2, boo(a, b))', 12) == ('(', 4, 19)

    assert get_brackets('foo(a[sas])', 6) == ('[', 6, 10)
    assert get_brackets('foo(a[sas])', 7) == ('[', 6, 10)
    assert get_brackets('foo(a[sas])', 9) == ('[', 6, 10)
    assert get_brackets('foo(a[sas])', 10) == ('(', 4, 11)

    assert get_brackets('foo() = boo()', 5) == (None, None, None)
    assert get_brackets('foo() = boo()', 6) == (None, None, None)
    assert get_brackets('foo() = boo()', 11) == (None, None, None)
    assert get_brackets('foo() = boo()', 12) == ('(', 12, 13)