Anonymous avatar Anonymous committed a4dc6e8

codeassist: offset in get_calltip() should be after the opening parens

Comments (0)

Files changed (2)

rope/contrib/codeassist.py

 
 
 def get_calltip(project, source_code, offset, resource=None, maxfixes=1):
-    pyname = _find_pyname_at(project, source_code, offset, resource, maxfixes)
+    finder = WordRangeFinder(source_code)
+    start = finder.find_parens_start_from_inside(max(0, offset - 1))
+    pyname = _find_pyname_at(project, source_code, start, resource, maxfixes)
     if pyname is None:
         return None
     pyobject = pyname.get_object()

ropetest/contrib/codeassisttest.py

         self.assert_completion_not_in_result('myvar', 'local', result)
 
     def test_simple_get_calltips(self):
-        src = 'def f():\n    pass\n'
-        doc = get_calltip(self.project, src, src.rindex('f'))
+        src = 'def f():\n    pass\nvar = f()\n'
+        doc = get_calltip(self.project, src, src.rindex(')'))
         self.assertEquals('f()', doc)
 
     def test_get_calltips_for_classes(self):
         src = 'class C(object):\n' \
-              '    def __init__(self):\n        pass\n'
-        doc = get_calltip(self.project, src, src.index('C'))
+              '    def __init__(self):\n        pass\nC('
+        doc = get_calltip(self.project, src, len(src))
         self.assertEquals('C.__init__(self)', doc)
 
     def test_get_calltips_for_objects_with_call(self):
         src = 'class C(object):\n' \
               '    def __call__(self, p):\n        pass\n' \
-              'c = C()\n'
-        doc = get_calltip(self.project, src, src.rindex('c'))
+              'c = C()\nc(1,'
+        doc = get_calltip(self.project, src, len(src))
         self.assertEquals('C.__call__(self, p)', doc)
 
     def test_get_calltips_and_including_module_name(self):
         src = 'class C(object):\n' \
               '    def __call__(self, p):\n        pass\n' \
-              'c = C()\n'
+              'c = C()\nc(1,'
         mod = testutils.create_module(self.project, 'mod')
         mod.write(src)
-        doc = get_calltip(self.project, src, src.rindex('c'), mod)
+        doc = get_calltip(self.project, src, len(src), mod)
         self.assertEquals('mod.C.__call__(self, p)', doc)
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.