Commits

Ali Gholami Rudi  committed 3974ba8

Taking care when current line ends with a colon
Ignoring string and comment contents

  • Participants
  • Parent commits d8ecad3

Comments (0)

Files changed (3)

File docs/workingon.txt

 *** Auto-completion should ignore current statement @ 2 ***
   What if the statement in current line is spread in more than one line.
 
-* Ignoring strings contents
-* When auto-completing at lines ending with a :
-? str joining is very fast
-? Use pass as placeholder
+- Use pass as placeholder when needed
+- When auto-completing at lines ending with a :
+- Ignoring strings contents
+- Ignoring comment contents
+
+* Ignoring """ or ''' string content
 
 ! scopes_count does not work because there might be loops and other blocks
 ? Add rope.scopes module

File rope/codeassist.py

         last_statement = 0
         open_parens = 0
         explicit_continuation = False
+        in_string = ''
         for current_line in range(0, lineno + 1):
-            if not explicit_continuation and open_parens == 0:
+            if not explicit_continuation and open_parens == 0 and in_string == '':
                 last_statement = current_line
             for char in lines[current_line]:
+                if char in '\'"':
+                    if in_string == '':
+                        in_string = char
+                    elif in_string == char:
+                        in_string = ''
+                if in_string != '':
+                    continue
+                if char == '#':
+                    break
                 if char in '([{':
                     open_parens += 1
                 if char in ')]}':
                 explicit_continuation = True
             else:
                 explicit_continuation = False
-        last_indents = 0
-        for char in lines[last_statement]:
-            if char == ' ':
-                last_indents += 1
-            else:
-                break
+        def _count_line_indents(line):
+            indents = 0
+            for char in line:
+                if char == ' ':
+                    indents += 1
+                else:
+                    break
+            return indents
+        last_indents = _count_line_indents(lines[last_statement])
+        end_line = lineno
+        if lines[lineno].rstrip().endswith(':'):
+            for i in range(lineno + 1, len(lines)):
+                if _count_line_indents(lines[i]) > last_indents:
+                    end_line = i
+                else:
+                    break
         lines[last_statement] = last_indents * ' ' + 'pass'
-        for line in range(last_statement + 1, lineno + 1):
-            lines[line] = '#' + lines[line]
+        for line in range(last_statement + 1, end_line + 1):
+            lines[line] = '#' # + lines[line]
         lines.append('\n')
         return '\n'.join(lines)
 

File 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_while_current_line_ends_with_a_colon(self):
+        code = "my_var = 10\nif my_:\n    pass"
+        result = self.assist.complete_code(code, 18)
+        self.assert_proposal_in_result('my_var', 'global_variable', result)
+
+    def test_ignoring_string_contents(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_comments(self):
+        code = "my_var = 10 #(\nmy_"
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_var', 'global_variable', result)
+
 
 if __name__ == '__main__':
     unittest.main()