RefactoringRope/CodeAssistServer.py

branch
server_client_variant
changeset 199
ae2ad82725b0
parent 198
898d8b4187de
child 200
1584892147ef
equal deleted inserted replaced
198:898d8b4187de 199:ae2ad82725b0
48 self.__completions = None 48 self.__completions = None
49 self.__calltips = None 49 self.__calltips = None
50 50
51 self.__methodMapping = { 51 self.__methodMapping = {
52 "CompletionsResult": self.__processCompletionsResult, 52 "CompletionsResult": self.__processCompletionsResult,
53 "CallTipsResult": self.__processCallTipsResult,
53 } 54 }
54 55
55 # Python 2 56 # Python 2
56 interpreter = Preferences.getDebugger("PythonInterpreter") 57 interpreter = Preferences.getDebugger("PythonInterpreter")
57 self.__startCodeAssistClient(interpreter, "Python2") 58 self.__startCodeAssistClient(interpreter, "Python2")
138 if "Error" in result: 139 if "Error" in result:
139 self.__completions = [] 140 self.__completions = []
140 else: 141 else:
141 self.__completions = result["Completions"] 142 self.__completions = result["Completions"]
142 143
143 # TODO: port this to the distributed variant
144 def getCallTips(self, pos, editor): 144 def getCallTips(self, pos, editor):
145 """ 145 """
146 Public method to calculate calltips. 146 Public method to calculate calltips.
147 147
148 @param pos position in the text for the calltip (integer) 148 @param pos position in the text for the calltip
149 @type int
149 @param editor reference to the editor object, that called this method 150 @param editor reference to the editor object, that called this method
150 QScintilla.Editor) 151 @type QScintilla.Editor
151 @return list of possible calltips (list of strings) 152 @return list of possible calltips
152 """ 153 @rtype list of str
153 print("rope: getCallTips") 154 """
154 return [] 155 # reset the calltips buffer
155 ## filename = editor.getFileName() 156 self.__calltips = None
156 ## if filename: 157
157 ## resource = rope.base.libutils.path_to_resource( 158 language = editor.getLanguage()
158 ## self.__project, filename) 159 if language not in self.__editorLanguageMapping:
159 ## else: 160 return []
160 ## resource = None 161 idString = self.__editorLanguageMapping[language]
161 ## source = editor.text() 162
162 ## maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") 163 filename = editor.getFileName()
163 ## try: 164 source = editor.text()
164 ## line, index = editor.lineIndexFromPosition(pos) 165 line, index = editor.lineIndexFromPosition(pos)
165 ## offset = len("".join(source.splitlines(True)[:line])) + index 166 offset = len("".join(source.splitlines(True)[:line])) + index
166 ## cts = rope.contrib.codeassist.get_calltip( 167 maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes")
167 ## self.__project, source, offset, resource, maxfixes=maxfixes, 168
168 ## remove_self=True) 169 self.sendJson("getCallTips", {
169 ## if cts is not None: 170 "FileName": filename,
170 ## cts = [cts] 171 "Source": source,
171 ## else: 172 "Offset": offset,
172 ## cts = [] 173 "MaxFixes": maxfixes,
173 ## except Exception: 174 }, idString=idString)
174 ## cts = [] 175
175 ## return cts 176 # emulate the synchronous behaviour
177 timer = QTimer()
178 timer.setSingleShot(True)
179 timer.start(5000) # 5s timeout
180 while self.__calltips is None and timer.isActive():
181 QCoreApplication.processEvents()
182
183 return [] if self.__calltips is None else self.__calltips
184
185 def __processCallTipsResult(self, result):
186 """
187 Private method to process the calltips sent by the client.
188
189 @param result dictionary containg the result sent by the client
190 @type dict
191 """
192 if "Error" in result:
193 self.__calltips = []
194 else:
195 self.__calltips = result["CallTips"]
176 196
177 # TODO: port this to the distributed variant 197 # TODO: port this to the distributed variant
178 def reportChanged(self, filename, oldSource): 198 def reportChanged(self, filename, oldSource):
179 """ 199 """
180 Public slot to report some changed sources. 200 Public slot to report some changed sources.

eric ide

mercurial