Commit 5d4a6ef4 authored by Samir Ibradžić's avatar Samir Ibradžić Committed by Johannes Schmid

python-support: bgo#664263 - Auto-complete fails with rope <= 0.9.2, calltip always fail

parent 0152e621
......@@ -5,8 +5,11 @@ from rope.base.project import Project
from rope.contrib import codeassist
from rope.contrib import autoimport
import os, re
import pkg_resources
from distutils.version import LooseVersion as V
CompletionItem = namedtuple('CompletionItem', 'name info type scope location')
def new_completion_item(**i):
......@@ -67,11 +70,19 @@ class RopeComplete(object):
proposals = codeassist.code_assist(self.project, self.source_code, self.code_point, resource=self.resource, maxfixes=10)
proposals = codeassist.sorted_proposals(proposals)
for proposal in proposals:
ret.append(new_completion_item(, scope=proposal.scope, type=proposal.type))
if V(ROPE_VERSION) <= V('0.9.2'):
for proposal in proposals:
ret.append(new_completion_item(, scope=proposal.kind, type=proposal.type))
for proposal in proposals:
ret.append(new_completion_item(, scope=proposal.scope, type=proposal.type))
return ret
def get_calltip(self):
calltip = codeassist.get_doc(self.project, self.source_code, self.code_point, resource=self.resource, maxfixes=10)
return calltip
def parse_arguments(args):
""" Returns a dictionary containing all the parsed args
and a string containing the source_code """
......@@ -95,7 +106,8 @@ def parse_arguments(args):
ret['option'] = option_arg;
ret['project_path'] = str.replace(project_arg, 'file://', '') if project_arg.startswith('file://') else project_arg
ret['resource_path'] = os.path.relpath(res_arg, ret['project_path'])
ret['project_files'] = builder_files_arg.split('|')
if ret['option'] != 'calltip':
ret['project_files'] = builder_files_arg.split('|')
ret['position'] = int(offset_arg)
input = open(source_code_arg, 'r')
......@@ -105,10 +117,16 @@ def parse_arguments(args):
return ret
if __name__ == '__main__':
ROPE_VERSION = pkg_resources.get_distribution('rope').version
print '|Missing python-rope module!|.|.|.|.|'
args = parse_arguments(sys.argv[1:])
suggestions = []
calltip = ''
if args['option'] == 'autocomplete':
#get any completions Rope offers us
comp = RopeComplete(args['project_path'], args['source_code'], args['resource_path'], args['position'])
......@@ -117,10 +135,12 @@ if __name__ == '__main__':
comp = BuilderComplete(args['project_path'], args['resource_path'], args['source_code'], args['position'], args['project_files'])
elif args['option'] == 'calltip':
proposals = codeassist.get_doc(proj, source_code, position, resource=res, maxfixes=10)
calltip_obj = RopeComplete(args['project_path'], args['source_code'], args['resource_path'], args['position'])
calltip = calltip_obj.get_calltip()
for s in suggestions:
print "|{0}|{1}|{2}|{3}|{4}|".format(, s.scope, s.type, s.location,
print calltip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment