Anonymous avatar Anonymous committed d1d18b3

Not proposing variables that are defined later in the current scope

Comments (0)

Files changed (3)

docs/workingon.txt

   What if the statement in current line is spread in more than one line.
 
 - More tests for explicit and implicit continuations
-i Transform big unextractible methods into method objects
+? Transform big unextractible methods into method objects
+- Not proposing variables defined after current line in the same scope
 
 * Ignoring """ or ''' string content
 
 ! scopes_count does not work because there might be loops and other blocks
 ? Add rope.scopes module
 ? Completions for for-loop, except, lambda, with variables
-? Not proposing local_variables that are defined after current position
 ? Remote pair programming support
 ? Completions are context dependant
 ? Separating ui modules and packages

rope/codeassist.py

 
 class _CurrentStatementRangeFinder(object):
     """A method object for finding the range of current statement"""
+
     def __init__(self, lines, lineno):
         self.lines = lines
         self.lineno = lineno
         end_line = self.lineno
         if True or self.lines[self.lineno].rstrip().endswith(':'):
             for i in range(self.lineno + 1, len(self.lines)):
-                if self.get_line_indents(i) > last_indents:
+                if self.get_line_indents(i) >= last_indents:
                     end_line = i
                 else:
                     break

ropetest/codeassisttest.py

         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_in_result('my_var', 'global_variable', result)
 
+    def test_not_proposing_later_defined_variables_in_current_block(self):
+        code = "my_\nmy_var = 10\n"
+        result = self.assist.complete_code(code, 3)
+        self.assert_proposal_not_in_result('my_var', 'global_variable', result)
+
+    def test_not_proposing_later_defined_variables_in_current_function(self):
+        code = "def f():\n    my_\n    my_var = 10\n"
+        result = self.assist.complete_code(code, 16)
+        self.assert_proposal_not_in_result('my_var', 'local_variable', result)
+
 
 if __name__ == '__main__':
     unittest.main()
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.