221 # backward compatibility < 16.12 |
224 # backward compatibility < 16.12 |
222 language = editor.apiLanguage |
225 language = editor.apiLanguage |
223 |
226 |
224 completeFromDocumentOnly = False |
227 completeFromDocumentOnly = False |
225 if language in ["", "Guessed"] or language.startswith("Pygments|"): |
228 if language in ["", "Guessed"] or language.startswith("Pygments|"): |
226 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
229 if ( |
227 AcsDocument: |
230 self.__plugin.getPreferences("AutoCompletionSource") & |
|
231 AcsDocument |
|
232 ): |
228 completeFromDocumentOnly = True |
233 completeFromDocumentOnly = True |
229 else: |
234 else: |
230 return [] |
235 return [] |
231 |
236 |
232 projectType = self.__getProjectType(editor) |
237 projectType = self.__getProjectType(editor) |
295 while col > 0 and beg[col - 1] not in wseps: |
302 while col > 0 and beg[col - 1] not in wseps: |
296 col -= 1 |
303 col -= 1 |
297 if col > 0 and beg[col - 1] != " ": |
304 if col > 0 and beg[col - 1] != " ": |
298 col -= 1 |
305 col -= 1 |
299 prefix = editor.getWordLeft(line, col) |
306 prefix = editor.getWordLeft(line, col) |
300 if editor.isPy2File() or editor.isPy3File(): |
307 if editor.isPyFile(): |
301 from Utilities.ModuleParser import Module |
308 from Utilities.ModuleParser import Module |
302 src = editor.text() |
309 src = editor.text() |
303 fn = editor.getFileName() |
310 fn = editor.getFileName() |
304 if fn is None: |
311 if fn is None: |
305 fn = "" |
312 fn = "" |
306 mod = Module("", fn, imp.PY_SOURCE) |
313 mod = Module("", fn, imp.PY_SOURCE) |
307 mod.scan(src) |
314 mod.scan(src) |
308 |
315 |
309 importCompletion = False |
316 importCompletion = False |
310 if editor.isPy2File() or editor.isPy3File(): |
317 if editor.isPyFile(): |
311 # check, if we are completing a from import statement |
318 # check, if we are completing a from import statement |
312 maxLines = 10 |
319 maxLines = 10 |
313 text = editor.text(line).strip() |
320 text = editor.text(line).strip() |
314 while maxLines and line > 0 and not text.startswith("from"): |
321 while maxLines and line > 0 and not text.startswith("from"): |
315 line -= 1 |
322 line -= 1 |
372 api = self.__apisManager.getAPIs( |
379 api = self.__apisManager.getAPIs( |
373 language, projectType=projectType) |
380 language, projectType=projectType) |
374 apiCompletionsList = self.__getApiCompletions( |
381 apiCompletionsList = self.__getApiCompletions( |
375 api, word, context, prefix, module, editor) |
382 api, word, context, prefix, module, editor) |
376 |
383 |
377 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
384 if ( |
378 AcsProject: |
385 self.__plugin.getPreferences("AutoCompletionSource") & |
|
386 AcsProject |
|
387 ): |
379 api = self.__apisManager.getAPIs(ApisNameProject) |
388 api = self.__apisManager.getAPIs(ApisNameProject) |
380 projectCompletionList = self.__getApiCompletions( |
389 projectCompletionList = self.__getApiCompletions( |
381 api, word, context, prefix, module, editor) |
390 api, word, context, prefix, module, editor) |
382 |
391 |
383 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument \ |
392 if ( |
384 and not importCompletion: |
393 self.__plugin.getPreferences("AutoCompletionSource") & |
|
394 AcsDocument and |
|
395 not importCompletion |
|
396 ): |
385 docCompletionsList = self.__getDocumentCompletions( |
397 docCompletionsList = self.__getDocumentCompletions( |
386 editor, word, context, sep, prefix, module) |
398 editor, word, context, sep, prefix, module) |
387 |
399 |
388 completionsList = list( |
400 completionsList = list( |
389 set(apiCompletionsList) |
401 set(apiCompletionsList) |
407 completionsList = [] |
419 completionsList = [] |
408 if api is not None: |
420 if api is not None: |
409 if prefix and module and prefix == "self": |
421 if prefix and module and prefix == "self": |
410 line, col = editor.getCursorPosition() |
422 line, col = editor.getCursorPosition() |
411 for cl in module.classes.values(): |
423 for cl in module.classes.values(): |
412 if line >= cl.lineno and \ |
424 if ( |
413 (cl.endlineno == -1 or line <= cl.endlineno): |
425 line >= cl.lineno and |
|
426 (cl.endlineno == -1 or line <= cl.endlineno) |
|
427 ): |
414 completions = [] |
428 completions = [] |
415 for superClass in cl.super: |
429 for superClass in cl.super: |
416 if prefix == word: |
430 if prefix == word: |
417 completions.extend( |
431 completions.extend( |
418 api.getCompletions( |
432 api.getCompletions( |
521 |
535 |
522 line, col = editor.getCursorPosition() |
536 line, col = editor.getCursorPosition() |
523 if prefix in ["cls", "self"]: |
537 if prefix in ["cls", "self"]: |
524 prefixFound = True |
538 prefixFound = True |
525 for cl in module.classes.values(): |
539 for cl in module.classes.values(): |
526 if line >= cl.lineno and \ |
540 if ( |
527 (cl.endlineno == -1 or line <= cl.endlineno): |
541 line >= cl.lineno and |
|
542 (cl.endlineno == -1 or line <= cl.endlineno) |
|
543 ): |
528 comps = [] |
544 comps = [] |
529 for method in cl.methods.values(): |
545 for method in cl.methods.values(): |
530 if method.name == "__init__": |
546 if method.name == "__init__": |
531 continue |
547 continue |
532 # determine icon type |
548 # determine icon type |
534 iconID = Editor.MethodPrivateID |
550 iconID = Editor.MethodPrivateID |
535 elif method.isProtected(): |
551 elif method.isProtected(): |
536 iconID = Editor.MethodProtectedID |
552 iconID = Editor.MethodProtectedID |
537 else: |
553 else: |
538 iconID = Editor.MethodID |
554 iconID = Editor.MethodID |
539 if (prefix == "cls" and |
555 if ( |
540 method.modifier == method.Class) or \ |
556 (prefix == "cls" and |
541 prefix == "self": |
557 method.modifier == method.Class) or |
|
558 prefix == "self" |
|
559 ): |
542 comps.append((method.name, cl.name, iconID)) |
560 comps.append((method.name, cl.name, iconID)) |
543 if prefix != "cls": |
561 if prefix != "cls": |
544 for attribute in cl.attributes.values(): |
562 for attribute in cl.attributes.values(): |
545 # determine icon type |
563 # determine icon type |
546 if attribute.isPrivate(): |
564 if attribute.isPrivate(): |
588 cl = module.classes[prefix] |
606 cl = module.classes[prefix] |
589 comps = [] |
607 comps = [] |
590 for method in cl.methods.values(): |
608 for method in cl.methods.values(): |
591 if method.name == "__init__": |
609 if method.name == "__init__": |
592 continue |
610 continue |
593 if doHierarchy or \ |
611 if ( |
594 method.modifier in [method.Class, method.Static]: |
612 doHierarchy or |
|
613 method.modifier in [method.Class, method.Static] |
|
614 ): |
595 # determine icon type |
615 # determine icon type |
596 if method.isPrivate(): |
616 if method.isPrivate(): |
597 if doHierarchy: |
617 if doHierarchy: |
598 continue |
618 continue |
599 iconID = Editor.MethodPrivateID |
619 iconID = Editor.MethodPrivateID |
653 else: |
673 else: |
654 completion = word |
674 completion = word |
655 line, index = editor.lineIndexFromPosition(pos) |
675 line, index = editor.lineIndexFromPosition(pos) |
656 curWord = editor.getWord(line, index, useWordChars=False) |
676 curWord = editor.getWord(line, index, useWordChars=False) |
657 completion += curWord[len(completion):] |
677 completion += curWord[len(completion):] |
658 if completion and completion not in completionsList and \ |
678 if ( |
659 completion != word: |
679 completion and |
|
680 completion not in completionsList and |
|
681 completion != word |
|
682 ): |
660 completionsList.append( |
683 completionsList.append( |
661 "{0}?{1}".format( |
684 "{0}?{1}".format( |
662 completion, self.__fromDocumentID)) |
685 completion, self.__fromDocumentID)) |
663 |
686 |
664 res = editor.findNextTarget() |
687 res = editor.findNextTarget() |
702 # backward compatibility < 16.12 |
725 # backward compatibility < 16.12 |
703 language = editor.apiLanguage |
726 language = editor.apiLanguage |
704 |
727 |
705 completeFromDocumentOnly = False |
728 completeFromDocumentOnly = False |
706 if language in ["", "Guessed"] or language.startswith("Pygments|"): |
729 if language in ["", "Guessed"] or language.startswith("Pygments|"): |
707 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
730 if ( |
708 AcsDocument: |
731 self.__plugin.getPreferences("AutoCompletionSource") & |
|
732 AcsDocument |
|
733 ): |
709 completeFromDocumentOnly = True |
734 completeFromDocumentOnly = True |
710 else: |
735 else: |
711 return [] |
736 return [] |
712 |
737 |
713 projectType = self.__getProjectType(editor) |
738 projectType = self.__getProjectType(editor) |
714 |
739 |
715 line, col = editor.lineIndexFromPosition(pos) |
740 line, col = editor.lineIndexFromPosition(pos) |
716 wc = re.sub("\w", "", editor.wordCharacters()) |
741 wc = re.sub("\w", "", editor.wordCharacters()) |
717 pat = re.compile("\w{0}".format(re.escape(wc))) |
742 pat = re.compile("\w{0}".format(re.escape(wc))) |
718 text = editor.text(line) |
743 text = editor.text(line) |
719 while col > 0 and \ |
744 while col > 0 and not pat.match(text[col - 1]): |
720 not pat.match(text[col - 1]): |
|
721 col -= 1 |
745 col -= 1 |
722 word = editor.getWordLeft(line, col) |
746 word = editor.getWordLeft(line, col) |
723 |
747 |
724 prefix = "" |
748 prefix = "" |
725 mod = None |
749 mod = None |
736 while col > 0 and beg[col - 1] not in wseps + [" ", "\t"]: |
760 while col > 0 and beg[col - 1] not in wseps + [" ", "\t"]: |
737 col -= 1 |
761 col -= 1 |
738 if col >= 0: |
762 if col >= 0: |
739 col -= 1 |
763 col -= 1 |
740 prefix = editor.getWordLeft(line, col) |
764 prefix = editor.getWordLeft(line, col) |
741 if editor.isPy2File() or editor.isPy3File(): |
765 if editor.isPyFile(): |
742 from Utilities.ModuleParser import Module |
766 from Utilities.ModuleParser import Module |
743 src = editor.text() |
767 src = editor.text() |
744 fn = editor.getFileName() |
768 fn = editor.getFileName() |
745 if fn is None: |
769 if fn is None: |
746 fn = "" |
770 fn = "" |
757 language, projectType=projectType) |
781 language, projectType=projectType) |
758 if api is not None: |
782 if api is not None: |
759 apiCalltips = self.__getApiCalltips( |
783 apiCalltips = self.__getApiCalltips( |
760 api, word, commas, prefix, mod, editor) |
784 api, word, commas, prefix, mod, editor) |
761 |
785 |
762 if self.__plugin.getPreferences("AutoCompletionSource") & \ |
786 if ( |
763 AcsProject: |
787 self.__plugin.getPreferences("AutoCompletionSource") & |
|
788 AcsProject |
|
789 ): |
764 api = self.__apisManager.getAPIs(ApisNameProject) |
790 api = self.__apisManager.getAPIs(ApisNameProject) |
765 projectCalltips = self.__getApiCalltips( |
791 projectCalltips = self.__getApiCalltips( |
766 api, word, commas, prefix, mod, editor) |
792 api, word, commas, prefix, mod, editor) |
767 |
793 |
768 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
794 if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
790 """ |
816 """ |
791 calltips = [] |
817 calltips = [] |
792 if prefix and module and prefix == "self": |
818 if prefix and module and prefix == "self": |
793 line, col = editor.getCursorPosition() |
819 line, col = editor.getCursorPosition() |
794 for cl in module.classes.values(): |
820 for cl in module.classes.values(): |
795 if line >= cl.lineno and \ |
821 if ( |
796 (cl.endlineno == -1 or line <= cl.endlineno): |
822 line >= cl.lineno and |
|
823 (cl.endlineno == -1 or line <= cl.endlineno) |
|
824 ): |
797 for superClass in cl.super: |
825 for superClass in cl.super: |
798 calltips.extend(api.getCalltips( |
826 calltips.extend(api.getCalltips( |
799 word, commas, superClass, None, |
827 word, commas, superClass, None, |
800 self.__plugin.getPreferences( |
828 self.__plugin.getPreferences( |
801 "CallTipsContextShown"), |
829 "CallTipsContextShown"), |
827 # prefix can be 'self', 'cls' or a class name |
855 # prefix can be 'self', 'cls' or a class name |
828 sep = editor.getLexer().autoCompletionWordSeparators()[0] |
856 sep = editor.getLexer().autoCompletionWordSeparators()[0] |
829 if prefix in ["self", "cls"]: |
857 if prefix in ["self", "cls"]: |
830 line, col = editor.getCursorPosition() |
858 line, col = editor.getCursorPosition() |
831 for cl in module.classes.values(): |
859 for cl in module.classes.values(): |
832 if line >= cl.lineno and \ |
860 if ( |
833 (cl.endlineno == -1 or line <= cl.endlineno): |
861 line >= cl.lineno and |
|
862 (cl.endlineno == -1 or line <= cl.endlineno) |
|
863 ): |
834 if word in cl.methods: |
864 if word in cl.methods: |
835 method = cl.methods[word] |
865 method = cl.methods[word] |
836 if prefix == "self" or \ |
866 if ( |
837 (prefix == "cls" and |
867 prefix == "self" or |
838 method.modifier == method.Class): |
868 (prefix == "cls" and |
|
869 method.modifier == method.Class) |
|
870 ): |
839 calltips.append( |
871 calltips.append( |
840 "{0}{1}{2}({3})".format( |
872 "{0}{1}{2}({3})".format( |
841 cl.name, |
873 cl.name, |
842 sep, |
874 sep, |
843 word, |
875 word, |