Beispiel #1
0
    def get_completion(self, code, offset):
        token_code = self._tokenize_text(code[:offset])
        scopes = self._search_for_scope(token_code)
        var_segment = self._search_for_completion_segment(token_code)
        words = var_segment.split('.', 1)
        words_final = var_segment.rsplit('.', 1)
        main_attribute = words[0].strip().split('(', 1)
        attr_name = main_attribute[0]
        word = ''
        final_word = ''
        if var_segment.count(".") > 0:
            word = words[1].strip()
        if not var_segment.endswith('.') and len(words_final) > 1:
            final_word = words_final[1].strip()
            word = word.rsplit('.', 1)[0].strip()
            if final_word == word:
                word = ''
        self.cdaemon.lock.acquire()
        module = self.cdaemon.get_module(self.module_id)
        imports = module.get_imports()
        result = module.get_type(attr_name, word, scopes)
        self.cdaemon.lock.release()
        if result['found'] and result['type'] is not None:
            prefix = attr_name
            if result['type'] != attr_name:
                prefix = result['type']
                word = final_word
            to_complete = "%s.%s" % (prefix, word)
            if result.get('main_attr_replace', False):
                to_complete = var_segment.replace(attr_name, result['type'], 1)
            imports = [imp.split('.')[0] for imp in imports]
            data = completer.get_all_completions(to_complete, imports)
            __attrib = [d for d in data.get('attributes', []) if d[:2] == '__']
            if __attrib:
                map(lambda i: data['attributes'].remove(i), __attrib)
                data['attributes'] += __attrib
            if data:
                return data
            else:
                result = {'found': None, 'type': None}

        if result['type'] is not None and len(result['type']) > 0:
            data = {'attributes': result['type']['attributes'],
                'functions': result['type']['functions']}
        else:
            clazzes = sorted(set(self.patClass.findall(code)))
            funcs = sorted(set(self.patFunction.findall(code)))
            attrs = sorted(set(self.patWords.split(code)))
            if final_word in attrs:
                attrs.remove(final_word)
            if attr_name in attrs:
                attrs.remove(attr_name)
            filter_attrs = lambda x: (x not in funcs) and \
                not x.isdigit() and (x not in self.keywords)
            attrs = filter(filter_attrs, attrs)
            funcs = filter(lambda x: x not in clazzes, funcs)
            data = {'attributes': attrs,
                'functions': funcs,
                'classes': clazzes}
        return data
Beispiel #2
0
 def _resolve_completion_argument(self):
     try:
         cursor = self.textCursor()
         cursor.movePosition(QTextCursor.StartOfLine,
             QTextCursor.KeepAnchor)
         var = unicode(cursor.selectedText())
         chars = self.patObject.findall(var)
         var = var[var.rfind(chars[-1]) + 1:]
         cr = self.cursorRect()
         proposals = completer.get_all_completions(var,
             imports=self.imports)
         if not proposals:
             if self.completer.popup().isVisible():
                 prefix = var[var.rfind('.') + 1:]
                 var = var[:var.rfind('.') + 1]
                 var = self._console.get_type(var)
                 var += prefix
             else:
                 var = self._console.get_type(var)
             proposals = completer.get_all_completions(var,
                 imports=self.imports)
         self.completer.complete(cr, proposals)
     except:
         self.completer.popup().hide()
Beispiel #3
0
 def _resolve_completion_argument(self):
     try:
         cursor = self.textCursor()
         cursor.movePosition(QTextCursor.StartOfLine,
                             QTextCursor.KeepAnchor)
         var = cursor.selectedText()
         chars = self.patObject.findall(var)
         var = var[var.rfind(chars[-1]) + 1:]
         cr = self.cursorRect()
         proposals = completer.get_all_completions(var,
                                                   imports=self.imports)
         if not proposals:
             if self.completer.popup().isVisible():
                 prefix = var[var.rfind('.') + 1:]
                 var = var[:var.rfind('.') + 1]
                 var = self._console.get_type(var)
                 var += prefix
             else:
                 var = self._console.get_type(var)
             proposals = completer.get_all_completions(var,
                                                       imports=self.imports)
         self.completer.complete(cr, proposals)
     except:
         self.completer.popup().hide()
