示例#1
0
 def testThem(self):
     index = findBase('bbbb', 2)
     self.assertEquals(index, 0)
     index = findBase('a.bbbb(', 7)
     self.assertEquals(index, 2)
     index = findBase('bbbb(', 5)
     self.assertEquals(index, 0)
     index = findBase('    bbbb', 6)
     self.assertEquals(index, 4)
     index = findBase('hehe.bbbb', 7)
     self.assertEquals(index, 5)
     index = findBase('    hehe.bbbb', 11)
     self.assertEquals(index, 9)
示例#2
0
 def testThem(self):
     index = findBase('bbbb', 2)
     self.assertEquals(index, 0)
     index = findBase('a.bbbb(', 7)
     self.assertEquals(index, 2)
     index = findBase('bbbb(', 5)
     self.assertEquals(index, 0)
     index = findBase('    bbbb', 6)
     self.assertEquals(index, 4)
     index = findBase('hehe.bbbb', 7)
     self.assertEquals(index, 5)
     index = findBase('    hehe.bbbb', 11)
     self.assertEquals(index, 9)
示例#3
0
def _main(cur_file, line_no, cur_col):
    if not cur_file:
        write('No filename - is the file saved?')
        return TOOLTIP
    source = sys.stdin.read()

    PYSMELLDICT = idehelper.findPYSMELLDICT(cur_file)
    if PYSMELLDICT is None:
        write('No PYSMELLTAGS found - you have to generate one.')
        return TOOLTIP
    line = source.splitlines()[line_no - 1]
    index = idehelper.findBase(line, cur_col)
    base = line[index:cur_col]

    options = idehelper.detectCompletionType(cur_file, source, line_no,
                                             cur_col, base, PYSMELLDICT)
    completions = idehelper.findCompletions(base, PYSMELLDICT, options)

    if not completions:
        write('No completions found')
        return TOOLTIP
    if len(completions) == 1:
        new_word = completions[0]['word']
        write(new_word[len(base):])
    elif len(completions) > 1:
        dialogTuples = [
            ("%s - %s" %
             (comp.get('abbr', comp['word']), comp.get('menu', '')), index)
            for index, comp in enumerate(completions)
        ]
        try:
            compIndex = tm_dialog.menu(dialogTuples)
        except Exception as e:
            import traceback
            write(traceback.format_exc(e))
            return TOOLTIP
        if compIndex is not None:
            write(completions[compIndex]['word'][len(base):])
示例#4
0
def _main(cur_file, line_no, cur_col):
    if not cur_file:
        write('No filename - is the file saved?')
        return TOOLTIP
    source = sys.stdin.read()

    PYSMELLDICT = idehelper.findPYSMELLDICT(cur_file)
    if PYSMELLDICT is None:
        write('No PYSMELLTAGS found - you have to generate one.')
        return TOOLTIP
    line = source.splitlines()[line_no - 1]
    index = idehelper.findBase(line, cur_col)
    base = line[index:cur_col]

    options = idehelper.detectCompletionType(cur_file, source, line_no, cur_col, base, PYSMELLDICT)
    completions = idehelper.findCompletions(base, PYSMELLDICT, options)

    if not completions:
        write('No completions found')
        return TOOLTIP
    if len(completions) == 1:
        new_word = completions[0]['word']
        write(new_word[len(base):])
    elif len(completions) > 1:
        dialogTuples = [
            (
              "%s - %s" % (comp.get('abbr', comp['word']), comp.get('menu', '')),
              index)
            for index, comp in enumerate(completions)
        ]
        try:
            compIndex = tm_dialog.menu(dialogTuples)
        except Exception, e:
            import traceback
            write(traceback.format_exc(e))
            return TOOLTIP
        if compIndex is not None:
            write(completions[compIndex]['word'][len(base):])