RefactoringRope/CodeAssist.py

changeset 118
d242ba11a04c
parent 106
b2b2107b8047
child 119
a03f2be1997b
equal deleted inserted replaced
117:7269e54fd316 118:d242ba11a04c
25 25
26 from PyQt5.QtCore import QObject 26 from PyQt5.QtCore import QObject
27 27
28 import Globals 28 import Globals
29 29
30
30 class CodeAssist(QObject): 31 class CodeAssist(QObject):
31 """ 32 """
32 Class implementing the autocompletion interface to rope. 33 Class implementing the autocompletion interface to rope.
33 """ 34 """
34 def __init__(self, plugin, parent = None): 35 def __init__(self, plugin, parent=None):
35 """ 36 """
36 Constructor 37 Constructor
37 38
38 @param plugin reference to the plugin object 39 @param plugin reference to the plugin object
39 @param parent parent (QObject) 40 @param parent parent (QObject)
63 source = editor.text() 64 source = editor.text()
64 offset = len("".join(source.splitlines(True)[:line])) + index 65 offset = len("".join(source.splitlines(True)[:line])) + index
65 maxfixes = self.__plugin.getPreferences("MaxFixes") 66 maxfixes = self.__plugin.getPreferences("MaxFixes")
66 try: 67 try:
67 proposals = rope.contrib.codeassist.code_assist( 68 proposals = rope.contrib.codeassist.code_assist(
68 self.__project, source, offset, resource, maxfixes = maxfixes) 69 self.__project, source, offset, resource, maxfixes=maxfixes)
69 proposals = rope.contrib.codeassist.sorted_proposals(proposals) 70 proposals = rope.contrib.codeassist.sorted_proposals(proposals)
70 names = [proposal.name for proposal in proposals] 71 names = [proposal.name for proposal in proposals]
71 return names 72 return names
72 except Exception: 73 except Exception:
73 return [] 74 return []
74 75
75 def getCallTips(self, pos, editor): 76 def getCallTips(self, pos, editor):
76 """ 77 """
77 Public method to calculate calltips. 78 Public method to calculate calltips.
78 79
80 @param pos position in the text for the calltip (integer)
79 @param editor reference to the editor object, that called this method 81 @param editor reference to the editor object, that called this method
80 QScintilla.Editor) 82 QScintilla.Editor)
81 @param pos position in the text for the calltip (integer)
82 @return list of possible calltips (list of strings) 83 @return list of possible calltips (list of strings)
83 """ 84 """
84 filename = editor.getFileName() 85 filename = editor.getFileName()
85 if filename: 86 if filename:
86 resource = rope.base.libutils.path_to_resource( 87 resource = rope.base.libutils.path_to_resource(
91 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") 92 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes")
92 try: 93 try:
93 line, index = editor.lineIndexFromPosition(pos) 94 line, index = editor.lineIndexFromPosition(pos)
94 offset = len("".join(source.splitlines(True)[:line])) + index 95 offset = len("".join(source.splitlines(True)[:line])) + index
95 cts = rope.contrib.codeassist.get_calltip( 96 cts = rope.contrib.codeassist.get_calltip(
96 self.__project, source, offset, resource, maxfixes = maxfixes, 97 self.__project, source, offset, resource, maxfixes=maxfixes,
97 remove_self = True) 98 remove_self=True)
98 if cts is not None: 99 if cts is not None:
99 cts = [cts] 100 cts = [cts]
100 else: 101 else:
101 cts = [] 102 cts = []
102 except Exception: 103 except Exception:

eric ide

mercurial