Exemplo n.º 1
0
    def trg_from_pos(self, buf, pos, implicit=True, lang=None):
        log.debug("trg_from_pos(pos=%r)", pos)
        if pos < 2:
            return None
        accessor = buf.accessor
        last_pos = pos - 1
        last_char = accessor.char_at_pos(last_pos)

        if last_char == ".":  # must be "complete-object-members" or None
            log.debug("  triggered 'complete-object-members'")
            return Trigger(self.lang, TRG_FORM_CPLN, "object-members", pos, implicit)
        elif last_char == "(":
            log.debug("  triggered 'calltip-call-signature'")
            return Trigger(self.lang, TRG_FORM_CALLTIP, "call-signature", pos, implicit)
        elif last_char in "'\"`" or last_char == "@":
            # Check if it's an import
            log.debug("  checking for import statement")
            ac = AccessorCache(accessor, pos, fetchsize=100)
            prev_style = accessor.style_at_pos(last_pos - 1)
            if prev_style == SCE_C_STRING:
                # It's the end of a string then, not what we are looking for.
                return False

            # Bug in Komodo 8 - peek at the previous style to ensure the cache
            # is primed. No needed in Komodo 9 onwards.
            p, ch, style = ac.peekPrevPosCharStyle()
            log.debug("  p1 %r, ch %r, style %r", p, ch, style)

            loops_left = 100
            while loops_left:
                loops_left -= 1
                p, ch, style = ac.getPrecedingPosCharStyle(style)
                log.debug("  p %r, ch %r, style %r", p, ch, style)
                if p is None:
                    break
                if style == SCE_C_WORD:
                    p, text = ac.getTextBackWithStyle(style)
                    log.debug("    p %r, text %r", p, text)
                    if text == "import":
                        log.debug("  triggered 'complete-imports'")
                        return Trigger(self.lang, TRG_FORM_CPLN, "imports", pos, implicit)
                    break
                elif style not in (
                    SCE_C_DEFAULT,
                    SCE_C_OPERATOR,
                    SCE_C_STRING,
                    SCE_C_COMMENT,
                    SCE_C_COMMENTDOC,
                    SCE_C_COMMENTLINE,
                ):
                    break

        log.debug("  triggered 'complete-any'")
        return Trigger(self.lang, TRG_FORM_CPLN, "any", pos, implicit)
Exemplo n.º 2
0
 def test_basics(self):
     content = "This is my test buffer\r\nSecond   line\r\nThird line\r\n"
     styles =  "1111011011011110111111 2 21111110001111 2 21111101111 2 2".replace(" ", "")
     ta = _TestAccessor(content, list(map(int, styles)))
     pos = len(content) - 2
     ac = AccessorCache(ta, pos)
     #ac._debug = True
     for i in range(2):
         assert(ac.getPrevPosCharStyle() == (pos-1, "e", 1))
         assert(ac.getPrecedingPosCharStyle(1) == (pos-5, " ", 0))
         assert(ac.getPrecedingPosCharStyle(0) == (pos-6, "d", 1))
         assert(ac.getPrecedingPosCharStyle(1) == (pos-11, "\n", 2))
         assert(ac.getPrecedingPosCharStyle()  == (pos-13, "e", 1))
         assert(ac.getTextBackWithStyle(1) == (pos-16, "line"))
         assert(ac.getPrevPosCharStyle() == (pos-17, " ", 0))
         assert(ac.getPrecedingPosCharStyle(0) == (pos-20, "d", 1))
         if i == 0:
             ac.resetToPosition(pos)
 
     assert(ac.getCurrentPosCharStyle() == (pos-20, "d", 1))
 
     #print pos
     #print ac.getSucceedingPosCharStyle()
     assert(ac.getNextPosCharStyle() == (pos-19, " ", 0))
     assert(ac.getSucceedingPosCharStyle() == (pos-16, "l", 1))
     assert(ac.getTextForwardWithStyle(1) == (pos-13, "line"))
     assert(ac.getNextPosCharStyle() == (pos-12, "\r", 2))
     assert(ac.getNextPosCharStyle() == (pos-11, "\n", 2))
     assert(ac.getSucceedingPosCharStyle(2) == (pos-10, "T", 1))
     assert(ac.getSucceedingPosCharStyle() == (pos-5, " ", 0))
     assert(ac.getSucceedingPosCharStyle() == (pos-4, "l", 1))
     assert(ac.getSucceedingPosCharStyle() == (pos, "\r", 2))
     assert(ac.getNextPosCharStyle() == (pos+1, "\n", 2))
 
     # Bug: http://bugs.activestate.com/show_bug.cgi?id=64227
     #      Ensure text_range uses correct parameters in boundary situations
     ac.resetToPosition(3)
     assert(ac.getTextBackWithStyle(1)[1] == "This")
     ac.resetToPosition(len(content) - 2)
     assert(ac.getTextForwardWithStyle(2)[1] == "\r\n")