Beispiel #4
0
 def get_completion(self, code, offset):
     token_code = self._tokenize_text(code[:offset])
     scopes = self._search_for_scope(token_code)
     var_segment = self._search_for_completion_segment(token_code)
     words = var_segment.split('.', 1)
     words_final = var_segment.rsplit('.', 1)
     attr_name = words[0].strip()
     word = ''
     final_word = ''
     if var_segment.count(".") > 0:
         word = words[1].strip()
     if not var_segment.endswith('.') and len(words_final) > 1:
         final_word = words_final[1].strip()
         word = word.rsplit('.', 1)[0].strip()
         if final_word == word:
             word = ''
     result = self.current_module.get_type(attr_name, word, scopes)
     if result[0] and result[1] is not None:
         imports = self.current_module.get_imports()
         prefix = attr_name
         if result[1] != attr_name:
             prefix = result[1]
             word = final_word
         to_complete = "%s.%s" % (prefix, word)
         data = completer.get_all_completions(to_complete, imports)
     else:
         if result[1] is not None and len(result[1]) > 0:
             data = {'attributes': result[1][0], 'functions': result[1][1]}
         else:
             clazzes = sorted(set(re.findall("class (\w+?)\(", code)))
             funcs = sorted(set(re.findall("(\w+?)\(", code)))
             attrs = sorted(set(re.split('\W+', code)))
             if final_word in attrs:
                 attrs.remove(final_word)
             if attr_name in attrs:
                 attrs.remove(attr_name)
             filter_attrs = lambda x: (x not in funcs) and \
                 not x.isdigit() and (x not in self.keywords)
             attrs = filter(filter_attrs, attrs)
             funcs = filter(lambda x: x not in clazzes, funcs)
             data = {
                 'attributes': attrs,
                 'functions': funcs,
                 'classes': clazzes
             }
     return data
Beispiel #5
0
 def get_completion(self, code, offset):
     token_code = self._tokenize_text(code[:offset])
     scopes = self._search_for_scope(token_code)
     var_segment = self._search_for_completion_segment(token_code)
     words = var_segment.split('.', 1)
     words_final = var_segment.rsplit('.', 1)
     attr_name = words[0].strip()
     word = ''
     final_word = ''
     if var_segment.count(".") > 0:
         word = words[1].strip()
     if not var_segment.endswith('.') and len(words_final) > 1:
         final_word = words_final[1].strip()
         word = word.rsplit('.', 1)[0].strip()
         if final_word == word:
             word = ''
     result = self.current_module.get_type(attr_name, word, scopes)
     if result[0] and result[1] is not None:
         imports = self.current_module.get_imports()
         prefix = attr_name
         if result[1] != attr_name:
             prefix = result[1]
             word = final_word
         to_complete = "%s.%s" % (prefix, word)
         data = completer.get_all_completions(to_complete, imports)
     else:
         if result[1] is not None and len(result[1]) > 0:
             data = {'attributes': result[1][0],
                 'functions': result[1][1]}
         else:
             clazzes = sorted(set(re.findall("class (\w+?)\(", code)))
             funcs = sorted(set(re.findall("(\w+?)\(", code)))
             attrs = sorted(set(re.split('\W+', code)))
             if final_word in attrs:
                 attrs.remove(final_word)
             if attr_name in attrs:
                 attrs.remove(attr_name)
             filter_attrs = lambda x: (x not in funcs) and \
                 not x.isdigit() and (x not in self.keywords)
             attrs = filter(filter_attrs, attrs)
             funcs = filter(lambda x: x not in clazzes, funcs)
             data = {'attributes': attrs,
                 'functions': funcs,
                 'classes': clazzes}
     return data
 def _resolve_inheritance(self, clazz, module):
     for base in clazz.bases:
         name = base.split('.', 1)
         main_attr = name[0]
         child_attrs = ''
         if len(name) == 2:
             child_attrs = name[1]
         result = module.get_type(main_attr, child_attrs)
         data = model.late_resolution
         if result.get('found', True):
             data_type = module.imports[main_attr].get_data_type()
             if child_attrs:
                 child_attrs = '.%s' % child_attrs
             name = '%s%s().' % (data_type, child_attrs)
             imports = module.get_imports()
             imports = [imp.split('.')[0] for imp in imports]
             data = completer.get_all_completions(name, imports)
             data = (name, data)
         elif result.get('object', False).__class__ is model.Clazz:
             data = result['object']
         clazz.bases[base] = data
     clazz.update_with_parent_data()
