Commits

Anonymous committed 649ab4e

Using logical lines for finding scope in codeassist

Comments (0)

Files changed (1)

rope/contrib/codeassist.py

         module_scope = _get_pymodule(self.pycore, source_code,
                                     self.resource).get_scope()
         result = {}
-        current_indents = _get_line_indents(lines[lineno - 1])
-        inner_scope = module_scope.get_inner_scope_for_line(lineno,
-                                                            current_indents)
+        indents = _get_line_indents(lines[_logical_start(lines, lineno) - 1])
+        inner_scope = module_scope.get_inner_scope_for_line(lineno, indents)
         if self.expression.strip() != '':
             result.update(self._get_dotted_completions(module_scope,
                                                        inner_scope))
         self.lines = lines
 
     def comment(self, lineno):
-        logical_finder = LogicalLineFinder(ArrayLinesAdapter(self.lines))
-        start = logical_finder.get_logical_line_in(lineno)[0] - 1
+        start = _logical_start(self.lines, lineno) - 1
         end = self._get_block_end(start)
         last_indents = _get_line_indents(self.lines[start])
         self.lines[start] = ' ' * last_indents + 'pass'
         for line in range(start + 1, end + 1):
-            #self.lines[line] = '#' # + lines[line]
             self.lines[line] = self.lines[start]
         self.lines.append('\n')
-        self._fix_incomplete_try_blocks(lineno)
+        self._fix_incomplete_try_blocks(lineno, last_indents)
 
     def _get_block_end(self, lineno):
         end_line = lineno
                 break
         return end_line
 
-    def _fix_incomplete_try_blocks(self, lineno):
+    def _fix_incomplete_try_blocks(self, lineno, indents):
         block_start = lineno
-        last_indents = current_indents = _get_line_indents(
-            self.lines[lineno - 1])
+        last_indents = current_indents = indents
         while block_start > 0:
             block_start = rope.base.codeanalyze.get_block_start(
                 ArrayLinesAdapter(self.lines), block_start) - 1
     return rope.base.codeanalyze.count_line_indents(line)
 
 
+def _logical_start(lines, lineno):
+    logical_finder = LogicalLineFinder(ArrayLinesAdapter(lines))
+    return logical_finder.get_logical_line_in(lineno)[0]
+
+
 class PyDocExtractor(object):
 
     def get_doc(self, pyobject):
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.