RefactoringRope/CodeAssistClient.py

branch
server_client_variant
changeset 217
874115c79ca7
parent 216
47fb0119f0be
child 228
e76a4991faef
equal deleted inserted replaced
216:47fb0119f0be 217:874115c79ca7
71 "getConfig": self.__getConfig, 71 "getConfig": self.__getConfig,
72 "configChanged": self.__configChanged, 72 "configChanged": self.__configChanged,
73 "closeProject": self.__closeProject, 73 "closeProject": self.__closeProject,
74 "getCompletions": self.__getCompletions, 74 "getCompletions": self.__getCompletions,
75 "getCallTips": self.__getCallTips, 75 "getCallTips": self.__getCallTips,
76 "getDocumentation": self.__getDocumentation,
76 "reportChanged": self.__reportChanged, 77 "reportChanged": self.__reportChanged,
77 } 78 }
78 79
79 self.__projectpath = projectPath 80 self.__projectpath = projectPath
80 self.__project = rope.base.project.Project(self.__projectpath) 81 self.__project = rope.base.project.Project(self.__projectpath)
161 filename = params["FileName"] 162 filename = params["FileName"]
162 source = params["Source"] 163 source = params["Source"]
163 offset = params["Offset"] 164 offset = params["Offset"]
164 maxfixes = params["MaxFixes"] 165 maxfixes = params["MaxFixes"]
165 166
167 self.__project.prefs.set("python_path", params["SysPath"])
166 if filename: 168 if filename:
167 resource = rope.base.libutils.path_to_resource( 169 resource = rope.base.libutils.path_to_resource(
168 self.__project, filename) 170 self.__project, filename)
169 else: 171 else:
170 resource = None 172 resource = None
205 filename = params["FileName"] 207 filename = params["FileName"]
206 source = params["Source"] 208 source = params["Source"]
207 offset = params["Offset"] 209 offset = params["Offset"]
208 maxfixes = params["MaxFixes"] 210 maxfixes = params["MaxFixes"]
209 211
212 self.__project.prefs.set("python_path", params["SysPath"])
210 if filename: 213 if filename:
211 resource = rope.base.libutils.path_to_resource( 214 resource = rope.base.libutils.path_to_resource(
212 self.__project, filename) 215 self.__project, filename)
213 else: 216 else:
214 resource = None 217 resource = None
230 } 233 }
231 result.update(errorDict) 234 result.update(errorDict)
232 235
233 self.sendJson("CallTipsResult", result) 236 self.sendJson("CallTipsResult", result)
234 237
238 def __getDocumentation(self, params):
239 """
240 Private method to get some source code documentation.
241
242 @param params dictionary containing the method parameters
243 @type dict
244 """
245 filename = params["FileName"]
246 source = params["Source"]
247 offset = params["Offset"]
248 maxfixes = params["MaxFixes"]
249
250 self.__project.prefs.set("python_path", params["SysPath"])
251 if filename:
252 resource = rope.base.libutils.path_to_resource(
253 self.__project, filename)
254 else:
255 resource = None
256
257 errorDict = {}
258 documentation = ""
259 cts = None
260
261 try:
262 cts = rope.contrib.codeassist.get_calltip(
263 self.__project, source, offset, resource, maxfixes=maxfixes,
264 remove_self=True)
265 except Exception:
266 pass
267
268 if cts is not None:
269 while '..' in cts:
270 cts = cts.replace('..', '.')
271 if '(.)' in cts:
272 cts = cts.replace('(.)', '(...)')
273
274 try:
275 documentation = rope.contrib.codeassist.get_doc(
276 self.__project, source, offset, resource, maxfixes=maxfixes)
277 except Exception as err:
278 errorDict = self.__handleRopeError(err)
279
280 documentationDict = self.__processDocumentation(cts, documentation)
281 result = {
282 "DocumentationDict": documentationDict,
283 }
284 result.update(errorDict)
285
286 self.sendJson("DocumentationResult", result)
287
288 def __processDocumentation(self, cts, documentation):
289 """
290 Private method to process the call-tips and documentation.
291
292 @param cts call-tips
293 @type str
294 @param documentation extracted source code documentation
295 @type str
296 @return dictionary containing document information
297 @rtype dictionary with keys "name", "argspec", "module" and
298 "docstring"
299 """
300 objectFullname = ''
301 calltip = ''
302 argspec = ''
303 module = ''
304
305 if cts:
306 cts = cts.replace('.__init__', '')
307 parenthesisPos = cts.find('(')
308 if parenthesisPos:
309 objectFullname = cts[:parenthesisPos]
310 objectName = objectFullname.split('.')[-1]
311 cts = cts.replace(objectFullname, objectName)
312 calltip = cts
313 if objectFullname and not objectFullname.startswith('self.'):
314 if calltip:
315 argspecStart = calltip.find('(')
316 argspec = calltip[argspecStart:]
317 moduleEnd = objectFullname.rfind('.')
318 module = objectFullname[:moduleEnd]
319
320 if not documentation and not calltip:
321 return None
322
323 return dict(name=objectFullname, argspec=argspec, module=module,
324 docstring=documentation)
325
235 def __reportChanged(self, params): 326 def __reportChanged(self, params):
236 """ 327 """
237 Private method to register some changed sources. 328 Private method to register some changed sources.
238 329
239 @param params dictionary containing the method parameters sent by 330 @param params dictionary containing the method parameters sent by

eric ide

mercurial