Beispiel #7
0
 def _resolve_inheritance(self, clazz, module):
     for base in clazz.bases:
         name = base.split('.', 1)
         main_attr = name[0]
         child_attrs = ''
         if len(name) == 2:
             child_attrs = name[1]
         result = module.get_type(main_attr, child_attrs)
         data = model.late_resolution
         if result.get('found', True):
             data_type = module.imports[main_attr].get_data_type()
             if child_attrs:
                 child_attrs = '.%s' % child_attrs
             name = '%s%s().' % (data_type, child_attrs)
             imports = module.get_imports()
             imports = [imp.split('.')[0] for imp in imports]
             data = completer.get_all_completions(name, imports)
             data = (name, data)
         elif result.get('object', False).__class__ is model.Clazz:
             data = result['object']
         clazz.bases[base] = data
     clazz.update_with_parent_data()
    def get_completion(self, code, offset):
        token_code = self._tokenize_text(code[:offset])
        scopes = self._search_for_scope(token_code)
        # Find section to attempt for code completion (var_segment)
        var_segment = self._search_for_completion_segment(token_code)
        words = var_segment.split('.', 1)
        words_final = var_segment.rsplit('.', 1)
        # Main_attribute is the stem off of which to search for completions
        # i.e. in exec(ninja_ide.gui. ..., "ninja_ide.gui.main_panel"
        # would be main_attribute.
        main_attribute = words[0].strip().split('(', 1)
        attr_name = main_attribute[0]
        word = ''
        final_word = ''
        if var_segment.count(".") > 0:
            word = words[1].strip()
        if not var_segment.endswith('.') and len(words_final) > 1:
            final_word = words_final[1].strip()
            word = word.rsplit('.', 1)[0].strip()
            if final_word == word:
                word = ''
        self.cdaemon.lock.acquire()
        module = self.cdaemon.get_module(self.module_id)
        if module:
            imports = module.get_imports()
            result = module.get_type(attr_name, word, scopes)
        else:
            result = {'found': False, 'type': None}
        self.cdaemon.lock.release()
        if result['found'] and result['type'] is not None:
            prefix = attr_name
            if result['type'] != attr_name:
                prefix = result['type']
                word = final_word
            to_complete = "%s.%s" % (prefix, word)
            if result.get('main_attr_replace', False):
                to_complete = var_segment.replace(attr_name, result['type'], 1)
            imports = [imp.split('.')[0] for imp in imports]
            data = completer.get_all_completions(to_complete, imports)
            # Move system attributes beginning in '__' (built_in_attribs)
            # to the end of the list.
            built_in_attribs = [
                d for d in data.get('attributes', []) if d[:2] == '__'
            ]
            if built_in_attribs:
                for i in built_in_attribs:
                    data['attributes'].remove(i)
                data['attributes'] += built_in_attribs
            if data:
                return data
            else:
                result = {'found': None, 'type': None}

        if result['type'] is not None and len(result['type']) > 0:
            data = {
                'attributes': result['type']['attributes'],
                'functions': result['type']['functions']
            }
        else:
            clazzes = sorted(set(self.patClass.findall(code)))
            funcs = sorted(set(self.patFunction.findall(code)))
            attrs = sorted(set(self.patWords.split(code)))
            if final_word in attrs:
                attrs.remove(final_word)
            if attr_name in attrs:
                attrs.remove(attr_name)
            filter_attrs = lambda x: (x not in funcs) and \
                not x.isdigit() and (x not in self.keywords)
            attrs = list(filter(filter_attrs, attrs))
            funcs = [x for x in funcs if x not in clazzes]
            data = {
                'attributes': attrs,
                'functions': funcs,
                'classes': clazzes
            }
        return data
