Beispiel #1
0
    def testKnowAboutClassHierarchies(self):
        options = CompletionOptions(
            Types.INSTANCE, klass='Module.bClass',
            parents=[])  #possible error - why no parents
        compls = findCompletions('', self.pysmelldict, options)
        expected = [
            compMeth('am', 'aClass'),
            compProp('aprop', 'aClass'),
            compMeth('bm', 'aClass'),
            compProp('bprop', 'aClass'),
            compMeth('cm', 'bClass'),
            compProp('cprop', 'bClass'),
            compMeth('dm', 'bClass'),
            compProp('dprop', 'bClass')
        ]
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.INSTANCE,
                                    klass='Module.cClass',
                                    parents=['Module.bClass'])
        compls = findCompletions('', self.pysmelldict, options)
        expected = [
            compMeth('am', 'aClass'),
            compProp('aprop', 'aClass'),
            compMeth('bm', 'aClass'),
            compProp('bprop', 'aClass'),
            compMeth('cm', 'bClass'),
            compProp('cprop', 'bClass'),
            compMeth('dm', 'bClass'),
            compProp('dprop', 'bClass')
        ]
        self.assertEquals(compls, expected)
Beispiel #2
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'])
    def testKnowAboutClassHierarchies(self):
        options = CompletionOptions(Types.INSTANCE, klass='Module.bClass', parents=[]) #possible error - why no parents
        compls = findCompletions('', self.pysmelldict, options)
        expected = [compMeth('am', 'aClass'), compProp('aprop', 'aClass'),
                    compMeth('bm', 'aClass'), compProp('bprop', 'aClass'),
                    compMeth('cm', 'bClass'), compProp('cprop', 'bClass'),
                    compMeth('dm', 'bClass'), compProp('dprop', 'bClass')]
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.INSTANCE, klass='Module.cClass', parents=['Module.bClass'])
        compls = findCompletions('', self.pysmelldict, options)
        expected = [compMeth('am', 'aClass'), compProp('aprop', 'aClass'),
                    compMeth('bm', 'aClass'), compProp('bprop', 'aClass'),
                    compMeth('cm', 'bClass'), compProp('cprop', 'bClass'),
                    compMeth('dm', 'bClass'), compProp('dprop', 'bClass')]
        self.assertEquals(compls, expected)
Beispiel #4
0
 def testCompletions(self):
     options = CompletionOptions(Types.TOPLEVEL)
     compls = findCompletions('b', self.pysmelldict, options)
     expected = [
         compFunc('b', 'arg1, arg2'),
         compClass('bClass'),
         compConst('bconst')
     ]
     self.assertEquals(compls, expected)
Beispiel #5
0
 def testCompleteArgumentLists(self):
     options = CompletionOptions(Types.FUNCTION,
                                 klass=None,
                                 parents=[],
                                 name='b',
                                 rindex=None)
     compls = findCompletions('b(', self.pysmelldict, options)
     orig = compFunc('b', 'arg1, arg2')
     orig['word'] = orig['abbr']
     self.assertEquals(compls, [orig])
Beispiel #6
0
 def testCompleteArgumentListsProp(self):
     options = CompletionOptions(Types.METHOD,
                                 klass=None,
                                 parents=[],
                                 name='bm',
                                 rindex=None)
     compls = findCompletions('bm(', self.pysmelldict, options)
     orig = compMeth('bm', 'aClass')
     orig['word'] = orig['abbr']
     self.assertEquals(compls, [orig])
Beispiel #7
0
 def testCompletionsWithPackages(self):
     options = CompletionOptions(Types.INSTANCE,
                                 klass='Nested.Package.Module.Class',
                                 parents=[])
     compls = findCompletions('', self.nestedDict, options)
     expected = [
         dict(word='cprop',
              kind='m',
              menu='Nested.Package.Module:Class',
              dup='1')
     ]
     self.assertEquals(compls, expected)
