Commits

Anonymous committed 886e651

Auto-completing import mod and import mod as name

  • Participants
  • Parent commits 9b17814

Comments (0)

Files changed (10)

+- Show searching status in the status bar : May 18, 2006
+
+
 - Auto-complete class and function names : May 16, 2006
 
 
   * C-s C-s should start the last search
   * Search history; BackSpace should go back to the matches found before
   * Starting from begining when end of file is reached
+  * Showing failed searches
 
 
 * Enhancing module running @ 2
   * Implicit line joining: Indenting lines whose previous line contains a ([{'''
   * Indenting a range of file
   * Removing extra spaces
+  * Correcting indentation sends the cursor to the last character of an empty line
 
 
 * Rename local variable @ 2
 * Writing ASTs @ 4
 
 
-* Auto-complete imported objects @ 3
+* Auto-complete imported objects @ 2
 
 
 * Proposing templates in auto-completion proposals @ 2
 > Public release 0.2pre : May 20, 2006
 
 
-* Show searching status in the status bar @ 2
+* Auto-complete imported objects @ 1
 
 
 --- Remaining Stories ---

docs/workingon.txt

-*** Show searching status in the status bar @ 2 ***
+*** Auto-complete imported objects @ 1 ***
 
-- Removing status kind
-- Return what when status kind does not exist
-- Setting width for status texts
-- Showing status while searching
-- Separate module for StatusBarManager
-- create_status, get_status
-- What if the editor goes out of focus while searching
+- import name
+- import name as name
 
-* Extract listbox; duplicates in editor and core
-    ? uihelpers module
+* from mod import name
+* from mod import name as name
+* from mod import *
+
 ? Separating ui modules and packages
-  ? Decide which modules are the domain and which are the presentation
-  ? Should editing tools access Editor directly? Which of them?
+    ? Decide which modules are the domain and which are the presentation
+    ? Should editing tools access Editor directly? Which of them?
 ? Specifing the type of each story; UI or Core
-
 ? The connection between ASTs and Type Hierarchies
 * Better font selection on windows
 ? Think about a library for functional testing

rope/codeassist.py

         self.starting = starting
         self.result = {}
 
+    def visitImport(self, node):
+        for import_pair in node.names:
+            name, alias = import_pair
+            imported = name
+            if alias is not None:
+                imported = alias
+            if imported.startswith(self.starting):
+                self.result[imported] = CompletionProposal(imported, 'module')
+
     def visitAssName(self, node):
         if node.name.startswith(self.starting):
             self.result[node.name] = CompletionProposal(node.name, 'global_variable')
     def delete(self, start=None, end=None):
         pass
 
-    def nextWord(self):
+    def next_word(self):
         pass
 
-    def prevWord(self):
+    def prev_word(self):
         pass
 
-    def deleteNextWord(self):
+    def delete_next_word(self):
         pass
 
-    def deletePrevWord(self):
+    def delete_prev_word(self):
         pass
 
-    def goToTheStart(self):
+    def goto_start(self):
         pass
 
-    def goToTheEnd(self):
+    def goto_end(self):
         pass
 
     def set_highlighting(self, highlighting):
             self.text.tag_add(kind, start._getIndex(), end._getIndex())
 
     def _bind_keys(self):
-        self.text.bind('<Alt-f>', lambda event: self.nextWord())
-        self.text.bind('<Alt-b>', lambda event: self.prevWord())
-        self.text.bind('<Alt-d>', lambda event: self.deleteNextWord())
-        def deletePrevWordListener(event):
-            self.deletePrevWord()
+        self.text.bind('<Alt-f>', lambda event: self.next_word())
+        self.text.bind('<Alt-b>', lambda event: self.prev_word())
+        self.text.bind('<Alt-d>', lambda event: self.delete_next_word())
+        def delete_prev_wordListener(event):
+            self.delete_prev_word()
             return 'break'
-        self.text.bind('<Alt-BackSpace>', deletePrevWordListener)
-        def doUndo(event):
+        self.text.bind('<Alt-BackSpace>', delete_prev_wordListener)
+        def do_undo(event):
             self.undo()
             return 'break'
-        def doRedo(event):
+        def do_redo(event):
             self.redo()
             return 'break'
-        self.text.bind('<Control-x><u>', doUndo)
-        self.text.bind('<Control-x><r>', doRedo)
-        def doGoToTheStart(event):
-            self.goToTheStart()
+        self.text.bind('<Control-x><u>', do_undo)
+        self.text.bind('<Control-x><r>', do_redo)
+        def do_goto_start(event):
+            self.goto_start()
             self.text.see(INSERT)
-        def doGoToTheEnd(event):
-            self.goToTheEnd()
+        def do_goto_end(event):
+            self.goto_end()
             self.text.see(INSERT)
-        self.text.bind('<Alt-less>', doGoToTheStart)
-        self.text.bind('<Alt-KeyPress->>', doGoToTheEnd)
-        def doSetMark(event):
-            self.setMark()
+        self.text.bind('<Alt-less>', do_goto_start)
+        self.text.bind('<Alt-KeyPress->>', do_goto_end)
+        def do_set_mark(event):
+            self.set_mark()
             return 'break'
-        self.text.bind('<Control-space>', doSetMark)
-        def doCopy(event):
-            self.copyRegion()
+        self.text.bind('<Control-space>', do_set_mark)
+        def do_copy(event):
+            self.copy_region()
             return 'break'
-        self.text.bind('<Alt-w>', doCopy)
-        def doCut(event):
-            self.cutRegion()
+        self.text.bind('<Alt-w>', do_copy)
+        def do_cut(event):
+            self.cut_region()
             return 'break'
-        self.text.bind('<Control-w>', doCut)
-        def doPaste(event):
+        self.text.bind('<Control-w>', do_cut)
+        def do_paste(event):
             self.paste()
             return 'break'
-        self.text.bind('<Control-y>', doPaste)
+        self.text.bind('<Control-y>', do_paste)
         def escape(event):
-            self.clearMark()
+            self.clear_mark()
             if self.get_searcher().is_searching():
                 self.get_searcher().cancel_searching()
         self.text.bind('<Control-g>', escape)
+        self.text.bind('<Escape>', escape)
         def do_swap_mark_and_insert(event):
-            self.swapMarkAndInsert()
+            self.swap_mark_and_insert()
             return 'break'
         self.text.bind('<Control-x><Control-x>', do_swap_mark_and_insert)
-        def goNextPage(event):
-            self.nextPage()
+        def go_next_page(event):
+            self.next_page()
             return 'break'
-        self.text.bind('<Control-v>', goNextPage)
-        def goPrevPage(event):
-            self.prevPage()
+        self.text.bind('<Control-v>', go_next_page)
+        def go_prev_page(event):
+            self.prev_page()
             return 'break'
-        self.text.bind('<Alt-v>', goPrevPage)
+        self.text.bind('<Alt-v>', go_prev_page)
         def indent_line(event):
             self.indenter.correct_indentation(self.get_insert())
             return 'break'
-        def doInsertTab(event):
+        def do_insert_tab(event):
             self.insert_tab()
             return 'break'
         self.text.bind('<Control-i>', indent_line)
-        self.text.bind('<Tab>', doInsertTab)
+        self.text.bind('<Tab>', do_insert_tab)
         def return_handler(event):
             if self.searcher.is_searching():
                 self.searcher.end_searching()
             result = str(self.text.index(result + '+1c'))
         return result + ' wordend'
 
-    def nextWord(self):
+    def next_word(self):
         self.text.mark_set(INSERT, self._get_next_word_index())
         self.text.see(INSERT)
 
             result = str(self.text.index(result + '-1c'))
         return result + '-1c wordstart'
 
-    def prevWord(self):
+    def prev_word(self):
         self.text.mark_set(INSERT, self._get_prev_word_index())
         self.text.see(INSERT)
 
-    def deleteNextWord(self):
+    def delete_next_word(self):
         self.text.delete(INSERT, self._get_next_word_index())
 
-    def deletePrevWord(self):
+    def delete_prev_word(self):
         self.text.delete(self._get_prev_word_index(), INSERT)
 
     def getWidget(self):
         except TclError:
             pass
 
-    def goToTheStart(self):
+    def goto_start(self):
         self.set_insert(self.get_start())
     
-    def goToTheEnd(self):
+    def goto_end(self):
         self.set_insert(self.get_end())
 
     def generate_event(self, event):
         self.text.event_generate(event)
 
-    def setMark(self):
+    def set_mark(self):
         self.text.mark_set('mark', INSERT)
 
-    def clearMark(self):
+    def clear_mark(self):
         self.text.mark_unset('mark')
 
-    def _selectRegion(self):
+    def _select_region(self):
         start = 'mark'
         end = INSERT
         if self.text.compare(start, '>', end):
             start, end = end, start
         self.text.tag_add(SEL, start, end)
 
-    def copyRegion(self):
+    def copy_region(self):
         try:
-            self._selectRegion()
+            self._select_region()
             self.text.event_generate('<<Copy>>')
             self.text.tag_remove(SEL, '1.0', END)
         except TclError:
             pass
 
-    def cutRegion(self):
+    def cut_region(self):
         try:
-            self._selectRegion()
+            self._select_region()
             self.text.event_generate('<<Cut>>')
             self.text.see(INSERT)
         except TclError:
         self.text.event_generate('<<Paste>>')
         self.text.see(INSERT)
 
-    def swapMarkAndInsert(self):
+    def swap_mark_and_insert(self):
         try:
             mark = self.text.index('mark')
-            self.setMark()
+            self.set_mark()
             self.text.mark_set(INSERT, mark)
         except TclError:
             pass
 
-    def nextPage(self):
+    def next_page(self):
         self.text.event_generate('<Next>')
 
-    def prevPage(self):
+    def prev_page(self):
         self.text.event_generate('<Prior>')
 
     def insert_tab(self, text_index = None):

ropetest/codeassisttest.py

         self.assertEquals(len(code) - 2, result.start_offset)
         self.assertEquals(len(code), result.end_offset)
 
+    def test_completing_imported_names(self):
+        code = 'import sys\na = sy'
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('sys', 'module', result)
+
+    def test_completing_imported_names_with_as(self):
+        code = 'import sys as mysys\na = mys'
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_in_result('mysys', 'module', result)
+
+    def test_not_completing_imported_names_with_as(self):
+        code = 'import sys as mysys\na = sy'
+        result = self.assist.complete_code(code, len(code))
+        self.assert_proposal_not_in_result('sys', 'module', result)
+
+        
 
 if __name__ == '__main__':
     unittest.main()

ropetest/editortest.py

         self.editor.redo()
 
     def test_copying(self):
-        self.editor.setMark()
-        self.editor.goToTheEnd()
-        self.editor.copyRegion()
+        self.editor.set_mark()
+        self.editor.goto_end()
+        self.editor.copy_region()
         self.editor.paste()
         self.assertEquals('sample textsample text', self.editor.get_text())
 
     def test_copying_in_the_middle(self):
-        self.editor.nextWord()
-        self.editor.setMark()
-        self.editor.goToTheEnd()
-        self.editor.copyRegion()
-        self.editor.goToTheStart()
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_end()
+        self.editor.copy_region()
+        self.editor.goto_start()
         self.editor.paste()
         self.assertEquals(' textsample text', self.editor.get_text())
 
     def test_cutting(self):
-        self.editor.setMark()
-        self.editor.nextWord()
-        self.editor.cutRegion()
+        self.editor.set_mark()
+        self.editor.next_word()
+        self.editor.cut_region()
         self.assertEquals(' text', self.editor.get_text())
         self.editor.paste()
         self.assertEquals('sample text', self.editor.get_text())
 
     def test_mark_not_set(self):
-        self.editor.cutRegion()
-        self.editor.copyRegion()
+        self.editor.cut_region()
+        self.editor.copy_region()
         self.assertEquals('sample text', self.editor.get_text())
 
     def test_clear_mark(self):
-        self.editor.setMark()
-        self.editor.nextWord()
-        self.editor.clearMark()
-        self.editor.cutRegion()
+        self.editor.set_mark()
+        self.editor.next_word()
+        self.editor.clear_mark()
+        self.editor.cut_region()
         self.assertEquals('sample text', self.editor.get_text())
 
     def test_when_insert_while_mark_precedes(self):
-        self.editor.nextWord()
-        self.editor.setMark()
-        self.editor.goToTheStart()
-        self.editor.cutRegion()
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_start()
+        self.editor.cut_region()
         self.assertEquals(' text', self.editor.get_text())
 
     def test_swap_mark_and_insert(self):
-        self.editor.setMark()
-        self.editor.nextWord()
-        self.editor.swapMarkAndInsert()
+        self.editor.set_mark()
+        self.editor.next_word()
+        self.editor.swap_mark_and_insert()
         self.assertEquals(self.editor.get_start(), self.editor.get_insert())
-        self.editor.cutRegion()
+        self.editor.cut_region()
         self.assertEquals(' text', self.editor.get_text())
 
     def test_no_mark_swap_mark_and_insert(self):
-        self.editor.swapMarkAndInsert()
+        self.editor.swap_mark_and_insert()
         self.assertEquals('sample text', self.editor.get_text())
 
     def test_swap_mark_and_insert_while_insert_precedes(self):
-        self.editor.nextWord()
-        self.editor.setMark()
-        self.editor.goToTheStart()
-        self.editor.swapMarkAndInsert()
+        self.editor.next_word()
+        self.editor.set_mark()
+        self.editor.goto_start()
+        self.editor.swap_mark_and_insert()
         self.assertEquals(self.editor.get_index(6), self.editor.get_insert())
-        self.editor.cutRegion()
+        self.editor.cut_region()
         self.assertEquals(' text', self.editor.get_text())
 
     def test_insert_tab(self):

ropetest/mockeditor.py

                 break
         return current
 
-    def nextWord(self):
+    def next_word(self):
         self.insertIndex = MockTextIndex(self, self._getNextWordIndex())
 
-    def deleteNextWord(self):
+    def delete_next_word(self):
         self.content = self.content[0 : self.insertIndex._getIndex()] + \
                        self.content[self._getNextWordIndex() :]
 
             current -= 1
         return current
 
-    def prevWord(self):
+    def prev_word(self):
         self.insertIndex = MockTextIndex(self, self._getPrevWordIndex())
 
-    def deletePrevWord(self):
+    def delete_prev_word(self):
         self.content = self.content[0 : self._getPrevWordIndex()] + \
                        self.content[self.insertIndex._getIndex() :]
 
-    def goToTheStart(self):
+    def goto_start(self):
         self.set_insert(self.get_start())
 
-    def goToTheEnd(self):
+    def goto_end(self):
         self.set_insert(self.get_end())
 
     def set_highlighting(self, highlighting):

ropetest/mockeditortest.py

         self.assertEquals('sample textanother piece of text', self.editor.get_text())
 
     def testMoveNextWord(self):
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals(' ', self.editor.get(), 'Expected <%c> but was <%c>' % (' ', self.editor.get()))
 
     def testMoveNextWordOnSpaces(self):
-        self.editor.nextWord()
+        self.editor.next_word()
         self.editor.insert(self.editor.get_end(), ' and\n')
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals(' ', self.editor.get())
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals('\n', self.editor.get())
 
     def testNextWordOnEnd(self):
         self.editor.set_insert(self.editor.get_end())
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals(self.editor.get_end(), self.editor.get_insert())
 
     def testNextWordOnNewLine(self):
         self.editor.set_insert(self.editor.get_relative(self.editor.get_end(), -1))
         self.editor.insert(self.editor.get_end(), '\non a new line')
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals('\n', self.editor.get())
 
     def testNextWordOnNewLine(self):
         self.editor.set_text('hello \n world\n')
-        self.editor.nextWord()
-        self.editor.nextWord()
+        self.editor.next_word()
+        self.editor.next_word()
         self.assertEquals('\n', self.editor.get(), self.editor.get())
 
     def testNextOneCharacterWord(self):
         self.editor.set_text('1 2\n')
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals(' ', self.editor.get())
-        self.editor.nextWord()
+        self.editor.next_word()
         self.assertEquals('\n', self.editor.get())
 
     def testPrevWordOnTheBegining(self):
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('s', self.editor.get())
 
     def testPrevWord(self):
         self.editor.set_insert(self.editor.get_end())
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('t', self.editor.get())
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('s', self.editor.get())
 
     def testPrevWordOnTheMiddleOfAWord(self):
         self.editor.set_insert(self.editor.get_relative(self.editor.get_end(), -2))
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('t', self.editor.get())
 
     def testPrevOneCharacterWord(self):
         self.editor.set_text('1 2 3')
         self.editor.set_insert(self.editor.get_end())
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('3', self.editor.get())
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('2', self.editor.get())
-        self.editor.prevWord()
+        self.editor.prev_word()
         self.assertEquals('1', self.editor.get())
 
     def testDeletingNextWord(self):
-        self.editor.deleteNextWord()
+        self.editor.delete_next_word()
         self.assertEquals(' text', self.editor.get_text())
 
     def testDeletingNextWordInTheMiddle(self):
         self.editor.set_insert(self.editor.get_index(2))
-        self.editor.deleteNextWord()
+        self.editor.delete_next_word()
         self.assertEquals('sa text', self.editor.get_text())
 
     def testDeletingPrevWord(self):
         self.editor.set_insert(self.editor.get_end())
-        self.editor.deletePrevWord()
+        self.editor.delete_prev_word()
         self.assertEquals('sample ', self.editor.get_text(), self.editor.get_text())
 
     def testDeletingPrevWordInTheMiddle(self):
         self.editor.set_insert(self.editor.get_relative(self.editor.get_end(), -2))
-        self.editor.deletePrevWord()
+        self.editor.delete_prev_word()
         self.assertEquals('sample xt', self.editor.get_text(), self.editor.get_text())
 
     def testDeletingPrevWordAtTheBeginning(self):
         self.editor.set_insert(self.editor.get_index(3))
-        self.editor.deletePrevWord()
+        self.editor.delete_prev_word()
         self.assertEquals('ple text', self.editor.get_text(), self.editor.get_text())
 
     def testGoingToTheStart(self):
         self.editor.set_insert(self.editor.get_index(3))
-        self.editor.goToTheStart()
+        self.editor.goto_start()
         self.assertEquals(self.editor.get_start(), self.editor.get_insert())
 
     def testGoingToTheStart(self):
         self.editor.set_insert(self.editor.get_index(3))
-        self.editor.goToTheEnd()
+        self.editor.goto_end()
         self.assertEquals(self.editor.get_end(), self.editor.get_insert())
 
     def test_searching(self):

ropetest/searchingtest.py

 import unittest
 
+from rope.statusbar import StatusBarException
 from rope.searching import Searcher
 from ropetest.mockeditortest import GraphicalEditorFactory, MockEditorFactory
 
 
     def test_searching_status_bar(self):
         self.editor.status_bar_manager = PlaceholderStatusBarManager()
-        # TODO: finish
+        manager = self.editor.status_bar_manager
+        try:
+            manager.get_status('search')
+            self.fail('Should have failed')
+        except StatusBarException:
+            pass
+        self.searcher.start_searching()
+        status = manager.get_status('search')
+        self.searcher.end_searching()
+        try:
+            manager.get_status('search')
+            self.fail('Should have failed')
+        except StatusBarException:
+            pass
 
 
 class PlaceholderStatusBarManager(object):
+    def __init__(self):
+        self.status_text = {}
+        
     def get_status(self, kind):
         if not self.status_text.has_key(kind):
-            self.status_text[kind] = StatusText(self, kind, label)
-            self.status_text[kind].set_text('')
+            raise StatusBarException('StatusText <%s> does not exist' % kind)
         return self.status_text[kind]
 
+    def create_status(self, kind):
+        if self.status_text.has_key(kind):
+            raise StatusBarException('StatusText <%s> already exists' % kind)
+        self.status_text[kind] = PlaceholderStatusText(self, kind)
+        self.status_text[kind].set_text('')
+        return self.status_text[kind]
+
+
     def remove_status(self, status):
         del self.status_text[status.kind]