Anonymous avatar Anonymous committed af7e552

Better handling of backslash in the strings for finding out the current statement range

Comments (0)

Files changed (3)

docs/workingon.txt

 *** Auto-completion should ignore current statement @ 2 ***
   What if the statement in current line is spread in more than one line.
 
-- Use pass as placeholder when needed
-- When auto-completing at lines ending with a :
-- Ignoring strings contents
-- Ignoring comment contents
+- More tests for explicit and implicit continuations
 
 * Ignoring """ or ''' string content
 

rope/codeassist.py

         open_parens = 0
         explicit_continuation = False
         in_string = ''
-        for current_line in range(0, lineno + 1):
+        for current_line_number in range(0, lineno + 1):
             if not explicit_continuation and open_parens == 0 and in_string == '':
-                last_statement = current_line
-            for char in lines[current_line]:
+                last_statement = current_line_number
+            current_line = lines[current_line_number]
+            for i in range(len(current_line)):
+                char = current_line[i]
                 if char in '\'"':
                     if in_string == '':
                         in_string = char
-                    elif in_string == char:
+                    elif in_string == char and \
+                         not (i > 0 and current_line[i - 1] == '\\' and
+                              not (i > 1 and current_line[i - 2:i] == '\\\\')):
                         in_string = ''
                 if in_string != '':
                     continue
                     open_parens += 1
                 if char in ')]}':
                     open_parens -= 1
-            if lines[current_line].rstrip().endswith('\\'):
+            if current_line.rstrip().endswith('\\'):
                 explicit_continuation = True
             else:
                 explicit_continuation = False
             return indents
         last_indents = _count_line_indents(lines[last_statement])
         end_line = lineno
-        if lines[lineno].rstrip().endswith(':'):
+        if True or lines[lineno].rstrip().endswith(':'):
             for i in range(lineno + 1, len(lines)):
                 if _count_line_indents(lines[i]) > last_indents:
                     end_line = i

ropetest/codeassisttest.py

         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_in_result('my_var', 'global_variable', result)
 
+    def test_ignoring_current_statement_brackets_continuation(self):
+        code = "my_var = 10\n'hello'[10:\n        my_"
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_var', 'global_variable', result)
+
+    def test_ignoring_current_statement_explicit_continuation(self):
+        code = "my_var = 10\nmy_var2 = 2 + \\\n          my_"
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_var', 'global_variable', result)
+
     def test_ignoring_current_statement_while_the_first_statement_of_the_block(self):
         code = "my_var = 10\ndef f():\n    my_"
         result = self.assist.complete_code(code, len(code))
         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_in_result('my_var', 'global_variable', result)
 
-    def test_ignoring_string_comments(self):
+    def test_ignoring_comment_contents(self):
         code = "my_var = 10 #(\nmy_"
         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_in_result('my_var', 'global_variable', result)
 
+    def test_ignoring_string_contents_backslash_plus_quotes(self):
+        code = "my_var = '\\''\nmy_"
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_var', 'global_variable', result)
+
+    def test_ignoring_string_contents_backslash_plus_backslash(self):
+        code = "my_var = '\\\\'\nmy_"
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_var', 'global_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.