Beispiel #8
0
 def testCompleteWithSelfInfer(self):
     options = CompletionOptions(Types.INSTANCE,
                                 klass='Module.aClass',
                                 parents=[])
     compls = findCompletions('', self.pysmelldict, options)
     expected = [
         compMeth('am', 'aClass'),
         compProp('aprop', 'aClass'),
         compMeth('bm', 'aClass'),
         compProp('bprop', 'aClass')
     ]
     self.assertEquals(compls, expected)
    def testModuleCompletion(self):
        options = CompletionOptions(Types.MODULE, module="Ne", showMembers=False)
        expected = [dict(word='Nested', kind='t', dup='1')]
        compls = findCompletions('Ne', self.nestedDict, options)
        self.assertEquals(compls, expected)
        
        options = CompletionOptions(Types.MODULE, module="Nested", showMembers=False)
        expected = [dict(word='Package', kind='t', dup='1')]
        compls = findCompletions('P', self.nestedDict, options)
        self.assertEquals(compls, expected)
        
        options = CompletionOptions(Types.MODULE, module="Nested.Package", showMembers=False)
        expected = [dict(word='Module', kind='t', dup='1')]
        compls = findCompletions('', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE, module="Mo", showMembers=False)
        expected = [dict(word='Module', kind='t', dup='1')]
        compls = findCompletions('Mo', self.pysmelldict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE, module="Module", showMembers=False)
        expected = []
        compls = findCompletions('', self.pysmelldict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE, module="Nested.Package", showMembers=True)
        expected = [dict(word='Module', kind='t', dup='1')]
        compls = findCompletions('', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE, module="Nested.Package.Module", showMembers=True)
        expected = [
            dict(word='Class', dup="1", kind="t", menu="Nested.Package.Module", abbr="Class()"),
            dict(word='Something', dup="1", kind="t"),
        ]
        compls = findCompletions('', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE, module="A", showMembers=True)
        expected = [
            dict(word='CONST_A', kind='d', dup='1', menu='A'),
            dict(word='CONST_B', kind='d', dup='1', menu='B'),
            dict(word='THING', kind='t', dup='1')
        ]
        compls = findCompletions('', self.complicatedDict, options)
        self.assertEquals(compls, expected)
Beispiel #10
0
def get_completions(fullPath, origSource, lineNo, origCol, matcher):
    """arguments: fullPath, origSource, lineNo, origCol, matcher

When visiting the file at fullPath, with edited source origSource, find a list 
of possible completion strings for the symbol located at origCol on orgLineNo using 
matching mode matcher"""
    PYSMELLDICT = idehelper.findPYSMELLDICT(fullPath)
    if not PYSMELLDICT:
        return
    origLine = origSource.splitlines()[lineNo - 1]
    base = split("[,.\-+/|\[\]]", origLine[:origCol].strip())[-1]
    options = idehelper.detectCompletionType(fullPath, origSource, lineNo, origCol, base, PYSMELLDICT)
    completions = [completion['word'] for completion in idehelper.findCompletions(base, PYSMELLDICT, options, matcher)]
    completions = list(_uniquify(completions))
    return completions
Beispiel #11
0
def get_completions(fullPath, origSource, lineNo, origCol, matcher):
    """arguments: fullPath, origSource, lineNo, origCol, matcher

When visiting the file at fullPath, with edited source origSource, find a list 
of possible completion strings for the symbol located at origCol on orgLineNo using 
matching mode matcher"""
    PYSMELLDICT = idehelper.findPYSMELLDICT(fullPath)
    if not PYSMELLDICT:
        return
    origLine = origSource.splitlines()[lineNo - 1]
    base = split("[,.\-+/|\[\]]", origLine[:origCol].strip())[-1]
    options = idehelper.detectCompletionType(fullPath, origSource, lineNo, origCol, base, PYSMELLDICT)
    completions = [completion['word'] for completion in idehelper.findCompletions(base, PYSMELLDICT, options, matcher)]
    completions = list(_uniquify(completions))
    return completions




        
