diff -r 2d77b3afc98f -r f6049d39f83d RefactoringRope/CodeAssist.py --- a/RefactoringRope/CodeAssist.py Sat Mar 07 15:57:24 2015 +0100 +++ b/RefactoringRope/CodeAssist.py Sat Mar 07 19:52:36 2015 +0100 @@ -25,72 +25,77 @@ from PyQt5.QtCore import QObject +import Globals + class CodeAssist(QObject): """ Class implementing the autocompletion interface to rope. """ - def __init__(self, refactoring, editor, plugin, parent = None): + def __init__(self, plugin, parent = None): """ Constructor - @param refactoring reference to the rope refactoring object - (Refactoring) - @param editor reference to the editor object, that called this method - QScintilla.Editor) @param plugin reference to the plugin object @param parent parent (QObject) """ QObject.__init__(self, parent) - self.__refactoring = refactoring - self.__editor = editor self.__plugin = plugin + + self.__project = rope.base.project.Project(Globals.getConfigDir()) + self.__project.validate(self.__project.root) - def getCompletions(self): + def getCompletions(self, editor): """ Public method to calculate the possible completions. + @param editor reference to the editor object, that called this method + QScintilla.Editor) @return list of proposals (QStringList) """ - project = self.__refactoring.getProject() - project.validate(project.root) - filename = self.__editor.getFileName() + filename = editor.getFileName() if filename: - resource = rope.base.libutils.path_to_resource(project, filename) + resource = rope.base.libutils.path_to_resource( + self.__project, filename) else: resource = None - line, index = self.__editor.getCursorPosition() - source = self.__editor.text() + line, index = editor.getCursorPosition() + source = editor.text() offset = len("".join(source.splitlines(True)[:line])) + index maxfixes = self.__plugin.getPreferences("MaxFixes") try: proposals = rope.contrib.codeassist.code_assist( - project, source, offset, resource, maxfixes = maxfixes) + self.__project, source, offset, resource, maxfixes = maxfixes) proposals = rope.contrib.codeassist.sorted_proposals(proposals) names = [proposal.name for proposal in proposals] return names except Exception: return [] - def getCallTips(self, pos): + def getCallTips(self, pos, editor): """ Public method to calculate calltips. + @param editor reference to the editor object, that called this method + QScintilla.Editor) @param pos position in the text for the calltip (integer) @return list of possible calltips (list of strings) """ - project = self.__refactoring.getProject() - project.validate(project.root) - filename = self.__editor.getFileName() + filename = editor.getFileName() if filename: - resource = rope.base.libutils.path_to_resource(project, filename) + resource = rope.base.libutils.path_to_resource( + self.__project, filename) else: resource = None - source = self.__editor.text() + source = editor.text() maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") try: + if pos >= len(source) or source[pos] != "(": + offset = source.rindex("(", 0, pos) + else: + offset = pos cts = rope.contrib.codeassist.get_calltip( - project, source, pos, resource, maxfixes = maxfixes, + self.__project, source, offset, resource, maxfixes = maxfixes, remove_self = True) if cts is not None: cts = [cts] @@ -99,3 +104,20 @@ except Exception: cts = [] return cts + + def reportChanged(self, filename, oldSource): + """ + Public slot to report some changed sources. + + @param filename file name of the changed source (string) + @param oldSource source code before the change (string) + """ + import rope.base.libutils + + try: + rope.base.libutils.report_change( + self.__project, filename, oldSource) + except RuntimeError: + # this could come from trying to do PyQt4/PyQt5 mixed stuff + # simply ignore it + pass