Commits

Ali Gholami Rudi  committed fcb0751

codeassist: get_calltip() includes module name

  • Participants
  • Parent commits 029ab5f

Comments (0)

Files changed (2)

File rope/contrib/codeassist.py

 from rope.base import pyobjects, pynames, taskhandle, builtins, exceptions
 from rope.base.codeanalyze import (ArrayLinesAdapter, LogicalLineFinder,
                                    SourceLinesAdapter, WordRangeFinder)
-from rope.refactor import occurrences, functionutils
+from rope.refactor import occurrences, functionutils, importutils
 
 
 def code_assist(project, source_code, offset, resource=None,
         except exceptions.AttributeNotFoundError:
             return None
         if isinstance(pyobject, pyobjects.AbstractFunction):
-            return self._get_function_signature(pyobject)
+            return self._get_function_signature(pyobject, add_module=True)
 
     def _get_class_docstring(self, pyclass):
         contents = self._trim_docstring(pyclass.get_doc(), 2)
             result.extend(self._get_super_methods(super_class, name))
         return result
 
-    def _get_function_signature(self, pyfunction):
+    def _get_function_signature(self, pyfunction, add_module=False):
         if isinstance(pyfunction, pyobjects.PyFunction):
-            if self._is_method(pyfunction):
-                prefix = pyfunction.parent.get_name() + '.'
-            else:
-                prefix = ''
+            prefixes = []
+            module = pyfunction.get_module()
+            if add_module:
+                prefixes.append(self._get_module(pyfunction))
+            parent = pyfunction.parent
+            while not isinstance(parent, pyobjects.AbstractModule):
+                prefixes.append(parent.get_name())
+                prefixes.append('.')
+                parent = parent.parent
             info = functionutils.DefinitionInfo.read(pyfunction)
-            return prefix + info.to_string()
+            return ''.join(prefixes) + info.to_string()
         else:
             return '%s(%s)' % (pyfunction.get_name(),
                                ', '.join(pyfunction.get_param_names()))
 
+    def _get_module(self, pyfunction):
+        module = pyfunction.get_module()
+        if module is not None:
+            resource = module.get_resource()
+            if resource is not None:
+                return importutils.get_module_name(
+                    pyfunction.pycore, resource) + '.'
+        return ''
+
     def _trim_docstring(self, docstring, indents=0):
         """The sample code from :PEP:`257`"""
         if not docstring:

File ropetest/contrib/codeassisttest.py

         doc = get_calltip(self.project, src, src.rindex('c'))
         self.assertEquals('C.__call__(self, p)', doc)
 
+    def test_get_calltips_and_including_module_name(self):
+        src = 'class C(object):\n' \
+              '    def __call__(self, p):\n        pass\n' \
+              'c = C()\n'
+        mod = testutils.create_module(self.project, 'mod')
+        mod.write(src)
+        doc = get_calltip(self.project, src, src.rindex('c'), mod)
+        self.assertEquals('mod.C.__call__(self, p)', doc)
+
 
 class CodeAssistInProjectsTest(unittest.TestCase):