Exemplo n.º 1
0
    def handle_info(self, cts, doc_text, source_code, offset):

        obj_fullname = ''
        calltip = ''
        argspec = ''
        note = ''

        if cts:
            cts = cts.replace('.__init__', '')
            parpos = cts.find('(')
            if parpos:
                obj_fullname = cts[:parpos]
                obj_name = obj_fullname.split('.')[-1]
                cts = cts.replace(obj_fullname, obj_name)
                calltip = cts
                if ('()' in cts) or ('(...)' in cts):
                    # Either inspected object has no argument, or it's
                    # a builtin or an extension -- in this last case
                    # the following attempt may succeed:
                    calltip = getsignaturefromtext(doc_text, obj_name)
        if not obj_fullname:
            obj_fullname = sourcecode.get_primary_at(source_code, offset)
        if obj_fullname and not obj_fullname.startswith('self.'):
            # doc_text was generated by utils.dochelpers.getdoc
            if type(doc_text) is dict:
                obj_fullname = doc_text['name'] or obj_fullname
                argspec = doc_text['argspec']
                note = doc_text['note']
                doc_text = doc_text['docstring']
            elif calltip:
                argspec_st = calltip.find('(')
                argspec = calltip[argspec_st:]
                module_end = obj_fullname.rfind('.')
                module = obj_fullname[:module_end]
                note = 'Present in %s module' % module

        if not doc_text and not calltip:
            return

        return dict(name=obj_fullname,
                    argspec=argspec,
                    note=note,
                    docstring=doc_text,
                    calltip=calltip)
Exemplo n.º 2
0
 def _get_definition_location_regex(self, source_code, offset, filename):
     """
     Find the definition for an object within a set of source code
     
     This is used to find the path of python-like modules 
     (e.g. cython and enaml) for a goto definition
     """
     token = sourcecode.get_primary_at(source_code, offset)
     eol = sourcecode.get_eol_chars(source_code) or '\n'
     lines = source_code[:offset].split(eol)
     line_nr = None
     if '.' in token:
         temp = token.split('.')[-1]
         line_nr = self.get_definition_with_regex(source_code, temp,
                                                  len(lines))
     if line_nr is None:
         line_nr = self.get_definition_with_regex(source_code, token,
                                                  len(lines), True)
     if line_nr is None and '.' in token:
         temp = token.split('.')[-1]
         line_nr = self.get_definition_with_regex(source_code, temp,
                                                  len(lines), True)
     if line_nr is None:
         return None, None
     line = source_code.split(eol)[line_nr - 1].strip()
     exts = self.python_like_exts()
     if not osp.splitext(filename)[-1] in exts:
         return filename, line_nr
     if line.startswith('import ') or line.startswith('from '):
         alt_path = osp.dirname(filename)
         source_file = self.python_like_mod_finder(line,
                                                   alt_path=alt_path,
                                                   stop_token=token)
         if (not source_file or not osp.splitext(source_file)[-1] in exts):
             line_nr = self.get_definition_with_regex(
                 source_code, token, line_nr)
             return filename, line_nr
         mod_name = osp.basename(source_file).split('.')[0]
         if mod_name == token or mod_name == '__init__':
             return source_file, 1
         else:
             line_nr = self.get_definition_from_file(source_file, token)
             return source_file, line_nr
     return filename, line_nr