Beispiel #12
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):])
Beispiel #13
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):])
 def testCompleteMembers(self):
     options = CompletionOptions(Types.INSTANCE, klass=None, parents=[])
     compls = findCompletions('a', self.pysmelldict, options)
     expected = [compMeth('am', 'aClass'), compProp('aprop', 'aClass')]
     self.assertEquals(compls, expected)
 def testCompletions(self):
     options = CompletionOptions(Types.TOPLEVEL)
     compls = findCompletions('b', self.pysmelldict, options)
     expected = [compFunc('b', 'arg1, arg2'), compClass('bClass'), compConst('bconst')]
     self.assertEquals(compls, expected)
 def testCompleteArgumentListsProp(self):
     options = CompletionOptions(Types.METHOD, klass=None, parents=[], name='bm', rindex=None)
     compls = findCompletions('bm(', self.pysmelldict, options)
     orig = compMeth('bm', 'aClass')
     orig['word'] = orig['abbr']
     self.assertEquals(compls, [orig])
Beispiel #17
0
 def testCompleteMembers(self):
     options = CompletionOptions(Types.INSTANCE, klass=None, parents=[])
     compls = findCompletions('a', self.pysmelldict, options)
     expected = [compMeth('am', 'aClass'), compProp('aprop', 'aClass')]
     self.assertEquals(compls, expected)
 def testCompletionsWithPackages(self):
     options = CompletionOptions(Types.INSTANCE, klass='Nested.Package.Module.Class', parents=[])
     compls = findCompletions('', self.nestedDict, options)
     expected = [dict(word='cprop', kind='m', menu='Nested.Package.Module:Class', dup='1')]
     self.assertEquals(compls, expected)
 def testCompleteWithSelfInfer(self):
     options = CompletionOptions(Types.INSTANCE, klass='Module.aClass', parents=[])
     compls = findCompletions('', self.pysmelldict, options)
     expected = [compMeth('am', 'aClass'), compProp('aprop', 'aClass'),
                 compMeth('bm', 'aClass'), compProp('bprop', 'aClass')]
     self.assertEquals(compls, expected)
 def testCompleteArgumentListsRightParen(self):
     options = CompletionOptions(Types.FUNCTION, klass=None, parents=[], name='b', rindex=-1)
     compls = findCompletions('b(', self.pysmelldict, options)
     orig = compFunc('b', 'arg1, arg2')
     orig['word'] = orig['abbr'][:-1]
     self.assertEquals(compls, [orig])
Beispiel #21
0
    def testModuleCompletion(self):
        options = CompletionOptions(Types.MODULE,
                                    module="Ne",
                                    showMembers=False)
        expected = [dict(word='Nested', kind='t', dup='1')]
        compls = findCompletions('Ne', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE,
                                    module="Nested",
                                    showMembers=False)
        expected = [dict(word='Package', kind='t', dup='1')]
        compls = findCompletions('P', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE,
                                    module="Nested.Package",
                                    showMembers=False)
        expected = [dict(word='Module', kind='t', dup='1')]
        compls = findCompletions('', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE,
                                    module="Mo",
                                    showMembers=False)
        expected = [dict(word='Module', kind='t', dup='1')]
        compls = findCompletions('Mo', self.pysmelldict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE,
                                    module="Module",
                                    showMembers=False)
        expected = []
        compls = findCompletions('', self.pysmelldict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE,
                                    module="Nested.Package",
                                    showMembers=True)
        expected = [dict(word='Module', kind='t', dup='1')]
        compls = findCompletions('', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE,
                                    module="Nested.Package.Module",
                                    showMembers=True)
        expected = [
            dict(word='Class',
                 dup="1",
                 kind="t",
                 menu="Nested.Package.Module",
                 abbr="Class()"),
            dict(word='Something', dup="1", kind="t"),
        ]
        compls = findCompletions('', self.nestedDict, options)
        self.assertEquals(compls, expected)

        options = CompletionOptions(Types.MODULE, module="A", showMembers=True)
        expected = [
            dict(word='CONST_A', kind='d', dup='1', menu='A'),
            dict(word='CONST_B', kind='d', dup='1', menu='B'),
            dict(word='THING', kind='t', dup='1')
        ]
        compls = findCompletions('', self.complicatedDict, options)
        self.assertEquals(compls, expected)