539 """ |
539 """ |
540 if "Error" not in result: |
540 if "Error" not in result: |
541 # ignore errors silently |
541 # ignore errors silently |
542 if "Location" in result: |
542 if "Location" in result: |
543 location = result["Location"] |
543 location = result["Location"] |
544 try: |
544 self.__vm.openSourceFile(location["ModulePath"], |
545 self.__vm.openSourceFile( |
545 location["Line"], |
546 location["ModulePath"], location["Line"], addNext=True) |
546 addNext=True) |
547 except TypeError: |
|
548 # backward compatibility; <= 17.03 |
|
549 self.__vm.openSourceFile( |
|
550 location["ModulePath"], location["Line"], next=True) |
|
551 else: |
547 else: |
552 e5App().getObject("UserInterface").statusBar().showMessage( |
548 e5App().getObject("UserInterface").statusBar().showMessage( |
553 self.tr('Code Assist: No definition found'), 5000) |
549 self.tr('Code Assist: No definition found'), 5000) |
554 |
550 |
555 ####################################################################### |
551 ####################################################################### |
661 clientEnv = os.environ.copy() |
657 clientEnv = os.environ.copy() |
662 if "PATH" in clientEnv: |
658 if "PATH" in clientEnv: |
663 clientEnv["PATH"] = self.__ui.getOriginalPathString() |
659 clientEnv["PATH"] = self.__ui.getOriginalPathString() |
664 venvManager = e5App().getObject("VirtualEnvManager") |
660 venvManager = e5App().getObject("VirtualEnvManager") |
665 if idString == "Python3": |
661 if idString == "Python3": |
666 # Python 3 |
|
667 venvName = Preferences.getDebugger("Python3VirtualEnv") |
662 venvName = Preferences.getDebugger("Python3VirtualEnv") |
668 if not venvName and sys.version_info[0] >= 3: |
663 if not venvName: |
669 venvName, _ = venvManager.getDefaultEnvironment() |
664 venvName, _ = venvManager.getDefaultEnvironment() |
670 if venvName: |
665 if venvName: |
671 interpreter = venvManager.getVirtualenvInterpreter( |
666 interpreter = venvManager.getVirtualenvInterpreter( |
672 venvName) |
667 venvName) |
673 |
668 |
698 """ |
693 """ |
699 projectLanguage = self.__e5project.getProjectLanguage() |
694 projectLanguage = self.__e5project.getProjectLanguage() |
700 interpreter = "" |
695 interpreter = "" |
701 clientEnv = os.environ.copy() |
696 clientEnv = os.environ.copy() |
702 if "PATH" in clientEnv: |
697 if "PATH" in clientEnv: |
703 try: |
698 clientEnv["PATH"] = self.__ui.getOriginalPathString() |
704 clientEnv["PATH"] = self.__ui.getOriginalPathString() |
|
705 except AttributeError: |
|
706 # ignore for eric6 < 18.12 |
|
707 pass |
|
708 |
699 |
709 if projectLanguage.startswith("Python"): |
700 if projectLanguage.startswith("Python"): |
710 try: |
701 venvManager = e5App().getObject("VirtualEnvManager") |
711 # new code using virtual environments |
702 |
712 venvManager = e5App().getObject("VirtualEnvManager") |
703 # get virtual environment from project first |
|
704 venvName = self.__e5project.getDebugProperty("VIRTUALENV") |
|
705 if not venvName: |
|
706 # get it from debugger settings next |
|
707 if projectLanguage == "Python3": |
|
708 venvName = Preferences.getDebugger("Python3VirtualEnv") |
|
709 if not venvName: |
|
710 venvName, _ = venvManager.getDefaultEnvironment() |
|
711 else: |
|
712 venvName = "" |
|
713 if venvName: |
|
714 interpreter = venvManager.getVirtualenvInterpreter( |
|
715 venvName |
|
716 ) |
|
717 execPath = venvManager.getVirtualenvExecPath(venvName) |
713 |
718 |
714 # get virtual environment from project first |
719 # build a suitable environment |
715 venvName = self.__e5project.getDebugProperty("VIRTUALENV") |
720 if execPath: |
716 if not venvName: |
721 if "PATH" in clientEnv: |
717 # get it from debugger settings next |
722 clientEnv["PATH"] = os.pathsep.join( |
718 if projectLanguage == "Python3": |
723 [execPath, clientEnv["PATH"]]) |
719 # Python 3 |
|
720 venvName = Preferences.getDebugger("Python3VirtualEnv") |
|
721 if not venvName and sys.version_info[0] >= 3: |
|
722 try: |
|
723 venvName, _ = ( |
|
724 venvManager.getDefaultEnvironment() |
|
725 ) |
|
726 except AttributeError: |
|
727 # ignore for eric6 < 18.10 |
|
728 pass |
|
729 else: |
724 else: |
730 venvName = "" |
725 clientEnv["PATH"] = execPath |
731 if venvName: |
|
732 interpreter = venvManager.getVirtualenvInterpreter( |
|
733 venvName |
|
734 ) |
|
735 |
|
736 try: |
|
737 execPath = venvManager.getVirtualenvExecPath(venvName) |
|
738 except AttributeError: |
|
739 # eric6 < 18.12 |
|
740 execPath = "" |
|
741 |
|
742 # build a suitable environment |
|
743 if execPath: |
|
744 if "PATH" in clientEnv: |
|
745 clientEnv["PATH"] = os.pathsep.join( |
|
746 [execPath, clientEnv["PATH"]]) |
|
747 else: |
|
748 clientEnv["PATH"] = execPath |
|
749 except KeyError: |
|
750 # backward compatibility (eric < 18.07) |
|
751 # get interpreter from project first |
|
752 interpreter = self.__e5project.getDebugProperty("INTERPRETER") |
|
753 if not interpreter or not Utilities.isinpath(interpreter): |
|
754 # get it from debugger settings second |
|
755 if projectLanguage == "Python3": |
|
756 interpreter = Preferences.getDebugger( |
|
757 "Python3Interpreter") |
|
758 |
726 |
759 return interpreter, clientEnv |
727 return interpreter, clientEnv |
760 |
728 |
761 @pyqtSlot() |
729 @pyqtSlot() |
762 def handleNewConnection(self): |
730 def handleNewConnection(self): |
763 """ |
731 """ |
764 Public slot for new incoming connections from a client. |
732 Public slot for new incoming connections from a client. |
765 """ |
733 """ |
766 super(CodeAssistServer, self).handleNewConnection() |
734 super().handleNewConnection() |
767 |
735 |
768 self.__updateEditorLanguageMapping() |
736 self.__updateEditorLanguageMapping() |
769 |
737 |
770 self.__getConfigs() |
738 self.__getConfigs() |
771 |
739 |
772 def activate(self): |
740 def activate(self): |
773 """ |
741 """ |
774 Public method to activate the code assist server. |
742 Public method to activate the code assist server. |
775 """ |
743 """ |
776 try: |
744 self.__documentationViewer = self.__ui.documentationViewer() |
777 self.__documentationViewer = self.__ui.documentationViewer() |
745 if self.__documentationViewer is not None: |
778 if self.__documentationViewer is not None: |
746 self.__documentationViewer.registerProvider( |
779 self.__documentationViewer.registerProvider( |
747 "rope", self.tr("Rope"), self.requestCodeDocumentation, |
780 "rope", self.tr("Rope"), self.requestCodeDocumentation, |
748 self.isSupportedLanguage) |
781 self.isSupportedLanguage) |
|
782 except AttributeError: |
|
783 # eric6 before 17.11 doesn't have this |
|
784 pass |
|
785 |
749 |
786 self.__e5project.projectClosed.connect(self.__projectClosed) |
750 self.__e5project.projectClosed.connect(self.__projectClosed) |
787 |
751 |
788 def deactivate(self): |
752 def deactivate(self): |
789 """ |
753 """ |