AssistantEric/Assistant.py

changeset 39
7b6ca9397ecc
parent 38
55f259fad55b
child 41
333735b1a460
--- a/AssistantEric/Assistant.py	Fri Sep 30 18:19:21 2011 +0200
+++ b/AssistantEric/Assistant.py	Sat Oct 01 16:21:09 2011 +0200
@@ -363,10 +363,12 @@
                         for super in cl.super:
                             if prefix == word:
                                 completions.extend(
-                                    api.getCompletions(context=super))
+                                    api.getCompletions(context=super,
+                                                       followHierarchy=True))
                             else:
                                 completions.extend(
-                                    api.getCompletions(start=word, context=super))
+                                    api.getCompletions(start=word, context=super,
+                                                       followHierarchy=True))
                         for completion in completions:
                             if not completion["context"]:
                                 entry = completion["completion"]
@@ -427,7 +429,8 @@
                         completionsList.append(entry)
         return completionsList
     
-    def __getDocumentCompletions(self, editor, word, context, sep, prefix, module):
+    def __getDocumentCompletions(self, editor, word, context, sep, prefix, module,
+                                 doHierarchy=False):
         """
         Private method to determine autocompletion proposals from the document.
         
@@ -437,6 +440,7 @@
         @param sep separator string (string)
         @param prefix prefix of the word to be completed (string)
         @param module reference to the scanned module info (Module)
+        @keyparam doHierarchy flag indicating a hierarchical search (boolean)
         @return list of possible completions (list of strings)
         """
         completionsList = []
@@ -496,6 +500,17 @@
                             completionsList.extend(
                                 ["{0} ({1})?{2}".format(c[0], c[1], c[2])
                                  for c in comps])
+                        
+                        for sup in cl.super:
+                            if sup in module.classes:
+                                if word == prefix:
+                                    nword = sup
+                                else:
+                                    nword = word
+                                completionsList.extend(self.__getDocumentCompletions(
+                                    editor, nword, context, sep, sup, module,
+                                    doHierarchy=True))
+                        
                         break
             else:
                 # possibly completing a named class attribute or method
@@ -506,12 +521,15 @@
                     for method in cl.methods.values():
                         if method.name == "__init__":
                             continue
-                        if not hasattr(method, "modifier"):
+                        if not doHierarchy and not hasattr(method, "modifier"):
                             # eric 5.1 cannot differentiate method types
                             continue
-                        if method.modifier in [method.Class, method.Static]:
+                        if doHierarchy or \
+                           method.modifier in [method.Class, method.Static]:
                             # determine icon type
                             if method.isPrivate():
+                                if doHierarchy:
+                                    continue
                                 iconID = Editor.MethodPrivateID
                             elif method.isProtected():
                                 iconID = Editor.MethodProtectedID
@@ -536,6 +554,16 @@
                         completionsList.extend(
                             ["{0} ({1})?{2}".format(c[0], c[1], c[2])
                              for c in comps])
+                    
+                    for sup in cl.super:
+                        if sup in module.classes:
+                            if word == prefix:
+                                nword = sup
+                            else:
+                                nword = word
+                            completionsList.extend(self.__getDocumentCompletions(
+                                editor, nword, context, sep, sup, module,
+                                doHierarchy=True))
         
         if not prefixFound:
             currentPos = editor.currentPosition()
@@ -678,7 +706,8 @@
                    (cl.endlineno == -1 or line <= cl.endlineno):
                     for super in cl.super:
                         calltips.extend(api.getCalltips(word, commas, super, None,
-                            self.__plugin.getPreferences("CallTipsContextShown")))
+                            self.__plugin.getPreferences("CallTipsContextShown"),
+                            followHierarchy=True))
                     break
         else:
             calltips = api.getCalltips(word, commas, self.__lastContext,
@@ -687,7 +716,7 @@
         
         return calltips
     
-    def __getDocumentCalltips(self, word, prefix, module, editor):
+    def __getDocumentCalltips(self, word, prefix, module, editor, doHierarchy=False):
         """
         Private method to determine calltips from the document.
         
@@ -695,6 +724,7 @@
         @param prefix prefix of the word to be completed (string)
         @param module reference to the scanned module info (Module)
         @param editor reference to the editor object (QScintilla.Editor)
+        @keyparam doHierarchy flag indicating a hierarchical search (boolean)
         @return list of calltips (list of string)
         """
         calltips = []
@@ -725,27 +755,37 @@
                                         sep,
                                         word,
                                         ', '.join(method.parameters[1:])))
+                            
+                            for sup in cl.super:
+                                calltips.extend(self.__getDocumentCalltips(
+                                    word, sup, module, editor, doHierarchy=True))
+                            
                             break
                 else:
                     if prefix in module.classes:
                         cl = module.classes[prefix]
                         if word in cl.methods:
                             method = cl.methods[word]
-                            if hasattr(method, "modifier") and \
-                               method.modifier == method.Class:
+                            if doHierarchy or \
+                               (hasattr(method, "modifier") and \
+                                method.modifier == method.Class):
                                 # only eric 5.2 and newer can differentiate method types
                                 calltips.append("{0}{1}{2}({3})".format(
                                     cl.name,
                                     sep,
                                     word,
                                     ', '.join(method.parameters[1:])))
+                        
+                        for sup in cl.super:
+                            calltips.extend(self.__getDocumentCalltips(
+                                word, sup, module, editor, doHierarchy=True))
             else:
                 # calltip for a module function or class
                 if word in module.functions:
                     fun = module.functions[word]
                     calltips.append("{0}({1})".format(
                         word,
-                        ', '.join(fun.parameters[1:])))
+                        ', '.join(fun.parameters)))
                 elif word in module.classes:
                     cl = module.classes[word]
                     if "__init__" in cl.methods:

eric ide

mercurial