def _trigger_code_completion(self, automatic):
        editor = self.tabs.currentWidget()
        source_code = unicode(editor.toPlainText())
        offset = editor.get_position('cursor')
        text = editor.get_text('sol', 'cursor')

        if text.startswith('import '):
            comp_list = module_completion(text)
            words = text.split(' ')
            if ',' in words[-1]:
                words = words[-1].split(',')
            if comp_list:
                editor.show_completion_list(comp_list,
                                            completion_text=words[-1],
                                            automatic=automatic)
            return
        elif text.startswith('from '):
            comp_list = module_completion(text)
            words = text.split(' ')
            if '(' in words[-1]:
                words = words[:-2] + words[-1].split('(')
            if ',' in words[-1]:
                words = words[:-2] + words[-1].split(',')
            editor.show_completion_list(comp_list,
                                        completion_text=words[-1],
                                        automatic=automatic)
            return
        elif self.rope_project:
            textlist = self.rope_project.get_completion_list(
                source_code, offset, editor.file_name or self.rope_temp_path)
            if textlist:
                completion_text = re.split(r"[^a-zA-Z0-9_]", text)[-1]
                if text.lstrip().startswith('#') and text.endswith('.'):
                    return
                else:
                    editor.show_completion_list(textlist, completion_text,
                                                automatic)
                return
    def _trigger_code_completion(self, automatic):
        editor = self.tabs.currentWidget()
        source_code = unicode(editor.toPlainText())
        offset = editor.get_position('cursor')
        text = editor.get_text('sol', 'cursor')

        if text.startswith('import '):
            comp_list = module_completion(text)
            words = text.split(' ')
            if ',' in words[-1]:
                words = words[-1].split(',')
            if comp_list:
                editor.show_completion_list(comp_list,
                                            completion_text=words[-1],
                                            automatic=automatic)
            return
        elif text.startswith('from '):
            comp_list = module_completion(text)
            words = text.split(' ')
            if '(' in words[-1]:
                words = words[:-2] + words[-1].split('(')
            if ',' in words[-1]:
                words = words[:-2] + words[-1].split(',')
            editor.show_completion_list(comp_list,
                                        completion_text=words[-1],
                                        automatic=automatic)
            return
        elif self.rope_project:
            textlist = self.rope_project.get_completion_list(
                source_code, offset, editor.file_name or self.rope_temp_path)
            if textlist:
                completion_text = re.split(r"[^a-zA-Z0-9_]", text)[-1]
                if text.lstrip().startswith('#') and text.endswith('.'):
                    return
                else:
                    editor.show_completion_list(textlist, completion_text,
                                                automatic)
                return
Beispiel #3
0
 def getmodcomplist(self, name, path):
     """Return module completion list for object named *name*"""
     return module_completion(name, path)