--- a/RefactoringRope/CodeAssistServer.py Sat Sep 30 14:52:32 2017 +0200 +++ b/RefactoringRope/CodeAssistServer.py Thu Oct 05 19:24:14 2017 +0200 @@ -49,15 +49,15 @@ self.__methodMapping = { "CompletionsResult": self.__processCompletionsResult, "CallTipsResult": self.__processCallTipsResult, + + "ClientException": self.__processClientException, } # Python 2 - interpreter = Preferences.getDebugger("PythonInterpreter") - self.__startCodeAssistClient(interpreter, "Python2") + self.__ensureActive("Python2") # Python 3 - interpreter = Preferences.getDebugger("Python3Interpreter") - self.__startCodeAssistClient(interpreter, "Python3") + self.__ensureActive("Python3") def __updateEditorLanguageMapping(self): """ @@ -111,6 +111,7 @@ offset = len("".join(source.splitlines(True)[:line])) + index maxfixes = self.__plugin.getPreferences("MaxFixes") + self.__ensureActive(idString) self.sendJson("getCompletions", { "FileName": filename, "Source": source, @@ -164,6 +165,7 @@ offset = len("".join(source.splitlines(True)[:line])) + index maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") + self.__ensureActive(idString) self.sendJson("getCallTips", { "FileName": filename, "Source": source, @@ -207,6 +209,7 @@ if language in self.__editorLanguageMapping: idString = self.__editorLanguageMapping[language] + self.__ensureActive(idString) self.sendJson("reportChanged", { "FileName": filename, "OldSource": oldSource, @@ -227,6 +230,35 @@ """ self.__methodMapping[method](params) + def __processClientException(self, params): + """ + Private method to handle exceptions of the refactoring client. + + @param params dictionary containing the exception data + @type dict + """ + if params["ExceptionType"] == "ProtocolError": + self.__ui.appendToStderr( + self.tr("""The data received from the code assist""" + """ server could not be decoded. Please report""" + """ this issue with the received data to the""" + """ eric bugs email address.\n""" + """Error: {0}\n""" + """Data: {1}\n""").format( + params["ExceptionValue"], + params["ProtocolData"])) + else: + self.__ui.appendToStderr( + self.tr("An exception happened in the code assist" + " client. Please report it to the eric bugs" + " email address.\n" + "Exception: {0}\n" + "Value: {1}\n" + "Traceback: {2}\n").format( + params["ExceptionType"], + params["ExceptionValue"], + params["Traceback"])) + def __startCodeAssistClient(self, interpreter, idString): """ Private method to start the code assist client with the given @@ -236,7 +268,11 @@ @type str @param idString id of the client to be started @type str + @return flag indicating a successful start of the client + @rtype bool """ + ok = False + if interpreter: client = os.path.join(os.path.dirname(__file__), "CodeAssistClient.py") @@ -246,13 +282,37 @@ if not ok: self.__ui.appendToStderr(self.tr( "'{0}' is not supported because the configured interpreter" - " could not be started." + " could not be started.\n" ).format(idString)) else: self.__ui.appendToStderr(self.tr( "'{0}' is not supported because no suitable interpreter is" - " configured." + " configured.\n" ).format(idString)) + + return ok + + def __ensureActive(self, idString): + """ + Private method to ensure, that the requested client is active. + + A non-active client will be started. + + @return flag indicating an active client + @rtype bool + """ + ok = idString in self.connectionNames() + if not ok: + # client is not running + if idString == "Python2": + # Python 2 + interpreter = Preferences.getDebugger("PythonInterpreter") + ok = self.__startCodeAssistClient(interpreter, "Python2") + elif idString == "Python3": + # Python 3 + interpreter = Preferences.getDebugger("Python3Interpreter") + ok = self.__startCodeAssistClient(interpreter, "Python3") + return ok @pyqtSlot() def handleNewConnection(self):