Anonymous avatar Anonymous committed dd71a05

Better lineno convention in codeassist

Comments (0)

Files changed (3)

rope/codeassist.py

         current_scope = visitor.scope
         current_indents = self._get_line_indents(lines, lineno)
         while current_scope is not None and \
-              self._get_line_indents(lines, current_scope.lineno) <= current_indents:
+              (current_scope == visitor.scope or
+               self._get_line_indents(lines, current_scope.lineno - 1) < current_indents):
             result.update(current_scope.var_dict)
             new_scope = None
             for scope in current_scope.children:
-                if scope.lineno < lineno + 1:
+                if scope.lineno - 1 <= lineno:
                     new_scope = scope
                 else:
                     break
             current_scope = new_scope
         return result
 
-    def _get_line_number(self, source_code, offset):
-        return source_code[:offset].count('\n') + 1
-
-    def _count_line_indents(self, source_code, offset):
-        last_non_space = offset - 1
-        current_pos = offset - 1
-        while current_pos >= 0 and source_code[current_pos] != '\n':
-            if source_code[current_pos] != ' ':
-                last_non_space = current_pos
-            current_pos -= 1
-        return (last_non_space - current_pos - 1) / self.indentation_length
-
     def add_template(self, name, definition):
         self.templates.append(TemplateProposal(name, Template(definition)))
 
         toplevel = Toplevel()
         toplevel.title('Completion Proposals')
         frame = Frame(toplevel)
-        label = Label(frame, text='Completion Proposals')
+        label = Label(frame, text='Code Assist Proposals')
         proposals = Listbox(frame, selectmode=SINGLE, width=23, height=7)
         scrollbar = Scrollbar(frame, orient=VERTICAL)
         scrollbar['command'] = proposals.yview
         proposals.config(yscrollcommand=scrollbar.set)
         for proposal in result.completions:
-            proposals.insert(END, proposal.name)
+            proposal_info = proposal.kind[0].upper() + '  ' + proposal.name
+            proposals.insert(END, proposal_info)
         if result:
             proposals.selection_set(0)
         self.text.see('insert')
                 self.text.delete('0.0 +%dc' % result.start_offset,
                                  '0.0 +%dc' % result.end_offset)
                 self.text.insert('0.0 +%dc' % result.start_offset,
-                                 result.completions[selected].completion)
+                                 result.completions[selected].name)
                 toplevel.destroy()
         def cancel():
             toplevel.destroy()

ropetest/codeassisttest.py

         result = self.assist.assist(code, len(code))
         self.assert_template_in_result('my_template', result)
 
+    def test_code_assist_when_having_a_two_line_function_header(self):
+        code = 'def f(param1,\n      param2):\n    para'
+        result = self.assist.assist(code, len(code))
+        self.assert_completion_in_result('param1', 'local_variable', result)
+
 
 class CodeAssistInProjectsTest(unittest.TestCase):
 
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.