--- a/RefactoringRope/CodeAssistServer.py Wed May 26 17:53:08 2021 +0200 +++ b/RefactoringRope/CodeAssistServer.py Wed May 26 19:07:42 2021 +0200 @@ -11,26 +11,22 @@ import sys import contextlib -from PyQt5.QtCore import ( +from PyQt6.QtCore import ( pyqtSlot, QCoreApplication, QTimer ) -from E5Gui.E5Application import e5App -from E5Gui import E5MessageBox +from EricWidgets.EricApplication import ericApp +from EricWidgets import EricMessageBox + +from EricNetwork.EricJsonServer import EricJsonServer from QScintilla.Editor import Editor -try: - from E5Network.E5JsonServer import E5JsonServer -except ImportError: - # TODO: delete JsonServer once ported to eric7 - from .JsonServer import JsonServer as E5JsonServer - import Globals import Preferences -class CodeAssistServer(E5JsonServer): +class CodeAssistServer(EricJsonServer): """ Class implementing the autocompletion interface to rope. """ @@ -66,15 +62,13 @@ self.__plugin = plugin self.__ui = parent - self.__vm = e5App().getObject("ViewManager") - self.__e5project = e5App().getObject("Project") + self.__vm = ericApp().getObject("ViewManager") + self.__e5project = ericApp().getObject("Project") self.__editorLanguageMapping = {} self.__clientConfigs = {} self.__editors = {} - self.__asyncCompletions = False - self.__documentationViewer = None # attributes to store the resuls of the client side @@ -106,15 +100,6 @@ # Python 3 self.__ensureActive("Python3") - def setAsyncCompletions(self, asynchronous): - """ - Public method to set the asynchronous completions flag. - - @param asynchronous flag indicating asynchronous completions - @type bool - """ - self.__asyncCompletions = asynchronous - def __updateEditorLanguageMapping(self): """ Private method to update the editor language to connection mapping. @@ -127,6 +112,7 @@ "MicroPython": "Python3", "Pygments|Python": "Python3", "Pygments|Python 2.x": "Python3", + "Cython": "Python3", }) def isSupportedLanguage(self, language): @@ -145,7 +131,7 @@ Private method to determine the ID string for the back-end. @param editor reference to the editor to determine the ID string for - @type QScintilla.Editor + @type Editor @return ID string @rtype str """ @@ -229,54 +215,18 @@ self.__editors[idString] = editor return else: - E5MessageBox.critical( + EricMessageBox.critical( self.__ui, self.tr("Configure Rope"), self.tr("""The Rope configuration file '{0}' does""" """ not exist.""").format(configfile)) - def getCompletions(self, editor, context): - """ - Public method to calculate the possible completions. - - Note: This is the synchronous variant for eric6 before 17.11. - - @param editor reference to the editor object, that called this method - @type QScintilla.Editor.Editor - @param context flag indicating to autocomplete a context - @type bool - @return list of possible completions - @rtype list of str - """ - if not self.__plugin.getPreferences("CodeAssistEnabled"): - return [] - - # reset the completions buffer - self.__completions = None - - if not self.__idString(editor): - return [] - - self.requestCompletions(editor, context, "") - - # emulate the synchronous behaviour - timer = QTimer() - timer.setSingleShot(True) - timer.start(5000) # 5s timeout - while self.__completions is None and timer.isActive(): - QCoreApplication.processEvents() - - return [] if self.__completions is None else self.__completions - def requestCompletions(self, editor, context, acText): """ Public method to request a list of possible completions. - Note: This is part of the asynchronous variant for eric6 17.11 and - later. - @param editor reference to the editor object, that called this method - @type QScintilla.Editor.Editor + @type Editor @param context flag indicating to autocomplete a context @type bool @param acText text to be completed @@ -320,26 +270,18 @@ completion['CompletionType'], '') names.append(name) - if self.__asyncCompletions: - # asynchronous variant for eric6 17.11 and later - if "Error" not in result: - editor = self.__vm.getOpenEditor(result["FileName"]) - if editor is not None: - editor.completionsListReady(names, - result["CompletionText"]) - else: - # synchronous variant for eric6 before 17.11 - if "Error" in result: - self.__completions = [] - else: - self.__completions = result["Completions"] + if "Error" not in result: + editor = self.__vm.getOpenEditor(result["FileName"]) + if editor is not None: + editor.completionsListReady(names, + result["CompletionText"]) def getCallTips(self, editor, pos, commas): """ Public method to calculate calltips. @param editor reference to the editor object, that called this method - @type QScintilla.Editor.Editor + @type Editor @param pos position in the text for the calltip @type int @param commas minimum number of commas contained in the calltip @@ -419,7 +361,7 @@ @param editor reference to the editor to get source code documentation for - @type QScintilla.Editor.Editor + @type Editor """ if self.__documentationViewer is None: return @@ -513,7 +455,7 @@ Note: This is executed upon a mouse click sequence. @param editor reference to the calling editor - @type QScintilla.Editor.Editor + @type Editor """ if not self.__plugin.getPreferences("MouseClickEnabled"): return @@ -551,7 +493,7 @@ location["Line"], addNext=True) else: - e5App().getObject("UserInterface").statusBar().showMessage( + ericApp().getObject("UserInterface").statusBar().showMessage( self.tr('Code Assist: No definition found'), 5000) ####################################################################### @@ -628,7 +570,7 @@ "CodeAssistClient.py") ok, exitCode = self.startClient( interpreter, client, - clientArgs=[configDir, Globals.getPythonModulesDirectory()], + clientArgs=[configDir, Globals.getPythonLibraryDirectory()], idString=idString, environment=clientEnv) if not ok: if exitCode == 42: @@ -670,7 +612,7 @@ clientEnv = os.environ.copy() if "PATH" in clientEnv: clientEnv["PATH"] = self.__ui.getOriginalPathString() - venvManager = e5App().getObject("VirtualEnvManager") + venvManager = ericApp().getObject("VirtualEnvManager") if idString == "Python3": venvName = Preferences.getDebugger("Python3VirtualEnv") if not venvName: @@ -711,7 +653,7 @@ clientEnv["PATH"] = self.__ui.getOriginalPathString() if projectLanguage.startswith("Python"): - venvManager = e5App().getObject("VirtualEnvManager") + venvManager = ericApp().getObject("VirtualEnvManager") # get virtual environment from project first venvName = self.__e5project.getDebugProperty("VIRTUALENV")