275 documentation = rope.contrib.codeassist.get_doc( |
275 documentation = rope.contrib.codeassist.get_doc( |
276 self.__project, source, offset, resource, maxfixes=maxfixes) |
276 self.__project, source, offset, resource, maxfixes=maxfixes) |
277 except Exception as err: |
277 except Exception as err: |
278 errorDict = self.__handleRopeError(err) |
278 errorDict = self.__handleRopeError(err) |
279 |
279 |
280 documentationDict = self.__processDocumentation(cts, documentation) |
280 typeName = self.__getObjectTypeAnName( |
|
281 self.__project, source, offset, resource, maxfixes=maxfixes) |
|
282 |
|
283 documentationDict = self.__processDocumentation(cts, documentation, |
|
284 typeName) |
281 result = { |
285 result = { |
282 "DocumentationDict": documentationDict, |
286 "DocumentationDict": documentationDict, |
283 } |
287 } |
284 result.update(errorDict) |
288 result.update(errorDict) |
285 |
289 |
286 self.sendJson("DocumentationResult", result) |
290 self.sendJson("DocumentationResult", result) |
287 |
291 |
288 def __processDocumentation(self, cts, documentation): |
292 def __processDocumentation(self, cts, documentation, typeName): |
289 """ |
293 """ |
290 Private method to process the call-tips and documentation. |
294 Private method to process the call-tips and documentation. |
291 |
295 |
292 @param cts call-tips |
296 @param cts call-tips |
293 @type str |
297 @type str |
294 @param documentation extracted source code documentation |
298 @param documentation extracted source code documentation |
295 @type str |
299 @type str |
|
300 @param typeName type and name of the object |
|
301 @type tuple of (str, str) |
296 @return dictionary containing document information |
302 @return dictionary containing document information |
297 @rtype dictionary with keys "name", "argspec", "module" and |
303 @rtype dictionary with keys "name", "argspec", "module" and |
298 "docstring" |
304 "docstring" |
299 """ |
305 """ |
300 objectFullname = "" |
306 objectFullname = "" |
310 objectName = objectFullname.split('.')[-1] |
316 objectName = objectFullname.split('.')[-1] |
311 cts = cts.replace(objectFullname, objectName) |
317 cts = cts.replace(objectFullname, objectName) |
312 calltip = cts |
318 calltip = cts |
313 else: |
319 else: |
314 objectFullname = cts |
320 objectFullname = cts |
|
321 |
315 if objectFullname and not objectFullname.startswith("self."): |
322 if objectFullname and not objectFullname.startswith("self."): |
316 if calltip: |
323 if calltip: |
317 argspecStart = calltip.find("(") |
324 argspecStart = calltip.find("(") |
318 argspec = calltip[argspecStart:] |
325 argspec = calltip[argspecStart:] |
319 |
326 |
320 moduleEnd = objectFullname.rfind('.') |
327 moduleEnd = objectFullname.rfind('.') |
321 module = objectFullname[:moduleEnd] |
328 module = objectFullname[:moduleEnd] |
322 |
329 |
323 if not documentation and not calltip: |
330 if not objectFullname and typeName[1] not in ["", "<unknown>"]: |
324 return None |
331 objectFullname = typeName[1] |
325 |
332 |
326 return dict(name=objectFullname, argspec=argspec, module=module, |
333 return dict(name=objectFullname, argspec=argspec, module=module, |
327 docstring=documentation) |
334 docstring=documentation, typ=typeName[0]) |
|
335 |
|
336 def __getObjectTypeAnName(self, project, sourceCode, offset, |
|
337 resource=None, maxfixes=1): |
|
338 """ |
|
339 Private method to determine an object type and name for the given |
|
340 location. |
|
341 |
|
342 @param project reference to the rope project object |
|
343 @type rope.base.project.Project |
|
344 @param sourceCode source code |
|
345 @type str |
|
346 @param offset offset to base the calculation on |
|
347 @type int |
|
348 @param resource reference to the rope resource object |
|
349 @type rope.base.resources.Resource |
|
350 @param maxfixes number of fixes to be done |
|
351 @type int |
|
352 """ |
|
353 from rope.base import pyobjects, pyobjectsdef, pynames |
|
354 from rope.contrib import fixsyntax |
|
355 |
|
356 fixer = fixsyntax.FixSyntax(project, sourceCode, resource, maxfixes) |
|
357 pyname = fixer.pyname_at(offset) |
|
358 if pyname is None: |
|
359 return "<unknown>", "<unknown>" |
|
360 |
|
361 pyobject = pyname.get_object() |
|
362 if isinstance(pyobject, pyobjectsdef.PyPackage): |
|
363 typ = "package" |
|
364 if isinstance(pyname, pynames.ImportedModule): |
|
365 name = pyname.module_name |
|
366 else: |
|
367 name = "<unknown>" |
|
368 elif isinstance(pyobject, pyobjectsdef.PyModule): |
|
369 typ = "module" |
|
370 name = pyobject.get_name() |
|
371 elif isinstance(pyobject, pyobjectsdef.PyClass): |
|
372 typ = "class" |
|
373 name = pyobject.get_name() |
|
374 elif isinstance(pyobject, pyobjectsdef.PyFunction): |
|
375 typ = pyobject.get_kind() |
|
376 name = pyobject.get_name() |
|
377 elif isinstance(pyobject, pyobjects.PyObject): |
|
378 typ = "object" |
|
379 name = "" |
|
380 else: |
|
381 typ = "" |
|
382 name = "" |
|
383 |
|
384 return(typ, name) |
328 |
385 |
329 def __reportChanged(self, params): |
386 def __reportChanged(self, params): |
330 """ |
387 """ |
331 Private method to register some changed sources. |
388 Private method to register some changed sources. |
332 |
389 |