[gnome-code-assistance] Make cursor a SourceLocation



commit bf7ddb168be8cd32fd28a0c8580350bf85ac7345
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Nov 11 23:38:54 2013 +0100

    Make cursor a SourceLocation

 README                                             |   12 ++++++------
 backends/go/dbus.go                                |   12 ++++++------
 backends/go/parser.go                              |    2 +-
 backends/go/server_dbus.go                         |   12 ++++++------
 backends/go/service.go                             |    2 +-
 .../gnome/codeassistance/transport_dbus.js         |   11 ++++++-----
 backends/jscommon/gnome/codeassistance/types.js    |    7 +++++++
 .../gnome/codeassistance/transport_dbus.py         |   18 +++++++++---------
 backends/pycommon/gnome/codeassistance/types.py    |    4 ++++
 .../gnome/codeassistance/transport/dbus.rb         |   12 ++++++------
 backends/rbcommon/gnome/codeassistance/types.rb    |    4 ++++
 backends/vala/dbus.vala                            |    4 ++--
 backends/vala/document.vala                        |    2 +-
 13 files changed, 59 insertions(+), 43 deletions(-)
---
diff --git a/README b/README
index 732370a..baa37f4 100644
--- a/README
+++ b/README
@@ -41,20 +41,20 @@ define the code assistance protocol.
         // Parse and analyse a single document.
         //
         // path:     the file path to be parsed.
-        // cursor:   the current location (in bytes) of the cursor. The cursor
-        //           position can be used for the purpose of obtaining
-        //           information for services like auto-completion.
         // dataPath: the path where the actual file data can be obtained. The
         //           dataPath should be used to provide the contents of a file
         //           that has modifications not yet written to disk (i.e. a file
         //           being edited).
+        // cursor:   the current location (line/column) of the cursor. The cursor
+        //           position can be used for the purpose of obtaining
+        //           information for services like auto-completion.
         // options:  a map of backend specific options.
         //
         // returns:  a dbus object path where information on the parsed document
         //           can be obtained. The object located at this path can
         //           be introspected to find out which services are available.
         //
-        Parse(path string, cursor int64, dataPath string, options map[string]variant) object
+        Parse(path string, dataPath string, cursor SourceLocation, options map[string]variant) object
 
         // Dispose the document representing the given file path. Note that this
         // is a file path, not a dbus object path. Clients can call dispose
@@ -74,7 +74,6 @@ define the code assistance protocol.
         // given path.
         //
         // path:      the file path to be parsed.
-        // cursor:    the cursor location (see org.gnome.CodeAssist.v1.Service.Parse).
         // documents: a list of open documents (path string, dataPath string).
         //            This list serves two purposes. 1) it provides dataPath
         //            for all being-edited documents and 2) it provides a list
@@ -83,6 +82,7 @@ define the code assistance protocol.
         //            language). Note that this list is *not* a list of files
         //            in a project. It is up to the backend to parse all files
         //            relevant to complete the file at path.
+        // cursor:    the cursor location (see org.gnome.CodeAssist.v1.Service.Parse).
         // options:   a map of backend specific options.
         //
         // returns:   a list of RemoteDocument (path string, remotePath object).
@@ -90,7 +90,7 @@ define the code assistance protocol.
         //            provided documents for which new information is available
         //            after parsing.
         //
-        ParseAll(path string, cursor int64, documents []OpenDocument, options map[string]variant) 
[]RemoteDocument
+        ParseAll(path string, documents []OpenDocument, cursor SourceLocation, options map[string]variant) 
[]RemoteDocument
     }
 
     // All services must the Document interface on each document
