[gnome-code-assistance/wip/completion: 16/17] [backens/pycommon] Add completion interface



commit 1dcefe060cb909517590d1290075c12c27a21f1c
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Jan 11 23:58:04 2015 +0100

    [backens/pycommon] Add completion interface

 .../gnome/codeassistance/transport_dbus.py         |   51 ++++++++++++++++++-
 backends/pycommon/gnome/codeassistance/types.py    |   34 +++++++++++++
 2 files changed, 82 insertions(+), 3 deletions(-)
---
diff --git a/backends/pycommon/gnome/codeassistance/transport_dbus.py 
b/backends/pycommon/gnome/codeassistance/transport_dbus.py
index a2dca4b..eceb92e 100644
--- a/backends/pycommon/gnome/codeassistance/transport_dbus.py
+++ b/backends/pycommon/gnome/codeassistance/transport_dbus.py
@@ -88,8 +88,10 @@ class Service:
         information. Finally @options contains backend specific options provided
         by a client.
 
-        @doc is an object of the register document type and should be populated
-        by the implementation.
+        doc: the document needing to be parsed.
+
+        options: an implementation specific set of options passed by the client
+
         """
         pass
 
@@ -130,6 +132,24 @@ class Project:
         """
         pass
 
+class Completion:
+    def complete(self, doc, options):
+        """compute completions at the cursor of a document.
+
+        @doc is an object of the register document type and should be populated
+        by the implementation.
+        """
+        pass
+
+class ProjectCompletion:
+    def complete_all(self, doc, docs, options):
+        """compute completions at the cursor of a document.
+
+        @doc is an object of the register document type and should be populated
+        by the implementation.
+        """
+        pass
+
 class Server(dbus.service.Object):
     class App:
         def __init__(self):
@@ -284,6 +304,29 @@ class ServeProject(dbus.service.Object):
 
         return [types.RemoteDocument(d.client_path, d._object_path).to_tuple() for d in parsed]
 
+class ServeCompletion(dbus.service.Object):
+    @dbus.service.method('org.gnome.CodeAssist.v1.Completion',
+                         in_signature='ss(xx)a{sv}', out_signature='a' + types.Completion.signature,
+                         sender_keyword='sender')
+    def Complete(self, path, data_path, cursor, options, sender=None):
+        app = self.ensure_app(sender)
+        doc = self.ensure_document(app, path, data_path, types.SourceLocation.from_tuple(cursor))
+
+        return [x.to_tuple() for x in app.service.complete(doc, options)]
+
+class ServeProjectCompletion(dbus.service.Object):
+    @dbus.service.method('org.gnome.CodeAssist.v1.ProjectCompletion',
+                         in_signature='sa(ss)(xx)a{sv}', out_signature='a' + types.Completion.signature,
+                         sender_keyword='sender')
+    def CompleteAll(self, path, documents, cursor, options, sender=None):
+        app = self.ensure_app(sender)
+        doc = self.ensure_document(app, path, '', types.SourceLocation.from_tuple(cursor))
+
+        opendocs = [types.OpenDocument.from_tuple(d) for d in documents]
+        docs = [self.ensure_document(app, d.path, d.data_path) for d in opendocs]
+
+        return [x.to_tuple() for x in app.service.complete_all(doc, docs, options)]
+
 class Transport():
     def __init__(self, service, document, srvtype=Server):
         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -302,7 +345,9 @@ class Transport():
     def make_server_cls(self, service):
         types = {
             Service: ServeService,
-            Project: ServeProject
+            Project: ServeProject,
+            Completion: ServeCompletion,
+            ProjectCompletion: ServeProjectCompletion
         }
 
         bases = inspect.getmro(service)[1:]
diff --git a/backends/pycommon/gnome/codeassistance/types.py b/backends/pycommon/gnome/codeassistance/types.py
index fc2310d..d82d9d1 100644
--- a/backends/pycommon/gnome/codeassistance/types.py
+++ b/backends/pycommon/gnome/codeassistance/types.py
@@ -109,4 +109,38 @@ class Diagnostic:
     def to_tuple(self):
         return (self.severity, [f.to_tuple() for f in self.fixits], [l.to_tuple() for l in self.locations], 
self.message)
 
+class Completion:
+    class Chunk:
+        signature = '(si)'
+
+        class Type:
+            TEXT = 0
+            PLACEHOLDER = 1
+
+        def __init__(self, text, type=Type.TEXT):
+            self.text = text
+            self.type = type
+
+        def __repr__(self):
+            return '<Completion.Chunk: {0}, {1}>'.format(self.text, self.type)
+
+        def to_tuple(self):
+            return (self.text, self.type)
+
+    signature = '(sa' + Chunk.signature + 'si)'
+
+    def __init__(self, text, chunks, description='', priority=0):
+        self.text = text
+        self.chunks = chunks
+        self.description = description
+        self.priority = priority
+
+    def __repr__(self):
+        chunks = [repr(chunk) for chunk in self.chunks]
+        return '<Completion: {0}, [{1}], {2}, {3}>'.format(self.text, ', '.join(chunks), self.description, 
self.priority)
+
+    def to_tuple(self):
+        chunks = [chunk.to_tuple() for chunk in self.chunks]
+        return (self.text, chunks, self.description, self.priority)
+
 # ex:ts=4:et:


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