Sun, 08 Mar 2015 13:30:48 +0100
Little improvement to update the SOA database for refactoring upon saving a file.
# -*- coding: utf-8 -*- # Copyright (c) 2008 - 2015 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the autocompletion interface to rope. """ from __future__ import unicode_literals import os import sys sys.path.insert(0, os.path.dirname(__file__)) if sys.version_info[0] >= 3: path = os.path.join(os.path.dirname(__file__), 'rope_py3') else: path = os.path.join(os.path.dirname(__file__), 'rope_py2') str = unicode # __IGNORE_WARNING__ sys.path.insert(0, path) import rope.base.libutils import rope.contrib.codeassist from PyQt5.QtCore import QObject import Globals class CodeAssist(QObject): """ Class implementing the autocompletion interface to rope. """ def __init__(self, plugin, parent = None): """ Constructor @param plugin reference to the plugin object @param parent parent (QObject) """ QObject.__init__(self, parent) self.__plugin = plugin self.__project = rope.base.project.Project(Globals.getConfigDir()) self.__project.validate(self.__project.root) 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) """ filename = editor.getFileName() if filename: resource = rope.base.libutils.path_to_resource( self.__project, filename) else: resource = None 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( 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, 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) """ filename = editor.getFileName() if filename: resource = rope.base.libutils.path_to_resource( self.__project, filename) else: resource = None source = editor.text() maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") try: line, index = editor.lineIndexFromPosition(pos) offset = len("".join(source.splitlines(True)[:line])) + index cts = rope.contrib.codeassist.get_calltip( self.__project, source, offset, resource, maxfixes = maxfixes, remove_self = True) if cts is not None: cts = [cts] else: cts = [] 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) """ 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