Anonymous avatar Anonymous committed 4f81f32

codeanalyze: ignoring comments when finding primaries

Comments (0)

Files changed (2)

rope/base/codeanalyze.py

             offset += 1;
         return offset
 
+    _char_pat = re.compile(r'[\'"#\n]')
     def _find_last_non_space_char(self, offset):
         if offset <= 0:
             return 0
-        while offset >= 0 and self.source[offset] in ' \t\n':
-            if self.source[offset - 1:offset + 1] == '\\\n':
-                offset -= 1
+        while offset >= 0 and self.source[offset].isspace():
+            if self.source[offset] == '\n':
+                if offset > 0 and self.source[offset - 1] == '\\':
+                    offset -= 1
+                try:
+                    start = self.source.rindex('\n', 0, offset)
+                except ValueError:
+                    start = 0
+
+                match = self._char_pat.search(self.source[start:offset][::-1])
+                if match and match.group() == '#':
+                    offset = self.source.rindex('#', 0, offset)
             offset -= 1
         return offset
 

ropetest/codeanalyzetest.py

         result = self._find_primary(code, code.index(')(') + 3)
         self.assertEquals('a_func()()', result)
 
-    # XXX: eliminating comments
-    def xxx_test_comments_for_finding_statements(self):
+    def test_comments_for_finding_statements(self):
         code = '# var2 . \n  var3'
         self.assertEquals('var3', self._find_primary(code, 14))
 
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.