Anonymous avatar Anonymous committed c0bee46

Proposing global classes and functions

Comments (0)

Files changed (5)

docs/workingon.txt

 
 - Test only reporting only completions with the given starting
 - Showing completions in GraphicalEditor
+- Test not proposing local assigns as global proposals
+- Propose global classes and functions
 
 * Extract listbox; duplicates in editor and core
 ? Proposing a name at most once? Use dicts instead of lists
-* Test not proposing local assigns as global proposals
+* Complete as you type (updating proposal list while typing)
 * Test not proposing the variables in current line
 * What if current line has errors
+* Applying the completion
 ? The connection between ASTs and Type Hierarchies
 ? Should Projects have ContentAssist objects?
 

rope/codeassist.py

         if node.name.startswith(self.starting):
             self.result.append(CompletionProposal(node.name, 'global_variable'))
 
+    def visitFunction(self, node):
+        if node.name.startswith(self.starting):
+            self.result.append(CompletionProposal(node.name, 'function'))
+    
+    def visitClass(self, node):
+        if node.name.startswith(self.starting):
+            self.result.append(CompletionProposal(node.name, 'class'))
+
 
 class ICodeAssist(object):
     def complete_code(self, source, offset):
     def _show_completion_window(self):
         toplevel = Toplevel()
         frame = Frame(toplevel)
-        label = Label(frame, text='Hello World')
+        label = Label(frame, text='Completion Proposals')
         proposals = Listbox(frame, selectmode=SINGLE, width=23, height=7)
         scrollbar = Scrollbar(frame, orient=VERTICAL)
         scrollbar['command'] = proposals.yview
             return fromIndex + ('%dc' % count)
 
     def _get_line_from_index(self, index):
-        return int(self.text.index(index).split('.')[0])
+        return int(str(self.text.index(index)).split('.')[0])
 
     def _get_column_from_index(self, index):
-        return int(self.text.index(index).split('.')[1])
+        return int(str(self.text.index(index)).split('.')[1])
 
     def set_insert(self, textIndex):
         self.text.mark_set(INSERT, textIndex._getIndex())
         result = INSERT
         while self.text.compare(result, '!=', 'end-1c') and \
               not self.text.get(result)[0].isalnum():
-            result = self.text.index(result + '+1c')
+            result = str(self.text.index(result + '+1c'))
         return result + ' wordend'
 
     def nextWord(self):
         result = INSERT
         while not self.text.compare(result, '==', '1.0') and \
               not self.text.get(result + '-1c')[0].isalnum():
-            result = self.text.index(result + '-1c')
+            result = str(self.text.index(result + '-1c'))
         return result + '-1c wordstart'
 
     def prevWord(self):
         current_pos = '1.0 lineend'
         for x in range(current_line - 1):
             result += self._get_column_from_index(current_pos) + 1
-            current_pos = self.text.index(current_pos + ' +1l lineend')
+            current_pos = str(self.text.index(current_pos + ' +1l lineend'))
         return result
 
 
         return 0
 
     def _getIndex(self):
-        return self.index
+        return str(self.index)
 
     def __str__(self):
         return '<%s, %s>' % (self.__class__.__name__, self.index)

rope/highlight.py

         return {'keyword': HighlightingStyle(color='blue', bold=True),
                 'string' : HighlightingStyle(color='#004080'),
                 'comment' : HighlightingStyle(color='#008000', italic=True),
-                'builtin' : HighlightingStyle(color='pink'),
+                'builtin' : HighlightingStyle(color='#908080'),
                 'definition' : HighlightingStyle(color='purple', bold=True)}
 
     def highlights(self, start, end):

ropetest/codeassisttest.py

         result = self.assist.complete_code(code, len(code))
         self.assert_proposal_not_in_result('my_global', 'global_variable', result)
 
+    def test_not_proposing_local_assigns_as_global_completions(self):
+        code = 'def f():    my_global = 10\nt = my_'
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_not_in_result('my_global', 'global_variable', result)
+
+    def test_proposing_functions(self):
+        code = 'def my_func():    return 2\nt = my_'
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('my_func', 'function', result)
+
+    def test_proposing_classes(self):
+        code = 'class Sample(object):    pass\nt = Sam'
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('Sample', 'class', result)
+
 
 if __name__ == '__main__':
     unittest.main()
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.