361 (cl.endlineno == -1 or line <= cl.endlineno): |
361 (cl.endlineno == -1 or line <= cl.endlineno): |
362 completions = [] |
362 completions = [] |
363 for super in cl.super: |
363 for super in cl.super: |
364 if prefix == word: |
364 if prefix == word: |
365 completions.extend( |
365 completions.extend( |
366 api.getCompletions(context=super)) |
366 api.getCompletions(context=super, |
|
367 followHierarchy=True)) |
367 else: |
368 else: |
368 completions.extend( |
369 completions.extend( |
369 api.getCompletions(start=word, context=super)) |
370 api.getCompletions(start=word, context=super, |
|
371 followHierarchy=True)) |
370 for completion in completions: |
372 for completion in completions: |
371 if not completion["context"]: |
373 if not completion["context"]: |
372 entry = completion["completion"] |
374 entry = completion["completion"] |
373 else: |
375 else: |
374 entry = "{0} ({1})".format( |
376 entry = "{0} ({1})".format( |
425 continue |
427 continue |
426 if entry not in completionsList: |
428 if entry not in completionsList: |
427 completionsList.append(entry) |
429 completionsList.append(entry) |
428 return completionsList |
430 return completionsList |
429 |
431 |
430 def __getDocumentCompletions(self, editor, word, context, sep, prefix, module): |
432 def __getDocumentCompletions(self, editor, word, context, sep, prefix, module, |
|
433 doHierarchy=False): |
431 """ |
434 """ |
432 Private method to determine autocompletion proposals from the document. |
435 Private method to determine autocompletion proposals from the document. |
433 |
436 |
434 @param editor reference to the editor object (QScintilla.Editor) |
437 @param editor reference to the editor object (QScintilla.Editor) |
435 @param word string to be completed (string) |
438 @param word string to be completed (string) |
436 @param context flag indicating to autocomplete a context (boolean) |
439 @param context flag indicating to autocomplete a context (boolean) |
437 @param sep separator string (string) |
440 @param sep separator string (string) |
438 @param prefix prefix of the word to be completed (string) |
441 @param prefix prefix of the word to be completed (string) |
439 @param module reference to the scanned module info (Module) |
442 @param module reference to the scanned module info (Module) |
|
443 @keyparam doHierarchy flag indicating a hierarchical search (boolean) |
440 @return list of possible completions (list of strings) |
444 @return list of possible completions (list of strings) |
441 """ |
445 """ |
442 completionsList = [] |
446 completionsList = [] |
443 |
447 |
444 prefixFound = False |
448 prefixFound = False |
494 for c in comps if c[0].startswith(word)]) |
498 for c in comps if c[0].startswith(word)]) |
495 else: |
499 else: |
496 completionsList.extend( |
500 completionsList.extend( |
497 ["{0} ({1})?{2}".format(c[0], c[1], c[2]) |
501 ["{0} ({1})?{2}".format(c[0], c[1], c[2]) |
498 for c in comps]) |
502 for c in comps]) |
|
503 |
|
504 for sup in cl.super: |
|
505 if sup in module.classes: |
|
506 if word == prefix: |
|
507 nword = sup |
|
508 else: |
|
509 nword = word |
|
510 completionsList.extend(self.__getDocumentCompletions( |
|
511 editor, nword, context, sep, sup, module, |
|
512 doHierarchy=True)) |
|
513 |
499 break |
514 break |
500 else: |
515 else: |
501 # possibly completing a named class attribute or method |
516 # possibly completing a named class attribute or method |
502 if prefix in module.classes: |
517 if prefix in module.classes: |
503 prefixFound = True |
518 prefixFound = True |
504 cl = module.classes[prefix] |
519 cl = module.classes[prefix] |
505 comps = [] |
520 comps = [] |
506 for method in cl.methods.values(): |
521 for method in cl.methods.values(): |
507 if method.name == "__init__": |
522 if method.name == "__init__": |
508 continue |
523 continue |
509 if not hasattr(method, "modifier"): |
524 if not doHierarchy and not hasattr(method, "modifier"): |
510 # eric 5.1 cannot differentiate method types |
525 # eric 5.1 cannot differentiate method types |
511 continue |
526 continue |
512 if method.modifier in [method.Class, method.Static]: |
527 if doHierarchy or \ |
|
528 method.modifier in [method.Class, method.Static]: |
513 # determine icon type |
529 # determine icon type |
514 if method.isPrivate(): |
530 if method.isPrivate(): |
|
531 if doHierarchy: |
|
532 continue |
515 iconID = Editor.MethodPrivateID |
533 iconID = Editor.MethodPrivateID |
516 elif method.isProtected(): |
534 elif method.isProtected(): |
517 iconID = Editor.MethodProtectedID |
535 iconID = Editor.MethodProtectedID |
518 else: |
536 else: |
519 iconID = Editor.MethodID |
537 iconID = Editor.MethodID |
534 for c in comps if c[0].startswith(word)]) |
552 for c in comps if c[0].startswith(word)]) |
535 else: |
553 else: |
536 completionsList.extend( |
554 completionsList.extend( |
537 ["{0} ({1})?{2}".format(c[0], c[1], c[2]) |
555 ["{0} ({1})?{2}".format(c[0], c[1], c[2]) |
538 for c in comps]) |
556 for c in comps]) |
|
557 |
|
558 for sup in cl.super: |
|
559 if sup in module.classes: |
|
560 if word == prefix: |
|
561 nword = sup |
|
562 else: |
|
563 nword = word |
|
564 completionsList.extend(self.__getDocumentCompletions( |
|
565 editor, nword, context, sep, sup, module, |
|
566 doHierarchy=True)) |
539 |
567 |
540 if not prefixFound: |
568 if not prefixFound: |
541 currentPos = editor.currentPosition() |
569 currentPos = editor.currentPosition() |
542 if context: |
570 if context: |
543 word += sep |
571 word += sep |
676 for cl in module.classes.values(): |
704 for cl in module.classes.values(): |
677 if line >= cl.lineno and \ |
705 if line >= cl.lineno and \ |
678 (cl.endlineno == -1 or line <= cl.endlineno): |
706 (cl.endlineno == -1 or line <= cl.endlineno): |
679 for super in cl.super: |
707 for super in cl.super: |
680 calltips.extend(api.getCalltips(word, commas, super, None, |
708 calltips.extend(api.getCalltips(word, commas, super, None, |
681 self.__plugin.getPreferences("CallTipsContextShown"))) |
709 self.__plugin.getPreferences("CallTipsContextShown"), |
|
710 followHierarchy=True)) |
682 break |
711 break |
683 else: |
712 else: |
684 calltips = api.getCalltips(word, commas, self.__lastContext, |
713 calltips = api.getCalltips(word, commas, self.__lastContext, |
685 self.__lastFullContext, |
714 self.__lastFullContext, |
686 self.__plugin.getPreferences("CallTipsContextShown")) |
715 self.__plugin.getPreferences("CallTipsContextShown")) |
687 |
716 |
688 return calltips |
717 return calltips |
689 |
718 |
690 def __getDocumentCalltips(self, word, prefix, module, editor): |
719 def __getDocumentCalltips(self, word, prefix, module, editor, doHierarchy=False): |
691 """ |
720 """ |
692 Private method to determine calltips from the document. |
721 Private method to determine calltips from the document. |
693 |
722 |
694 @param word function to get calltips for (string) |
723 @param word function to get calltips for (string) |
695 @param prefix prefix of the word to be completed (string) |
724 @param prefix prefix of the word to be completed (string) |
696 @param module reference to the scanned module info (Module) |
725 @param module reference to the scanned module info (Module) |
697 @param editor reference to the editor object (QScintilla.Editor) |
726 @param editor reference to the editor object (QScintilla.Editor) |
|
727 @keyparam doHierarchy flag indicating a hierarchical search (boolean) |
698 @return list of calltips (list of string) |
728 @return list of calltips (list of string) |
699 """ |
729 """ |
700 calltips = [] |
730 calltips = [] |
701 if module: |
731 if module: |
702 if prefix: |
732 if prefix: |
723 calltips.append("{0}{1}{2}({3})".format( |
753 calltips.append("{0}{1}{2}({3})".format( |
724 cl.name, |
754 cl.name, |
725 sep, |
755 sep, |
726 word, |
756 word, |
727 ', '.join(method.parameters[1:]))) |
757 ', '.join(method.parameters[1:]))) |
|
758 |
|
759 for sup in cl.super: |
|
760 calltips.extend(self.__getDocumentCalltips( |
|
761 word, sup, module, editor, doHierarchy=True)) |
|
762 |
728 break |
763 break |
729 else: |
764 else: |
730 if prefix in module.classes: |
765 if prefix in module.classes: |
731 cl = module.classes[prefix] |
766 cl = module.classes[prefix] |
732 if word in cl.methods: |
767 if word in cl.methods: |
733 method = cl.methods[word] |
768 method = cl.methods[word] |
734 if hasattr(method, "modifier") and \ |
769 if doHierarchy or \ |
735 method.modifier == method.Class: |
770 (hasattr(method, "modifier") and \ |
|
771 method.modifier == method.Class): |
736 # only eric 5.2 and newer can differentiate method types |
772 # only eric 5.2 and newer can differentiate method types |
737 calltips.append("{0}{1}{2}({3})".format( |
773 calltips.append("{0}{1}{2}({3})".format( |
738 cl.name, |
774 cl.name, |
739 sep, |
775 sep, |
740 word, |
776 word, |
741 ', '.join(method.parameters[1:]))) |
777 ', '.join(method.parameters[1:]))) |
|
778 |
|
779 for sup in cl.super: |
|
780 calltips.extend(self.__getDocumentCalltips( |
|
781 word, sup, module, editor, doHierarchy=True)) |
742 else: |
782 else: |
743 # calltip for a module function or class |
783 # calltip for a module function or class |
744 if word in module.functions: |
784 if word in module.functions: |
745 fun = module.functions[word] |
785 fun = module.functions[word] |
746 calltips.append("{0}({1})".format( |
786 calltips.append("{0}({1})".format( |
747 word, |
787 word, |
748 ', '.join(fun.parameters[1:]))) |
788 ', '.join(fun.parameters))) |
749 elif word in module.classes: |
789 elif word in module.classes: |
750 cl = module.classes[word] |
790 cl = module.classes[word] |
751 if "__init__" in cl.methods: |
791 if "__init__" in cl.methods: |
752 method = cl.methods["__init__"] |
792 method = cl.methods["__init__"] |
753 calltips.append("{0}({1})".format( |
793 calltips.append("{0}({1})".format( |