[gnome-builder: 5/7] jedi: use IdeSourceSnippet for jedi completions



commit b3a83e7bd62f3a3f738c070ec25cce18c4b3cd61
Author: Christian Hergert <christian hergert me>
Date:   Mon Aug 24 16:36:23 2015 -0700

    jedi: use IdeSourceSnippet for jedi completions
    
    This allows us to complete functions with the function names as tab stops.
    We still need to improve the GObject Introspection so that function calls
    actually appear as "function".
    
    Functions, (at least those defined in python for now), will be expanded
    like:
    
      self.foo(a, b, c)
    
    and you can tab through a, b, and c. A final tab will land you after the
    trailing ).

 plugins/jedi/jedi_plugin.py |   59 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/plugins/jedi/jedi_plugin.py b/plugins/jedi/jedi_plugin.py
index f4bcfac..91b2205 100644
--- a/plugins/jedi/jedi_plugin.py
+++ b/plugins/jedi/jedi_plugin.py
@@ -168,8 +168,63 @@ class JediCompletionProvider(Ide.Object,
         _, iter = context.get_iter()
         return True, iter
 
-    def do_activate_proposal(self, provider, proposal):
-        return False, None
+    def do_activate_proposal(self, proposal, location):
+        # Use snippets to push the replacement text and/or parameters with
+        # tab stops.
+        snippet = Ide.SourceSnippet()
+
+        chunk = Ide.SourceSnippetChunk()
+        chunk.set_text(proposal.completion.complete)
+        chunk.set_text_set(True)
+        snippet.add_chunk(chunk)
+
+        # Add parameter completion for functions.
+        if proposal.completion.type == 'function':
+            chunk = Ide.SourceSnippetChunk()
+            chunk.set_text('(')
+            chunk.set_text_set(True)
+            snippet.add_chunk(chunk)
+
+            params = proposal.completion.params
+
+            if not params:
+                chunk = Ide.SourceSnippetChunk()
+                chunk.set_text('')
+                chunk.set_text_set(True)
+                chunk.set_tab_stop(0)
+                snippet.add_chunk(chunk)
+            else:
+                tab_stop = 0
+
+                for param in params[:-1]:
+                    tab_stop += 1
+                    chunk = Ide.SourceSnippetChunk()
+                    chunk.set_text(param.name)
+                    chunk.set_text_set(True)
+                    chunk.set_tab_stop(tab_stop)
+                    snippet.add_chunk(chunk)
+
+                    chunk = Ide.SourceSnippetChunk()
+                    chunk.set_text(', ')
+                    chunk.set_text_set(True)
+                    snippet.add_chunk(chunk)
+
+                tab_stop += 1
+                chunk = Ide.SourceSnippetChunk()
+                chunk.set_text(params[-1].name)
+                chunk.set_text_set(True)
+                chunk.set_tab_stop(tab_stop)
+                snippet.add_chunk(chunk)
+
+            chunk = Ide.SourceSnippetChunk()
+            chunk.set_text(')')
+            chunk.set_text_set(True)
+            snippet.add_chunk(chunk)
+
+        view = proposal.context.props.completion.props.view
+        view.push_snippet(snippet)
+
+        return True, None
 
     def do_get_interactive_delay(self):
         return -1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]