Exemplo n.º 3
0
 def _get_definition_location_regex(self, source_code, offset, filename):
     """
     Find the definition for an object within a set of source code
     
     This is used to find the path of python-like modules 
     (e.g. cython and enaml) for a goto definition
     """
     token = sourcecode.get_primary_at(source_code, offset)
     eol = sourcecode.get_eol_chars(source_code) or '\n'
     lines = source_code[:offset].split(eol)
     line_nr = None
     if '.' in token:
         temp = token.split('.')[-1]
         line_nr = self.get_definition_with_regex(source_code, temp, 
                                                  len(lines))
     if line_nr is None:
         line_nr = self.get_definition_with_regex(source_code, token, 
                                              len(lines), True)
     if line_nr is None and '.' in token:
         temp = token.split('.')[-1]
         line_nr = self.get_definition_with_regex(source_code, temp, 
                                              len(lines), True)
     if line_nr is None:
         return None, None
     line = source_code.split(eol)[line_nr - 1].strip()
     exts = self.python_like_exts()
     if not osp.splitext(filename)[-1] in exts:
         return filename, line_nr
     if line.startswith('import ') or line.startswith('from '):
         alt_path = osp.dirname(filename)
         source_file = self.python_like_mod_finder(line, alt_path=alt_path,
                                              stop_token=token)
         if (not source_file or
                 not osp.splitext(source_file)[-1] in exts):
             line_nr = self.get_definition_with_regex(source_code, token, 
                                                      line_nr)
             return filename, line_nr
         mod_name = osp.basename(source_file).split('.')[0]
         if mod_name == token or mod_name == '__init__':
             return source_file, 1
         else:
             line_nr = self.get_definition_from_file(source_file, token)
             return source_file, line_nr
     return filename, line_nr
Exemplo n.º 4
0
    def handle_info(self, cts, doc_text, source_code, offset):

        obj_fullname = ''
        calltip = ''
        argspec = ''
        note = ''

        if cts:
            cts = cts.replace('.__init__', '')
            parpos = cts.find('(')
            if parpos:
                obj_fullname = cts[:parpos]
                obj_name = obj_fullname.split('.')[-1]
                cts = cts.replace(obj_fullname, obj_name)
                calltip = cts
                if ('()' in cts) or ('(...)' in cts):
                    # Either inspected object has no argument, or it's
                    # a builtin or an extension -- in this last case
                    # the following attempt may succeed:
                    calltip = getsignaturefromtext(doc_text, obj_name)
        if not obj_fullname:
            obj_fullname = sourcecode.get_primary_at(source_code, offset)
        if obj_fullname and not obj_fullname.startswith('self.'):
            # doc_text was generated by utils.dochelpers.getdoc
            if type(doc_text) is dict:
                obj_fullname = doc_text['name'] or obj_fullname
                argspec = doc_text['argspec']
                note = doc_text['note']
                doc_text = doc_text['docstring']
            elif calltip:
                argspec_st = calltip.find('(')
                argspec = calltip[argspec_st:]
                module_end = obj_fullname.rfind('.')
                module = obj_fullname[:module_end]
                note = 'Present in %s module' % module

        if not doc_text and not calltip:
            return

        return dict(name=obj_fullname, argspec=argspec, note=note,
            docstring=doc_text, calltip=calltip)
Exemplo n.º 5
0
    def handle_info(self, cts, doc_text, source_code, offset):

        obj_fullname = ""
        calltip = ""
        argspec = ""
        note = ""

        if cts:
            cts = cts.replace(".__init__", "")
            parpos = cts.find("(")
            if parpos:
                obj_fullname = cts[:parpos]
                obj_name = obj_fullname.split(".")[-1]
                cts = cts.replace(obj_fullname, obj_name)
                calltip = cts
                if ("()" in cts) or ("(...)" in cts):
                    # Either inspected object has no argument, or it's
                    # a builtin or an extension -- in this last case
                    # the following attempt may succeed:
                    calltip = getsignaturefromtext(doc_text, obj_name)
        if not obj_fullname:
            obj_fullname = sourcecode.get_primary_at(source_code, offset)
        if obj_fullname and not obj_fullname.startswith("self."):
            # doc_text was generated by utils.dochelpers.getdoc
            if type(doc_text) is dict:
                obj_fullname = doc_text["name"] or obj_fullname
                argspec = doc_text["argspec"]
                note = doc_text["note"]
                doc_text = doc_text["docstring"]
            elif calltip:
                argspec_st = calltip.find("(")
                argspec = calltip[argspec_st:]
                module_end = obj_fullname.rfind(".")
                module = obj_fullname[:module_end]
                note = "Present in %s module" % module

        if not doc_text and not calltip:
            return

        return dict(name=obj_fullname, argspec=argspec, note=note, docstring=doc_text, calltip=calltip)