Commits

Ali Gholami Rudi  committed d8ecad3

Ignoring current statement continued using either implicit of explicit continuation

  • Participants
  • Parent commits 8c2dc2f

Comments (0)

Files changed (6)

 Version Overview
 ----------------
 Features added in this release:
-  * Auto complete global variables
-  * Auto complete class and function names
-  * Showing searching status in status bar
-  * Auto complete imported modules
-  * Auto complete keywords and builtins
-
-In this release some basic auto-completion support was added.
+  *
 
 
 Keybinding
 Get Involved!
 -------------
   Rope has just started. Right now rope's design changes rapidly and it's not
-yet ready for code contributions. I hope in soon future, somewhere around version
+yet ready for code contributions. I hope in soon future, somewhere about version
 0.5 or 0.6, rope would be mature enough for being extended easily.
 
   Anyway right now contributions are really needed in many places. For example

File docs/stories.txt

 * File Encodings @ 2
 
 
+* Static type inference @ 6
+
+
 * Changing next/prev word to stop on underline and capital letters @ 1
 
 
   ? Separating entering and correcting indentation
 
 
+* Dynamic type inference @ 3
+
+
 * Rename local variable @ 2
 
 
 * Proposing templates in auto-completion proposals @ 2
 
 
-* Auto-complete from-import imported objects @ 2
+* Auto-complete from-import imported objects @ 3
 
 
-* Auto-completion should ignore current statement @ 1
+* Auto-completion should ignore current statement @ 2
   What if the statement in current line is spread in more than one line.
 
 

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.
 
-! Scopes_count does not work because there might be loops and other blocks
+* Ignoring strings contents
+* When auto-completing at lines ending with a :
+? str joining is very fast
+? Use pass as placeholder
+
+! scopes_count does not work because there might be loops and other blocks
 ? Add rope.scopes module
-? For loop, except, lambda variables
+? 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

File rope/codeassist.py

             current_offset -= 1;
         return current_offset + 1
 
-    def _comment_current_line(self, source_code, offset):
-        line_beginning = offset - 1
-        while line_beginning >= 0 and source_code[line_beginning] != '\n':
-            line_beginning -= 1
-        line_ending = offset
-        while line_ending < len(source_code) and source_code[line_ending] != '\n':
-            line_ending += 1
-        result = source_code
-        if line_beginning != -1 and line_beginning < line_ending - 1:
-            result = source_code[:line_beginning] + '#' + source_code[line_beginning + 2:]
-        return result
-    
+    def _comment_current_statement(self, source_code, offset):
+        lines = source_code.split('\n')
+        current_pos = 0
+        lineno = 0
+        while current_pos + len(lines[lineno]) < offset:
+            current_pos += len(lines[lineno]) + 1
+            lineno += 1
+        last_statement = 0
+        open_parens = 0
+        explicit_continuation = False
+        for current_line in range(0, lineno + 1):
+            if not explicit_continuation and open_parens == 0:
+                last_statement = current_line
+            for char in lines[current_line]:
+                if char in '([{':
+                    open_parens += 1
+                if char in ')]}':
+                    open_parens -= 1
+            if lines[current_line].rstrip().endswith('\\'):
+                explicit_continuation = True
+            else:
+                explicit_continuation = False
+        last_indents = 0
+        for char in lines[last_statement]:
+            if char == ' ':
+                last_indents += 1
+            else:
+                break
+        lines[last_statement] = last_indents * ' ' + 'pass'
+        for line in range(last_statement + 1, lineno + 1):
+            lines[line] = '#' + lines[line]
+        lines.append('\n')
+        return '\n'.join(lines)
+
+
     def _get_matching_builtins(self, starting):
         result = {}
         for builtin in self.builtins:
             return []
         starting_offset = self._find_starting_offset(source_code, offset)
         starting = source_code[starting_offset:offset]
-        commented_source_code = self._comment_current_line(source_code, offset)
+        commented_source_code = self._comment_current_statement(source_code, offset)
         try:
             code_ast = compiler.parse(commented_source_code)
         except SyntaxError, e:

File ropetest/codeassisttest.py

         self.assertEquals(1, count)
 
     def test_throwing_exception_in_case_of_syntax_errors(self):
-        code = 'sample (sdf\n'
+        code = 'sample (sdf+)\n'
         self.assertRaises(RopeSyntaxError, 
                           lambda: self.assist.complete_code(code, len(code)))
     
         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_not_in_result('my_param', 'local_variable', result)
 
+    def test_ignoring_current_statement(self):
+        code = "my_var = 10\nmy_tuple = (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_while_the_first_statement_of_the_block(self):
+        code = "my_var = 10\ndef f():\n    my_"
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_var', 'global_variable', result)
+
 
 if __name__ == '__main__':
     unittest.main()

File ropetest/indentertest.py

         self.indenter.insert_tab(self.editor.get_end())
         self.assertEquals('print "a"    ', self.editor.get_text())
 
+    # ignoring strings while correcting indentations
+    def xxx_test_ignoring_parens_in_strings(self):
+        self.editor.set_text('print "("\na = 10')
+        self.indenter.correct_indentation(self.editor.get_end())
+        self.assertEquals('print "("\na = 10', self.editor.get_text())
+
 
 if __name__ == '__main__':
     unittest.main()