예제 #1
0
    def do_complete(self, data):
        file_ = self.db.get_file(self.current_file)
        file_ = to_unicode(file_)
        lines = file_.splitlines()
        lno = self.current['lno']
        line_before = ''
        if len(lines) >= lno:
            line_before = lines[lno - 1]
        indent = len(line_before) - len(line_before.lstrip())
        segments = data.splitlines()
        for segment in reversed(segments):
            line = u(' ') * indent + segment
            lines.insert(lno - 1, line)
        script = Script(
            u('\n').join(lines), lno - 1 + len(segments),
            len(segments[-1]) + indent, '')
        try:
            completions = script.completions()
        except:
            self.db.send('Suggest')
            self.notify_exc('Completion failed for %s' %
                            ('\n'.join(reversed(segments))))
            return

        try:
            funs = script.call_signatures() or []
        except:
            self.db.send('Suggest')
            self.notify_exc('Completion of function failed for %s' %
                            ('\n'.join(reversed(segments))))
            return

        try:
            suggest_obj = {
                'params': [{
                    'params':
                    [p.get_code().replace('\n', '') for p in fun.params],
                    'index':
                    fun.index,
                    'module':
                    fun.module.path,
                    'call_name':
                    fun.call_name
                } for fun in funs],
                'completions': [{
                    'base':
                    comp.name[:len(comp.name) - len(comp.complete)],
                    'complete':
                    comp.complete,
                    'description':
                    comp.description
                } for comp in completions if comp.name.endswith(comp.complete)]
            }
            self.db.send('Suggest|%s' % dump(suggest_obj))
        except:
            self.db.send('Suggest')
            self.notify_exc('Completion generation failed for %s' %
                            ('\n'.join(reversed(segments))))
예제 #2
0
파일: ui.py 프로젝트: Avinash9/wdb
    def do_complete(self, data):
        file_ = self.db.get_file(self.current_file)
        file_ = to_unicode(file_)
        lines = file_.splitlines()
        lno = self.current['lno']
        line_before = ''
        if len(lines) >= lno:
            line_before = lines[lno - 1]
        indent = len(line_before) - len(line_before.lstrip())
        segments = data.splitlines()
        for segment in reversed(segments):
            line = u(' ') * indent + segment
            lines.insert(lno - 1, line)
        script = Script(
            u('\n').join(lines), lno - 1 + len(segments),
            len(segments[-1]) + indent, '')
        try:
            completions = script.completions()
        except Exception:
            self.db.send('Suggest')
            self.notify_exc('Completion failed for %s' % (
                '\n'.join(reversed(segments))))
            return

        try:
            funs = script.call_signatures() or []
        except Exception:
            self.db.send('Suggest')
            self.notify_exc('Completion of function failed for %s' % (
                '\n'.join(reversed(segments))))
            return

        try:
            suggest_obj = {
                'params': [{
                    'params': [p.get_code().replace('\n', '')
                               for p in fun.params],
                    'index': fun.index,
                    'module': fun.module.path,
                    'call_name': fun.call_name} for fun in funs],
                'completions': [{
                    'base': comp.name[
                        :len(comp.name) - len(comp.complete)],
                    'complete': comp.complete,
                    'description': comp.description
                } for comp in completions if comp.name.endswith(
                    comp.complete)]
            }
            self.db.send('Suggest|%s' % dump(suggest_obj))
        except Exception:
            self.db.send('Suggest')
            self.notify_exc('Completion generation failed for %s' % (
                '\n'.join(reversed(segments))))
예제 #3
0
def test_dict_literal_in_incomplete_call():
    source = """\
    import json

    def foo():
        json.loads(

        json.load.return_value = {'foo': [],
                                  'bar': True}

        c = Foo()
    """

    script = Script(dedent(source), line=4, column=15)
    assert script.call_signatures()
예제 #4
0
def test_dict_literal_in_incomplete_call():
    source = """\
    import json

    def foo():
        json.loads(

        json.load.return_value = {'foo': [],
                                  'bar': True}

        c = Foo()
    """

    script = Script(dedent(source), line=4, column=15)
    assert script.call_signatures()
def _get_defs(source, func, line=None, column=None):
    error = None
    try:
        num_lines = len(source.split('\n'))
        if line is None:
            line = num_lines
        s = Script(source, line=line, column=column)
        defs = s.goto_definitions()
        sigs = s.call_signatures()
    except:
        print('Exception in defs thread')
        traceback.print_exc()
        defs = []
        sigs = []
        error = 'Could not retrieve docstring'

    mainthread(WrappablePartial(func, defs, sigs, error=error))()