Anonymous avatar Anonymous committed 215ea81

Added rope.codeanalyze module

Comments (0)

Files changed (3)

docs/workingon.txt

 *** Ignoring string contents while indenting @ 1 ***
 
-- Adding LineOriented to the Editor class
+* Ignoring comment contents
+* Ignoring string contents
+? Use StatementRangeFinder
+- Add codeanalyze module
+- Adding LineEditor to the Editor class
 
+* Hold the list of project classes and import them automatically
+  in codeassist
 
 
 --- Before 0.2 Release ---

rope/codeassist.py

 import re
 
 from rope.exceptions import RopeException
+from rope.codeanalyze import StatementRangeFinder
 
 
 class RopeSyntaxError(RopeException):
         return Proposals()
 
 
-class _CurrentStatementRangeFinder(object):
-    """A method object for finding the range of current statement"""
-
-    def __init__(self, lines, lineno):
-        self.lines = lines
-        self.lineno = lineno
-        self.in_string = ''
-        self.open_parens = 0
-        self.explicit_continuation = False
-
-    def _analyze_line(self, current_line):
-        for i in range(len(current_line)):
-            char = current_line[i]
-            if char in '\'"':
-                if self.in_string == '':
-                    self.in_string = char
-                    if char * 3 == current_line[i:i + 3]:
-                        self.in_string = char * 3
-                elif self.in_string == current_line[i:i + len(self.in_string)] and \
-                     not (i > 0 and current_line[i - 1] == '\\' and
-                          not (i > 1 and current_line[i - 2:i] == '\\\\')):
-                    self.in_string = ''
-            if self.in_string != '':
-                continue
-            if char == '#':
-                break
-            if char in '([{':
-                self.open_parens += 1
-            if char in ')]}':
-                self.open_parens -= 1
-        if current_line.rstrip().endswith('\\'):
-            self.explicit_continuation = True
-        else:
-            self.explicit_continuation = False
-
-
-    def get_range(self):
-        last_statement = 0
-        for current_line_number in range(0, self.lineno + 1):
-            if not self.explicit_continuation and self.open_parens == 0 and self.in_string == '':
-                last_statement = current_line_number
-            current_line = self.lines[current_line_number]
-            self._analyze_line(current_line)
-        last_indents = self.get_line_indents(last_statement)
-        end_line = self.lineno
-        if True or self.lines[self.lineno].rstrip().endswith(':'):
-            for i in range(self.lineno + 1, len(self.lines)):
-                if self.get_line_indents(i) >= last_indents:
-                    end_line = i
-                else:
-                    break
-        return (last_statement, end_line)
-
-    def get_line_indents(self, line_number):
-        indents = 0
-        for char in self.lines[line_number]:
-            if char == ' ':
-                indents += 1
-            else:
-                break
-        return indents
-
 
 class CodeAssist(ICodeAssist):
     def __init__(self, project):
         return current_offset + 1
 
     def _comment_current_statement(self, lines, lineno):
-        range_finder = _CurrentStatementRangeFinder(lines, lineno)
+        range_finder = StatementRangeFinder(lines, lineno)
         start, end = range_finder.get_range()
         last_indents = range_finder.get_line_indents(start)
         lines[start] = last_indents * ' ' + 'pass'
                 self.searcher.end_searching()
                 return 'break'
             self.text.insert(INSERT, '\n')
-            self.indenter.correct_indentation(self.get_insert())
+            self.indenter.correct_indentation(self.get_current_line_number())
             self.text.see(INSERT)
             return 'break'
         def backspace(event):
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.