Commits

Anonymous committed ddd95d0

Not commenting lines before current offset in get_doc

  • Participants
  • Parent commits 641898b

Comments (0)

Files changed (2)

File rope/contrib/codeassist.py

     errors in it.
 
     """
-    pymodule = _get_pymodule(project.pycore, source_code,
-                             resource, maxfixes=maxfixes)
+    pymodule = _get_pymodule(project.pycore, source_code, resource,
+                             maxfixes=maxfixes, error_limit=offset)
     scope_finder = ScopeNameFinder(pymodule)
     element = scope_finder.get_pyname_at(offset)
     if element is None:
         return len(self.lines) - 1
 
 
-def _get_pymodule(pycore, code, resource, maxfixes=1):
+def _get_pymodule(pycore, code, resource, maxfixes=1, error_limit=None):
+    """Get a `PyModule`
+
+    Errors before `error_limit` offset arereported and are not never
+    fixed.
+
+    """
     if resource and resource.exists() and code == resource.read():
         return pycore.resource_to_pyobject(resource)
     commenter = None
                 tries += 1
                 if commenter is None:
                     commenter = _Commenter(code.splitlines())
+                if error_limit is not None:
+                    offset = 0
+                    for line in commenter.lines[:e.lineno]:
+                        offset += len(line) + 1
+                    if offset <= error_limit:
+                        raise
                 commenter.comment(e.lineno)
                 code = '\n'.join(commenter.lines)
             else:

File ropetest/contrib/codeassisttest.py

         doc = get_doc(self.project, src,
                       src.rindex('replace') + 1, maxfixes=0)
 
+    @testutils.assert_raises(exceptions.ModuleSyntaxError)
+    def test_not_commenting_errors_before_offset(self):
+        src = 'lsjd lsjdf\ns = "hey"\ns.replace()\n'
+        doc = get_doc(self.project, src,
+                      src.rindex('replace') + 1, maxfixes=1)
+
     def test_proposing_variables_defined_till_the_end_of_scope(self):
         code = 'if True:\n    a_v\na_var = 10\n'
         result = self._assist(code, code.index('a_v') + 3)