Anonymous avatar Anonymous committed ccce3fc

Added code completion

Comments (0)

Files changed (3)

ropemacs/__init__.py

             ('C-c r 1 v', lisp.rope_move_current_module),
             ('C-c r 1 p', lisp.rope_module_to_package),
 
+            ('C-c x', lisp.rope_code_assist),
             ('C-c g', lisp.rope_goto_definition),
             ('C-c C-d', lisp.rope_show_doc),
             ('C-c i o', lisp.rope_organize_imports)]
             lisp.insert(docs)
             lisp.display_buffer(pydoc_buffer)
 
+    @interactive()
+    def code_assist(self):
+        self._check_project()
+        resource, offset = self._get_location()
+        source = lisp.buffer_string()
+        proposals = codeassist.code_assist(self.project, source,
+                                           offset, resource)
+        proposals = codeassist.sorted_proposals(proposals)
+        starting_offset = codeassist.starting_offset(source, offset)
+        names = [proposal.name for proposal in proposals]
+        starting = source[starting_offset:offset]
+        prompt = 'Completion for %s: ' % starting
+        result = lisp.completing_read(prompt, names, None, None, starting)
+        lisp.delete_region(starting_offset + 1, offset + 1)
+        lisp.insert(result)
+
     def _get_location(self):
         resource = self._get_resource()
         offset = self._get_offset()
         if hasattr(attr, 'interaction') or hasattr(attr, 'lisp'):
             globals()[attrname] = attr
 
+
+class _LispAskConfig(object):
+
+    def __call__(self, conf):
+        if conf.values:
+            return lisp.completing_read(
+                conf.prompt, conf.values, None, True)
+        else:
+            return lisp.read_from_minibuffer(conf.prompt)
+
+
 def _ask(prompt, default=None):
-    return lisp.read_from_minibuffer(prompt, None, None, None,
-                                     None, default)
+    return lisp.read_from_minibuffer(prompt, default, None, None,
+                                     None, default, None)
 
 interface = RopeInterface()
 _register_functions(interface)

ropemacs/config.py

 class Config(object):
 
-    def __init__(self, name):
+    def __init__(self, name, prompt=None, values=None):
         self.name = name
+        self.prompt = prompt
+        self.values = values
 
 
-def ask(confs, minibuffer):
+def ask(confs, askconfig):
     result = {}
     for conf in confs:
-        result[conf.name] = minibuffer(conf.name)
+        result[conf.name] = askconfig(conf)
     return result
         super(ConfigTest, self).tearDown()
 
     def test_trivial_case(self):
-        config.ask([], MiniBuffer())
+        config.ask([], _MockAskConfig())
 
     def test_asking_normal_configs(self):
         confs = [config.Config('name')]
-        minibuffer = MiniBuffer(['value'])
+        minibuffer = _MockAskConfig(['value'])
         result = config.ask(confs, minibuffer)
         self.assertEquals(['name'], minibuffer.asked)
         self.assertEquals({'name': 'value'}, result)
 
 
-class MiniBuffer(object):
+class _MockAskConfig(object):
 
     def __init__(self, responses=[]):
         self.responses = responses
         self.asked = []
 
-    def __call__(self, message):
-        self.asked.append(message)
+    def __call__(self, config):
+        self.asked.append(config.name)
         return self.responses[len(self.asked) - 1]
 
 
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.