diff --git a/backends/go/dbus.go b/backends/go/dbus.go
index 5c62613..d8eb996 100644
--- a/backends/go/dbus.go
+++ b/backends/go/dbus.go
@@ -33,8 +33,8 @@ func (s *ServiceDbus) Introspect() *introspect.Node {
                                                Name: "Parse",
                                                Args: []introspect.Arg{
                                                        {"path", "s", "in"},
-                                                       {"cursor", "x", "in"},
                                                        {"data_path", "s", "in"},
+                                                       {"cursor", "(xx)", "in"},
                                                        {"options", "a{sv}", "in"},
                                                        {"result", "o", "out"},
                                                },
@@ -55,8 +55,8 @@ func (s *ServiceDbus) Introspect() *introspect.Node {
                                                Name: "ParseAll",
                                                Args: []introspect.Arg{
                                                        {"path", "s", "in"},
-                                                       {"cursor", "x", "in"},
                                                        {"documents", "a(ss)", "in"},
+                                                       {"cursor", "(xx)", "in"},
                                                        {"options", "a{sv}", "in"},
                                                        {"result", "a(so)", "out"},
                                                },
@@ -91,16 +91,16 @@ func (d *DocumentDbus) Introspect() *introspect.Node {
        }
 }
 
-func (s *ServiceDbus) Parse(path string, cursor int64, dataPath string, options map[string]dbus.Variant, 
sender dbus.Sender) (dbus.ObjectPath, *dbus.Error) {
-       return s.Server.Parse(string(sender), path, cursor, dataPath, options)
+func (s *ServiceDbus) Parse(path string, dataPath string, cursor SourceLocation, options 
map[string]dbus.Variant, sender dbus.Sender) (dbus.ObjectPath, *dbus.Error) {
+       return s.Server.Parse(string(sender), path, dataPath, cursor, options)
 }
 
 func (s *ServiceDbus) Dispose(path string, sender dbus.Sender) *dbus.Error {
        return s.Server.Dispose(string(sender), path)
 }
 
-func (s *ServiceDbus) ParseAll(path string, cursor int64, documents []OpenDocument, options 
map[string]dbus.Variant, sender dbus.Sender) ([]RemoteDocument, *dbus.Error) {
-       return s.Server.ParseAll(string(sender), path, cursor, documents, options)
+func (s *ServiceDbus) ParseAll(path string, documents []OpenDocument, cursor SourceLocation, options 
map[string]dbus.Variant, sender dbus.Sender) ([]RemoteDocument, *dbus.Error) {
+       return s.Server.ParseAll(string(sender), path, documents, cursor, options)
 }
 
 func (d *DocumentDbus) Diagnostics() ([]Diagnostic, *dbus.Error) {
diff --git a/backends/go/parser.go b/backends/go/parser.go
index 14043e0..8b3a9f2 100644
--- a/backends/go/parser.go
+++ b/backends/go/parser.go
@@ -252,7 +252,7 @@ func (p *Parser) importSourceFirst(imports map[string]*types.Package, fs *token.
        return pkg, err
 }
 
-func (p *Parser) Parse(path string, cursor int64, unsaved []UnsavedDocument, options Options) (*Parsed, 
error) {
+func (p *Parser) Parse(path string, cursor SourceLocation, unsaved []UnsavedDocument, options Options) 
(*Parsed, error) {
        if len(options.GoPath) == 0 {
                options.GoPath = os.Getenv("GOPATH")
        }
diff --git a/backends/go/server_dbus.go b/backends/go/server_dbus.go
index 4bee670..7f371ef 100644
--- a/backends/go/server_dbus.go
+++ b/backends/go/server_dbus.go
@@ -124,7 +124,7 @@ func (s *ServerDbus) makeDocument(app *App, path string, clientPath string) *Doc
        return ddoc
 }
 
-func (s *ServerDbus) ensureDocument(app *App, path string, dataPath string, cursor int64) *DocumentDbus {
+func (s *ServerDbus) ensureDocument(app *App, path string, dataPath string, cursor SourceLocation) 
*DocumentDbus {
        npath := filepath.Clean(path)
 
        doc := app.docs[npath]
@@ -152,7 +152,7 @@ func (s *ServerDbus) parseOptions(options map[string]dbus.Variant) (Options, err
        return o, err
 }
 
-func (s *ServerDbus) parse(appid string, path string, cursor int64, documents []OpenDocument, options 
map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
+func (s *ServerDbus) parse(appid string, path string, documents []OpenDocument, cursor SourceLocation, 
options map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
        s.mutex.Lock()
        app := s.ensureApp(appid)
        s.mutex.Unlock()
@@ -202,12 +202,12 @@ func (s *ServerDbus) parse(appid string, path string, cursor int64, documents []
        }, nil
 }
 
-func (s *ServerDbus) Parse(appid string, path string, cursor int64, dataPath string, options 
map[string]dbus.Variant) (dbus.ObjectPath, *dbus.Error) {
+func (s *ServerDbus) Parse(appid string, path string, dataPath string, cursor SourceLocation, options 
map[string]dbus.Variant) (dbus.ObjectPath, *dbus.Error) {
        documents := []OpenDocument{
                {path, dataPath},
        }
 
-       ret, err := s.parse(appid, path, cursor, documents, options)
+       ret, err := s.parse(appid, path, documents, cursor, options)
 
        if err != nil {
                return "", err
@@ -222,8 +222,8 @@ func (s *ServerDbus) Parse(appid string, path string, cursor int64, dataPath str
        return "", nil
 }
 
-func (s *ServerDbus) ParseAll(appid string, path string, cursor int64, documents []OpenDocument, options 
map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
-       return s.parse(appid, path, cursor, documents, options)
+func (s *ServerDbus) ParseAll(appid string, path string, documents []OpenDocument, cursor SourceLocation, 
options map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
+       return s.parse(appid, path, documents, cursor, options)
 }
 
 func (s *ServerDbus) disposeApp(app *App) {
diff --git a/backends/go/service.go b/backends/go/service.go
index 785ad15..f6e0331 100644
--- a/backends/go/service.go
+++ b/backends/go/service.go
@@ -49,7 +49,7 @@ type Document struct {
        Path       string
        DataPath   string
        ClientPath string
-       Cursor     int64
+       Cursor     SourceLocation
 
        Diagnostics []Diagnostic
 
diff --git a/backends/jscommon/gnome/codeassistance/transport_dbus.js 
b/backends/jscommon/gnome/codeassistance/transport_dbus.js
index d3b9af8..11085a9 100644
--- a/backends/jscommon/gnome/codeassistance/transport_dbus.js
+++ b/backends/jscommon/gnome/codeassistance/transport_dbus.js
@@ -2,12 +2,13 @@ const GLib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const System = imports.system;
 const Lang = imports.lang;
+const Types = imports.gnome.codeassistance.types;
 
 var ServiceIface = '<interface name="org.gnome.CodeAssist.v1.Service">          \
   <method name="Parse">                                                         \
     <arg direction="in"  type="s" name="path" />                                \
-    <arg direction="in"  type="x" name="cursor" />                              \
     <arg direction="in"  type="s" name="dataPath" />                            \
+    <arg direction="in"  type="(xx)" name="cursor" />                           \
     <arg direction="in"  type="a{sv}" name="options" />                         \
     <arg direction="out" type="o" name="documentPath"/>                         \
   </method>                                                                     \
@@ -19,8 +20,8 @@ var ServiceIface = '<interface name="org.gnome.CodeAssist.v1.Service">
 var ProjectIface = '<interface name="org.gnome.CodeAssist.v1.Project">          \
   <method name="ParseAll">                                                      \
     <arg direction="in"  type="s" name="path" />                                \
-    <arg direction="in"  type="x" name="cursor" />                              \
     <arg direction="in"  type="a(ss)" name="documents" />                       \
+    <arg direction="in"  type="(xx)" name="cursor" />                           \
     <arg direction="in"  type="a{sv}" name="options" />                         \
     <arg direction="out" type="a(so)" name="documents" />                       \
   </method>                                                                     \
@@ -127,7 +128,7 @@ Service.prototype = {
     ParseAsync: function(args, invocation) {
         this.server.dbusAsync(args, invocation, function(sender, path, cursor, dataPath, options) {
             let app = this.ensureApp(sender);
-            let doc = this.ensureDocument(app, path, dataPath, cursor);
+            let doc = this.ensureDocument(app, path, dataPath, Types.SourceLocation.fromTuple(cursor));
 
             app.service['org.gnome.CodeAssist.v1.Service'].parse.call(app.service,
                                                                       doc,
@@ -169,7 +170,7 @@ Project.prototype = {
     ParseAllAsync: function(args, invocation) {
         this.server.dbusAsync(args, invocation, function(sender, path, cursor, documents, options) {
             let app = this.ensureApp(sender);
-            let doc = this.ensureDocument(app, path, '', cursor);
+            let doc = this.ensureDocument(app, path, '', Types.SourceLocation.fromTuple(cursor));
 
             let opendocs = documents.map(function (d) {
                 return OpenDocument.fromTuple(d);
@@ -314,7 +315,7 @@ Server.prototype = {
         return Gio.file_new_for_path(path).get_path();
     },
 
-    ensureDocument: function(app, path, dataPath, cursor=0) {
+    ensureDocument: function(app, path, dataPath, cursor) {
         let cpath = this.cleanPath(path);
 
         let doc;
diff --git a/backends/jscommon/gnome/codeassistance/types.js b/backends/jscommon/gnome/codeassistance/types.js
index 5bcac81..61dffaa 100644
--- a/backends/jscommon/gnome/codeassistance/types.js
+++ b/backends/jscommon/gnome/codeassistance/types.js
@@ -25,6 +25,13 @@ SourceLocation.prototype = {
     }
 };
 
+SourceLocation.fromTuple = function(tp) {
+    return new SourceLocation({
+        line: tp[0],
+        column: tp[1]
+    });
+};
+
 let SourceRange = function(vals) {
     this._init(vals);
 };
diff --git a/backends/pycommon/gnome/codeassistance/transport_dbus.py 
b/backends/pycommon/gnome/codeassistance/transport_dbus.py
index ac32a99..2781912 100644
--- a/backends/pycommon/gnome/codeassistance/transport_dbus.py
+++ b/backends/pycommon/gnome/codeassistance/transport_dbus.py
@@ -38,7 +38,7 @@ class Document(dbus.service.Object):
         self.path = ''
         self.client_path = ''
         self.data_path = ''
-        self.cursor = 0
+        self.cursor = types.SourceLocation()
 
 class Diagnostics(dbus.service.Object):
     """Diagnostics interface.
@@ -194,7 +194,7 @@ class Server(dbus.service.Object):
 
         return doc
 
-    def ensure_document(self, app, path, data_path, cursor=0):
+    def ensure_document(self, app, path, data_path, cursor=None):
         npath = (path and os.path.normpath(path))
 
         try:
@@ -203,7 +203,7 @@ class Server(dbus.service.Object):
             doc = self.make_document(app, npath, path)
 
         doc.data_path = (data_path or path)
-        doc.cursor = cursor
+        doc.cursor = cursor or types.SourceLocation()
 
         return doc
 
@@ -234,11 +234,11 @@ class Server(dbus.service.Object):
 
 class ServeService(dbus.service.Object):
     @dbus.service.method('org.gnome.CodeAssist.v1.Service',
-                         in_signature='sxa(ss)a{sv}', out_signature='o',
+                         in_signature='ss(xx)a{sv}', out_signature='o',
                          sender_keyword='sender')
-    def Parse(self, path, cursor, data_path, options, sender=None):
+    def Parse(self, path, data_path, cursor, options, sender=None):
         app = self.ensure_app(sender)
-        doc = self.ensure_document(app, path, data_path, cursor)
+        doc = self.ensure_document(app, path, data_path, types.SourceLocation.from_tuple(cursor))
 
         app.service.parse(doc, options)
 
@@ -259,11 +259,11 @@ class ServeService(dbus.service.Object):
 
 class ServeProject(dbus.service.Object):
     @dbus.service.method('org.gnome.CodeAssist.v1.Project',
-                         in_signature='sxa(ss)a{sv}', out_signature='a(so)',
+                         in_signature='sa(ss)(xx)a{sv}', out_signature='a(so)',
                          sender_keyword='sender')
-    def ParseAll(self, path, cursor, documents, options, sender=None):
+    def ParseAll(self, path, documents, cursor, options, sender=None):
         app = self.ensure_app(sender)
-        doc = self.ensure_document(app, path, '', cursor)
+        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]
diff --git a/backends/pycommon/gnome/codeassistance/types.py b/backends/pycommon/gnome/codeassistance/types.py
index 91ed27d..fc2310d 100644
--- a/backends/pycommon/gnome/codeassistance/types.py
+++ b/backends/pycommon/gnome/codeassistance/types.py
@@ -46,6 +46,10 @@ class SourceLocation:
     def __repr__(self):
         return '{0}.{1}'.format(self.line, self.column)
 
+    @classmethod
+    def from_tuple(cls, tp):
+        return cls(tp[0], tp[1])
+
     def to_range(self, file=0):
         start = SourceLocation(line=self.line, column=self.column)
         end = SourceLocation(line=self.line, column=self.column)
diff --git a/backends/rbcommon/gnome/codeassistance/transport/dbus.rb 
b/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
index c8845cb..6f6f6ae 100644
--- a/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
+++ b/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
@@ -82,9 +82,9 @@ module Gnome::CodeAssistance::DBus
 
     module Service
         dbus_interface 'org.gnome.CodeAssist.v1.Service' do
-            dbus_method :Parse, "in path:s, in cursor:x, in data_path:s, in options:a{sv}, out document:o" 
do |path, cursor, data_path, options|
+            dbus_method :Parse, "in path:s, in data_path:s, in cursor:(xx), in options:a{sv}, out 
document:o" do |path, data_path, cursor, options|
                 app = ensure_app(@sender)
-                doc = ensure_document(app, path, data_path, cursor)
+                doc = ensure_document(app, path, data_path, SourceLocation.from_tuple(cursor))
 
                 app.service.parse(doc, options)
 
@@ -101,9 +101,9 @@ module Gnome::CodeAssistance::DBus
 
     module Project
         dbus_interface 'org.gnome.CodeAssist.v1.Project' do
-            dbus_method :ParseAll, "in path:s, in cursor:x, in docs:a(ss), in options:a{sv}, out 
documents:a(so)" do |path, cursor, documents, options|
+            dbus_method :ParseAll, "in path:s, in docs:a(ss), in cursor:(xx), in options:a{sv}, out 
documents:a(so)" do |path, cursor, documents, options|
                 app = ensure_app(@sender)
-                doc = ensure_document(app, path, '', cursor)
+                doc = ensure_document(app, path, '', SourceLocation.from_tuple(cursor))
 
                 opendocs = documents.collect { |d| OpenDocument.from_tuple(d) }
                 docs = opendocs.collect { |d| ensure_document(app, d.path, d.data_path) }
@@ -258,13 +258,13 @@ module Gnome::CodeAssistance
             doc
         end
 
-        def ensure_document(app, path, data_path, cursor=0)
+        def ensure_document(app, path, data_path, cursor=nil)
             npath = normpath(path)
 
             doc = app.docs[npath] || make_document(app, npath, path)
 
             doc.data_path = data_path || path
-            doc.cursor = cursor
+            doc.cursor = cursor || SourceLocation()
 
             doc
         end
diff --git a/backends/rbcommon/gnome/codeassistance/types.rb b/backends/rbcommon/gnome/codeassistance/types.rb
index d7f86fb..42a8052 100644
--- a/backends/rbcommon/gnome/codeassistance/types.rb
+++ b/backends/rbcommon/gnome/codeassistance/types.rb
@@ -64,6 +64,10 @@ module Gnome::CodeAssistance
             "#{ line} #{@column}"
         end
 
+        def self.from_tuple(tp)
+            SourceLocation.new(tp[0], tp[1])
+        end
+
         def to_range(file=0)
             s = SourceLocation.new(@line, @column)
             e = SourceLocation.new(@line, @column)
diff --git a/backends/vala/dbus.vala b/backends/vala/dbus.vala
index c9df068..1835574 100644
--- a/backends/vala/dbus.vala
+++ b/backends/vala/dbus.vala
@@ -195,7 +195,7 @@ public class Service : Object
                return doc;
        }
 
-       private Document ensure_document(App app, string path, string data_path, int64 cursor)
+       private Document ensure_document(App app, string path, string data_path, SourceLocation cursor)
        {
                var cpath = clean_path(path);
                Document doc;
@@ -222,7 +222,7 @@ public class Service : Object
                return doc;
        }
 
-       public ObjectPath parse(string path, int64 cursor, string data_path, HashTable<string, Variant> 
options, GLib.BusName sender) throws Error
+       public ObjectPath parse(string path, string data_path, SourceLocation cursor, HashTable<string, 
Variant> options, GLib.BusName sender) throws Error
        {
                var app = ensure_app(sender);
                var doc = ensure_document(app, path, data_path, cursor);
diff --git a/backends/vala/document.vala b/backends/vala/document.vala
index 1e845d1..60387b8 100644
--- a/backends/vala/document.vala
+++ b/backends/vala/document.vala
@@ -24,7 +24,7 @@ public class Document : Object
 {
        public string path { get; construct set; }
        public string data_path { get; set; }
-       public int64 cursor { get; set; }
+       public SourceLocation cursor { get; set; }
        public string client_path { get; set; }
 
        public Diagnostic[] diagnostics { get; set; }


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