Beispiel #9
0
    def get_completion(self, code, offset):
        token_code = self._tokenize_text(code[:offset])
        scopes = self._search_for_scope(token_code)
        var_segment = self._search_for_completion_segment(token_code)
        words = var_segment.split('.', 1)
        words_final = var_segment.rsplit('.', 1)
        main_attribute = words[0].strip().split('(', 1)
        attr_name = main_attribute[0]
        word = ''
        final_word = ''
        if var_segment.count(".") > 0:
            word = words[1].strip()
        if not var_segment.endswith('.') and len(words_final) > 1:
            final_word = words_final[1].strip()
            word = word.rsplit('.', 1)[0].strip()
            if final_word == word:
                word = ''
        self.cdaemon.lock.acquire()
        module = self.cdaemon.get_module(self.module_id)
        if module:
            imports = module.get_imports()
            result = module.get_type(attr_name, word, scopes)
        else:
            result = {'found': False, 'type': None}
        self.cdaemon.lock.release()
        if result['found'] and result['type'] is not None:
            prefix = attr_name
            if result['type'] != attr_name:
                prefix = result['type']
                word = final_word
            to_complete = "%s.%s" % (prefix, word)
            if result.get('main_attr_replace', False):
                to_complete = var_segment.replace(attr_name, result['type'], 1)
            imports = [imp.split('.')[0] for imp in imports]
            data = completer.get_all_completions(to_complete, imports)
            __attrib = [d for d in data.get('attributes', []) if d[:2] == '__']
            if __attrib:
                map(lambda i: data['attributes'].remove(i), __attrib)
                data['attributes'] += __attrib
            if data:
                return data
            else:
                result = {'found': None, 'type': None}

        if result['type'] is not None and len(result['type']) > 0:
            data = {
                'attributes': result['type']['attributes'],
                'functions': result['type']['functions']
            }
        else:
            clazzes = sorted(set(self.patClass.findall(code)))
            funcs = sorted(set(self.patFunction.findall(code)))
            attrs = sorted(set(self.patWords.split(code)))
            if final_word in attrs:
                attrs.remove(final_word)
            if attr_name in attrs:
                attrs.remove(attr_name)
            filter_attrs = lambda x: (x not in funcs) and \
                not x.isdigit() and (x not in self.keywords)
            attrs = filter(filter_attrs, attrs)
            funcs = filter(lambda x: x not in clazzes, funcs)
            data = {
                'attributes': attrs,
                'functions': funcs,
                'classes': clazzes
            }
        return data
    def get_completion(self, code, offset):
        token_code = self._tokenize_text(code[:offset])
        scopes = self._search_for_scope(token_code)
        # Find section to attempt for code completion (var_segment)
        var_segment = self._search_for_completion_segment(token_code)
        words = var_segment.split('.', 1)
        words_final = var_segment.rsplit('.', 1)
        # Main_attribute is the stem off of which to search for completions
        # i.e. in exec(ninja_ide.gui. ..., "ninja_ide.gui.main_panel"
        # would be main_attribute.
        main_attribute = words[0].strip().split('(', 1)
        attr_name = main_attribute[0]
        word = ''
        final_word = ''
        if var_segment.count(".") > 0:
            word = words[1].strip()
        if not var_segment.endswith('.') and len(words_final) > 1:
            final_word = words_final[1].strip()
            word = word.rsplit('.', 1)[0].strip()
            if final_word == word:
                word = ''
        self.cdaemon.lock.acquire()
        module = self.cdaemon.get_module(self.module_id)
        if module:
            imports = module.get_imports()
            result = module.get_type(attr_name, word, scopes)
        else:
            result = {'found': False, 'type': None}
        self.cdaemon.lock.release()
        if result['found'] and result['type'] is not None:
            prefix = attr_name
            if result['type'] != attr_name:
                prefix = result['type']
                word = final_word
            to_complete = "%s.%s" % (prefix, word)
            if result.get('main_attr_replace', False):
                to_complete = var_segment.replace(attr_name, result['type'], 1)
            imports = [imp.split('.')[0] for imp in imports]
            data = completer.get_all_completions(to_complete, imports)
            # Move system attributes beginning in '__' (built_in_attribs)
            # to the end of the list.
            built_in_attribs = [d for d in data.get('attributes', [])
                                if d[:2] == '__']
            if built_in_attribs:
                for i in built_in_attribs:
                    data['attributes'].remove(i)
                data['attributes'] += built_in_attribs
            if data:
                return data
            else:
                result = {'found': None, 'type': None}

        if result['type'] is not None and len(result['type']) > 0:
            data = {'attributes': result['type']['attributes'],
                    'functions': result['type']['functions']}
        else:
            clazzes = sorted(set(self.patClass.findall(code)))
            funcs = sorted(set(self.patFunction.findall(code)))
            attrs = sorted(set(self.patWords.split(code)))
            if final_word in attrs:
                attrs.remove(final_word)
            if attr_name in attrs:
                attrs.remove(attr_name)
            filter_attrs = lambda x: (x not in funcs) and \
                not x.isdigit() and (x not in self.keywords)
            attrs = list(filter(filter_attrs, attrs))
            funcs = [x for x in funcs if x not in clazzes]
            data = {'attributes': attrs,
                    'functions': funcs,
                    'classes': clazzes}
        return data