Exemplo n.º 3
0
 def test_basics(self):
     content = "This is my test buffer\r\nSecond   line\r\nThird line\r\n"
     styles =  "1111011011011110111111 2 21111110001111 2 21111101111 2 2".replace(" ", "")
     ta = _TestAccessor(content, map(int, styles))
     pos = len(content) - 2
     ac = AccessorCache(ta, pos)
     #ac._debug = True
     for i in range(2):
         assert(ac.getPrevPosCharStyle() == (pos-1, "e", 1))
         assert(ac.getPrecedingPosCharStyle(1) == (pos-5, " ", 0))
         assert(ac.getPrecedingPosCharStyle(0) == (pos-6, "d", 1))
         assert(ac.getPrecedingPosCharStyle(1) == (pos-11, "\n", 2))
         assert(ac.getPrecedingPosCharStyle()  == (pos-13, "e", 1))
         assert(ac.getTextBackWithStyle(1) == (pos-16, "line"))
         assert(ac.getPrevPosCharStyle() == (pos-17, " ", 0))
         assert(ac.getPrecedingPosCharStyle(0) == (pos-20, "d", 1))
         if i == 0:
             ac.resetToPosition(pos)
 
     assert(ac.getCurrentPosCharStyle() == (pos-20, "d", 1))
 
     #print pos
     #print ac.getSucceedingPosCharStyle()
     assert(ac.getNextPosCharStyle() == (pos-19, " ", 0))
     assert(ac.getSucceedingPosCharStyle() == (pos-16, "l", 1))
     assert(ac.getTextForwardWithStyle(1) == (pos-13, "line"))
     assert(ac.getNextPosCharStyle() == (pos-12, "\r", 2))
     assert(ac.getNextPosCharStyle() == (pos-11, "\n", 2))
     assert(ac.getSucceedingPosCharStyle(2) == (pos-10, "T", 1))
     assert(ac.getSucceedingPosCharStyle() == (pos-5, " ", 0))
     assert(ac.getSucceedingPosCharStyle() == (pos-4, "l", 1))
     assert(ac.getSucceedingPosCharStyle() == (pos, "\r", 2))
     assert(ac.getNextPosCharStyle() == (pos+1, "\n", 2))
 
     # Bug: http://bugs.activestate.com/show_bug.cgi?id=64227
     #      Ensure text_range uses correct parameters in boundary situations
     ac.resetToPosition(3)
     assert(ac.getTextBackWithStyle(1)[1] == "This")
     ac.resetToPosition(len(content) - 2)
     assert(ac.getTextForwardWithStyle(2)[1] == "\r\n")
Exemplo n.º 4
0
    def trg_from_pos(self, buf, pos, implicit=True, lang=None):
        log.debug("trg_from_pos(pos=%r)", pos)
        if pos < 2:
            return None
        accessor = buf.accessor
        last_pos = pos - 1
        last_char = accessor.char_at_pos(last_pos)

        if last_char == '.':  # must be "complete-object-members" or None
            log.debug("  triggered 'complete-object-members'")
            return Trigger(self.lang, TRG_FORM_CPLN, "object-members", pos,
                           implicit)
        elif last_char == '(':
            log.debug("  triggered 'calltip-call-signature'")
            return Trigger(self.lang, TRG_FORM_CALLTIP, "call-signature", pos,
                           implicit)
        elif last_char in '\'"`' or last_char == "@":
            # Check if it's an import
            log.debug("  checking for import statement")
            ac = AccessorCache(accessor, pos, fetchsize=100)
            prev_style = accessor.style_at_pos(last_pos - 1)
            if prev_style == SCE_C_STRING:
                # It's the end of a string then, not what we are looking for.
                return False

            # Bug in Komodo 8 - peek at the previous style to ensure the cache
            # is primed. No needed in Komodo 9 onwards.
            p, ch, style = ac.peekPrevPosCharStyle()
            log.debug("  p1 %r, ch %r, style %r", p, ch, style)

            loops_left = 100
            while loops_left:
                loops_left -= 1
                p, ch, style = ac.getPrecedingPosCharStyle(style)
                log.debug("  p %r, ch %r, style %r", p, ch, style)
                if p is None:
                    break
                if style == SCE_C_WORD:
                    p, text = ac.getTextBackWithStyle(style)
                    log.debug("    p %r, text %r", p, text)
                    if text == "import":
                        log.debug("  triggered 'complete-imports'")
                        return Trigger(self.lang, TRG_FORM_CPLN, "imports",
                                       pos, implicit)
                    break
                elif style not in (SCE_C_DEFAULT, SCE_C_OPERATOR, SCE_C_STRING,
                                   SCE_C_COMMENT, SCE_C_COMMENTDOC,
                                   SCE_C_COMMENTLINE):
                    break

        log.debug("  triggered 'complete-any'")
        return Trigger(self.lang, TRG_FORM_CPLN, "any", pos, implicit)