Beispiel #1
0
 def testFindBasePropIndent(self):
     self.vim.current.buffer = ['aaaa', '    hehe.bbbb', 'cccc']
     self.vim.current.window.cursor =(2, 11)
     index = findBase('    hehe.bbbb', 11)
     word = findWord(self.vim, 11, '    hehe.bbbb')
     self.assertEquals(index, 9)
     self.assertEquals(word, 'hehe.bb')
Beispiel #2
0
 def testFindBaseNameIndent(self):
     self.vim.current.buffer = ['aaaa', '    bbbb', 'cccc']
     self.vim.current.window.cursor =(2, 6)
     index = findBase('    bbbb', 6)
     word = findWord(self.vim, 6, '    bbbb')
     self.assertEquals(index, 4)
     self.assertEquals(word, 'bb')
Beispiel #3
0
 def testFindBaseMethodCall(self):
     self.vim.current.buffer = ['aaaa', 'a.bbbb(', 'cccc']
     self.vim.current.window.cursor =(2, 7)
     index = findBase('a.bbbb(', 7)
     word = findWord(self.vim, 7, 'a.bbbb(')
     self.assertEquals(index, 2)
     self.assertEquals(word, 'a.bbbb(')
Beispiel #4
0
 def testFindBaseFuncCall(self):
     self.vim.current.buffer = ['aaaa', 'bbbb(', 'cccc']
     self.vim.current.window.cursor =(2, 5)
     index = findBase('bbbb(', 5)
     word = findWord(self.vim, 5, 'bbbb(')
     self.assertEquals(index, 0)
     self.assertEquals(word, 'bbbb(')
Beispiel #5
0
def main():
    cur_file = os.environ.get("TM_FILEPATH")
    source = sys.stdin.read()
    line_no = int(os.environ.get("TM_LINE_NUMBER"))
    cur_col = int(os.environ.get("TM_LINE_INDEX"))

    PYSMELLDICT = idehelper.findPYSMELLDICT(cur_file)
    line = source.splitlines()[line_no - 1]
    index = vimhelper.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')
        sys.exit(206) #magic code for tooltip
    if len(completions) == 1:
        new_word = completions[0]['word']
        write(new_word)
    elif len(completions) > 1:
        dialogTuples = [
            (
              "%s - %s" % (comp.get('abbr', comp['word']), comp.get('menu', '')),
              index)
            for index, comp in enumerate(completions)
        ]
        compIndex = dialog.menu(dialogTuples)
        if compIndex is not None:
            write(completions[compIndex]['word'])