22 str = unicode # __IGNORE_WARNING__ |
22 str = unicode # __IGNORE_WARNING__ |
23 sys.path.insert(0, path) |
23 sys.path.insert(0, path) |
24 |
24 |
25 import rope.base.libutils |
25 import rope.base.libutils |
26 import rope.contrib.codeassist |
26 import rope.contrib.codeassist |
|
27 from rope.base.exceptions import BadIdentifierError |
27 |
28 |
28 from JsonClient import JsonClient |
29 from JsonClient import JsonClient |
29 |
30 |
30 |
31 |
31 class CodeAssistClient(JsonClient): |
32 class CodeAssistClient(JsonClient): |
275 documentation = rope.contrib.codeassist.get_doc( |
276 documentation = rope.contrib.codeassist.get_doc( |
276 self.__project, source, offset, resource, maxfixes=maxfixes) |
277 self.__project, source, offset, resource, maxfixes=maxfixes) |
277 except Exception as err: |
278 except Exception as err: |
278 errorDict = self.__handleRopeError(err) |
279 errorDict = self.__handleRopeError(err) |
279 |
280 |
280 typeName = self.__getObjectTypeAnName( |
281 typeName = self.__getObjectTypeAndName( |
281 self.__project, source, offset, resource, maxfixes=maxfixes) |
282 self.__project, source, offset, resource, maxfixes=maxfixes) |
282 |
283 |
283 documentationDict = self.__processDocumentation(cts, documentation, |
284 documentationDict = self.__processDocumentation(cts, documentation, |
284 typeName) |
285 typeName) |
285 result = { |
286 result = { |
331 objectFullname = typeName[1] |
332 objectFullname = typeName[1] |
332 |
333 |
333 return dict(name=objectFullname, argspec=argspec, module=module, |
334 return dict(name=objectFullname, argspec=argspec, module=module, |
334 docstring=documentation, typ=typeName[0]) |
335 docstring=documentation, typ=typeName[0]) |
335 |
336 |
336 def __getObjectTypeAnName(self, project, sourceCode, offset, |
337 def __getObjectTypeAndName(self, project, sourceCode, offset, |
337 resource=None, maxfixes=1): |
338 resource=None, maxfixes=1): |
338 """ |
339 """ |
339 Private method to determine an object type and name for the given |
340 Private method to determine an object type and name for the given |
340 location. |
341 location. |
341 |
342 |
342 @param project reference to the rope project object |
343 @param project reference to the rope project object |
351 @type int |
352 @type int |
352 """ |
353 """ |
353 from rope.base import pyobjects, pyobjectsdef, pynames |
354 from rope.base import pyobjects, pyobjectsdef, pynames |
354 from rope.contrib import fixsyntax |
355 from rope.contrib import fixsyntax |
355 |
356 |
356 fixer = fixsyntax.FixSyntax(project, sourceCode, resource, maxfixes) |
357 try: |
357 pyname = fixer.pyname_at(offset) |
358 fixer = fixsyntax.FixSyntax(project, sourceCode, resource, |
|
359 maxfixes) |
|
360 pyname = fixer.pyname_at(offset) |
|
361 except BadIdentifierError: |
|
362 pyname = None |
358 if pyname is None: |
363 if pyname is None: |
359 return "<unknown>", "<unknown>" |
364 return "<unknown>", "<unknown>" |
360 |
365 |
361 pyobject = pyname.get_object() |
366 pyobject = pyname.get_object() |
362 if isinstance(pyobject, pyobjectsdef.PyPackage): |
367 if isinstance(pyobject, pyobjectsdef.PyPackage): |