Anonymous avatar Anonymous committed 557b5f4

codeassist: add CompletionProposal.parameters

Comments (0)

Files changed (1)

rope/contrib/codeassist.py

 
     """
 
-    def __init__(self, name, kind, type=None):
+    def __init__(self, name, kind, type=None, pyname=None):
         super(CompletionProposal, self).__init__(name, kind)
         self.type = type
+        self.pyname = pyname
 
     def __str__(self):
         return '%s (%s, %s)' % (self.name, self.kind, self.type)
     def __repr__(self):
         return str(self)
 
+    @property
+    def parameters(self):
+        """The names of the parameters the function takes.
+
+        Returns None if this completion is not a function.
+        """
+        if isinstance(self.pyname, pynames.DefinedName):
+            pyobject = self.pyname.get_object()
+            if isinstance(pyobject, pyobject.AbstractFunction):
+                return pyobject.get_param_names()
+
 
 def sorted_proposals(proposals, kindpref=None, typepref=None):
     """Sort a list of proposals
             for name, pyname in element.get_attributes().items():
                 if name.startswith(self.starting):
                     result[name] = CompletionProposal(
-                        name, 'attribute', self._get_pyname_type(pyname))
+                        name, 'attribute', self._get_pyname_type(pyname), pyname)
         return result
 
     def _undotted_completions(self, scope, result, lineno=None):
                 if lineno is None or self.later_locals or \
                    not self._is_defined_after(scope, pyname, lineno):
                     result[name] = CompletionProposal(
-                        name, kind, self._get_pyname_type(pyname))
+                        name, kind, self._get_pyname_type(pyname), pyname)
 
     def _from_import_completions(self, pymodule):
         module_name = self.word_finder.get_from_module(self.offset)
         for name in pymodule:
             if name.startswith(self.starting):
                 result[name] = CompletionProposal(name, kind='global',
-                                                  type='imported')
+                                                  type='imported',
+                                                  pyname=pymodule[name])
         return result
 
     def _find_module(self, pymodule, module_name):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.