Commits

Ali Gholami Rudi  committed 77d5018

Handling a_func()()

  • Participants
  • Parent commits 0ce18de

Comments (0)

Files changed (6)

File docs/future.txt

 * Encapsulate attribute
 * Inline method
 * Change method signature
+* Introduce redirection
 
 Advanced Algorithms
 -------------------

File docs/stories.txt

 
 * Enhancing editor @ 8h
 
-  * Kill line; C-k
   * Select all; C-x h
   * Go to line
   * Fixed places for StatusTexts
 * Local history
 
 
-* Open Type; C-T
-
-
 * Compound statements and auto-completion
   Completions for for-loop, except, lambda and with variables
 
 * reST outlines
 
 
-* Code contexts; context_finder.get_context(text, offset)
-  This can be used when proposing code assists.
-
-
-* Rename function parameters
-
-
 * Static type inference
 
 
-* Auto-completing function parameter names when calling
-
-
-* Formating Code
-
-
 * Enhancing editor
 
   * Clearing selection if something happens
     is active do the builtin cut and paste
 
 
+* Auto-completing function parameter names when calling
+
+
+* Code contexts; context_finder.get_context(text, offset)
+  This can be used when proposing code assists.
+
+
+* Formating Code
+
+
 * What to do when the program has syntax errors for code assists
 
 
 * Move a module or package to another package
 
 
+* Move a class/function to another module
+
+
 * Inline method
 
 
-* Move a class/function to another module
+* Encapsulate method
 
 
-* Renaming attributes in a hierarchy
+* Introduce redirection
+
+
+* Introduce factory method
+
+
+* Change method signature
+
+
+* Rename function parameters
+
+
+* Open Type; C-T
 
 
 * Analyzing function decorators
 * Subversion support using pysvn
 
 
+* Renaming attributes in a hierarchy
+
+
 * Dynamic type inference using Cartesian algorithm
 
 
 * Enhancing module running
 
   * Showing running status in the GUI
-  * Printing output somewhere
-  * Getting input from somewhere
+  * Printing output
+  * Getting input
   * Customizing CWD and parameters
   * Running last run
 
 
 Remaining Stories
 -----------------
+
 * Migrating to sourceforge SVN before 0.3 release
   SF repository; How to synchronize local SVN with SF SVN?
 * Change program goals and description; principles.txt

File docs/workingon.txt

 Dynamic OI Small Enhancements
 =============================
 
+- Handle ``a_func()()``
+
 * Calling `sys.settrace` for all threads in `rope.runmod` module
-* Handle ``a_func()()``
 
 
 Before 0.3m2 Release
 * Do something for modules that can not be found
 * Dotted not found modules
 * GUI testing redux; make a functests directory?; rename ropetest to unittests?
-

File rope/codeanalyze.py

         return current_offset - 1
 
     def _find_last_non_space_char(self, offset):
+        if offset <= 0:
+            return 0
         current_offset = offset
         while current_offset >= 0 and self.source_code[current_offset] in ' \t\n':
             while current_offset >= 0 and self.source_code[current_offset] in ' \t':
         if self.source_code[offset].isalnum() or self.source_code[offset] == '_':
             return self._find_word_start(offset)
         return old_offset
+    
+    def _find_primary_without_dot_start(self, offset):
+        last_parens = offset
+        current_offset = self._find_last_non_space_char(offset)
+        while current_offset > 0 and self.source_code[current_offset] in ')]}':
+            last_parens = current_offset = self._find_parens_start(current_offset)
+            current_offset = self._find_last_non_space_char(current_offset - 1)
+
+        if current_offset > 0 and self.source_code[current_offset] in '\'"':
+            return self._find_string_start(current_offset)
+        elif current_offset > 0 and (self.source_code[current_offset].isalnum() or \
+                                     self.source_code[current_offset] == '_'):
+            return self._find_word_start(current_offset)
+        return last_parens
 
     def _find_primary_start(self, offset):
         current_offset = offset + 1
         if self.source_code[offset] != '.':
-            current_offset = self._find_atom_start(offset)
+            current_offset = self._find_primary_without_dot_start(offset)
         while current_offset > 0 and \
               self.source_code[self._find_last_non_space_char(current_offset - 1)] == '.':
             dot_position = self._find_last_non_space_char(current_offset - 1)
-            current_offset = self._find_last_non_space_char(dot_position - 1)
+            current_offset = self._find_primary_without_dot_start(dot_position - 1)
+            
+            first_char = self.source_code[current_offset]
+            if first_char != '_' and not first_char.isalnum():
+                break
 
-            if self.source_code[current_offset].isalnum() or \
-               self.source_code[current_offset] == '_':
-                current_offset = self._find_word_start(current_offset)
-            elif self.source_code[current_offset] in '\'"':
-                current_offset = self._find_string_start(current_offset)
-            elif self.source_code[current_offset] in ')]}':
-                current_offset = self._find_parens_start(current_offset)
-                if current_offset == 0:
-                    break
-                current_offset = self._find_last_non_space_char(current_offset - 1)
-                if self.source_code[current_offset].isalnum() or \
-                   self.source_code[current_offset] == '_':
-                    current_offset = self._find_word_start(current_offset)
-                else:
-                    break
         return current_offset
     
     def get_primary_at(self, offset):

File rope/runmod.py

                     pass
         
         def _is_an_interesting_call(self, frame):
-            if not frame.f_back or \
-               not os.path.abspath(inspect.getsourcefile(frame.f_back)).startswith(self.project_root):
+            if not self._is_code_inside_project(frame.f_code) and \
+               (not frame.f_back or not self._is_code_inside_project(frame.f_back)):
                 return False
             if frame.f_code.co_name in ['?', '<module>']:
                 return False
             return True
+        
+        def _is_code_inside_project(self, code):
+            return os.path.abspath(inspect.getsourcefile(code)).startswith(self.project_root)
     
         def _get_persisted_code(self, object_):
             return ('function', os.path.abspath(object_.co_filename), object_.co_firstlineno)

File ropetest/codeanalyzetest.py

         self.assertEquals('print {1: "one", 2: "two"}.keys',
                           word_finder.get_primary_at(29))
 
+    def test_following_parens(self):
+        code = 'a_var = a_func()()'
+        word_finder = WordRangeFinder(code)
+        self.assertEquals('a_func()()',
+                          word_finder.get_primary_at(code.index(')(') + 3))
+
     # TODO: eliminating comments
     def xxx_test_comments_for_finding_statements(self):
         word_finder = WordRangeFinder('# var2 . \n  var3')