Anonymous avatar Anonymous committed dc38fbb Draft

autoimport: added rope-complete-and-import

Comments (0)

Files changed (2)

ropemacs/interface.py

         lisp.delete_region(starting_offset + 1, offset + 1)
         lisp.insert(result)
 
-    @rawprefixed
-    def auto_import(self, prefix):
+    @interactive
+    def auto_import(self):
         self._check_project()
         if self.autoimport is None:
             return
             if len(modules) == 1:
                 module = modules[0]
             else:
-                module = lisputils.ask_values('Which module to import: ',
-                                              modules)
-            current = lisp.point()
-            lisp.goto_char(0)
-            newimport = 'from %s import %s\n' % (module, name)
-            lisp.insert(newimport)
-            lisp.goto_char(current + len(newimport))
+                module = lisputils.ask_values(
+                    'Which module to import: ', modules)
+            self._insert_import(name, module)
         else:
             lisputils.message('Not found!')
 
+    @interactive
+    def complete_and_import(self):
+        self._check_project()
+        if self.autoimport is None:
+            return
+        starting = lisp.current_word()
+        proposals = [x[0] + ' : ' + x[1]
+                     for x in self.autoimport.import_assist(starting)]
+        if proposals:
+            if len(proposals) == 1:
+                proposal = proposals[0]
+            else:
+                proposal = lisputils.ask_values('Which to import: ',
+                                                proposals)
+            name, module = proposal.rsplit(' :', 1)
+            lisp.insert(name[len(starting):])
+            self._insert_import(name, module)
+        else:
+            lisputils.message('Not found!')
+
+    def _insert_import(self, name, module):
+        current = lisp.point()
+        lisp.goto_char(0)
+        newimport = 'from %s import %s\n' % (module, name)
+        lisp.insert(newimport)
+        lisp.goto_char(current + len(newimport))
+
     def _calculate_proposals(self):
         self._check_project()
         resource, offset = self._get_location()
             self.project.validate(self.project.root)
 
     def _reload_buffers(self, changes, undo=False):
-        self._reload_buffers_for_changes(changes.get_changed_resources(),
-                             self._get_moved_resources(changes, undo))
+        self._reload_buffers_for_changes(
+            changes.get_changed_resources(),
+            self._get_moved_resources(changes, undo))
 
     def _reload_buffers_for_changes(self, changed_resources,
                                     moved_resources={}):
             if buffer:
                 if resource.exists():
                     lisp.set_buffer(buffer)
-                    lisp.revert_buffer(None, 1)
+                    lisp.revert_buffer(False, True)
                 elif resource in moved_resources:
                     new_resource = moved_resources[resource]
                     lisp.kill_buffer(buffer)

ropemacs/refactor.py

 import rope.contrib.generate
 import rope.refactor.extract
 import rope.refactor.inline
+import rope.refactor.method_object
 import rope.refactor.move
 import rope.refactor.rename
 import rope.refactor.restructure
 import rope.refactor.usefunction
-import rope.refactor.method_object
 
 from ropemacs import dialog, lisputils
 
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.