[gnome-code-assistance/wip/completion: 17/19] Added context parameter to Parse and ParseAll
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-code-assistance/wip/completion: 17/19] Added context parameter to Parse and ParseAll
- Date: Sat, 10 Jan 2015 15:26:59 +0000 (UTC)
commit 060ff28351bdb7120f399d0496df91f2750a2321
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Fri Apr 11 15:54:41 2014 +0200
Added context parameter to Parse and ParseAll
backends/c/service.py | 4 +-
backends/go/dbus.go | 10 ++++---
backends/go/server_dbus.go | 12 ++++----
backends/go/service.go | 2 +-
backends/js/main.js | 2 +-
.../gnome/codeassistance/transport_dbus.js | 9 ++++--
backends/json/__init__.py | 2 +-
.../gnome/codeassistance/transport_dbus.py | 29 ++++++++++++-------
backends/python/__init__.py | 2 +-
.../gnome/codeassistance/transport/dbus.rb | 8 +++---
backends/ruby/app.rb | 2 +-
backends/sh/__init__.py | 2 +-
backends/vala/dbus.vala | 16 +++++-----
backends/vala/service.vala | 4 +-
backends/xml/__init__.py | 2 +-
tests/interfaces.json | 2 +
tests/service | 4 +-
17 files changed, 63 insertions(+), 49 deletions(-)
---
diff --git a/backends/c/service.py b/backends/c/service.py
index 429b285..938f7fb 100644
--- a/backends/c/service.py
+++ b/backends/c/service.py
@@ -94,11 +94,11 @@ class Service(transport.Service, transport.Project):
return self._process(doc, docs)
- def parse_all(self, doc, docs, options):
+ def parse_all(self, doc, docs, context, options):
unsaved = [(d.path, open(d.data_path, 'rb')) for d in docs if d.data_path != d.path]
return self._parse(doc, docs, unsaved, options)
- def parse(self, doc, options):
+ def parse(self, doc, context, options):
if doc.data_path != doc.path:
unsaved = [(doc.path, open(doc.data_path, 'rb'))]
else:
diff --git a/backends/go/dbus.go b/backends/go/dbus.go
index 4bbcde9..9ef56fc 100644
--- a/backends/go/dbus.go
+++ b/backends/go/dbus.go
@@ -35,6 +35,7 @@ func (s *ServiceDbus) Introspect() *introspect.Node {
{"path", "s", "in"},
{"data_path", "s", "in"},
{"cursor", "(xx)", "in"},
+ {"context", "s", "in"},
{"options", "a{sv}", "in"},
{"result", "o", "out"},
},
@@ -57,6 +58,7 @@ func (s *ServiceDbus) Introspect() *introspect.Node {
{"path", "s", "in"},
{"documents", "a(ss)", "in"},
{"cursor", "(xx)", "in"},
+ {"context", "s", "in"},
{"options", "a{sv}", "in"},
{"result", "a(so)", "out"},
},
@@ -91,16 +93,16 @@ func (d *DocumentDbus) Introspect() *introspect.Node {
}
}
-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) Parse(path string, dataPath string, cursor SourceLocation, context string, options
map[string]dbus.Variant, sender dbus.Sender) (dbus.ObjectPath, *dbus.Error) {
+ return s.Server.Parse(string(sender), path, dataPath, cursor, context, 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, 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 (s *ServiceDbus) ParseAll(path string, documents []OpenDocument, cursor SourceLocation, context string,
options map[string]dbus.Variant, sender dbus.Sender) ([]RemoteDocument, *dbus.Error) {
+ return s.Server.ParseAll(string(sender), path, documents, cursor, context, options)
}
func (d *DocumentDbus) Diagnostics() ([]Diagnostic, *dbus.Error) {
diff --git a/backends/go/server_dbus.go b/backends/go/server_dbus.go
index ba39ec7..2d1fab9 100644
--- a/backends/go/server_dbus.go
+++ b/backends/go/server_dbus.go
@@ -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, documents []OpenDocument, cursor SourceLocation,
options map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
+func (s *ServerDbus) parse(appid string, path string, documents []OpenDocument, cursor SourceLocation,
context string, options map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
s.mutex.Lock()
app := s.ensureApp(appid)
s.mutex.Unlock()
@@ -193,7 +193,7 @@ func (s *ServerDbus) parse(appid string, path string, documents []OpenDocument,
app.mutex.Unlock()
- if err := app.service.Parse(doc.Document, unsaved, o); err != nil {
+ if err := app.service.Parse(doc.Document, unsaved, context, o); err != nil {
return nil, NewDbusError("ParseError", "%v", err)
}
@@ -202,12 +202,12 @@ func (s *ServerDbus) parse(appid string, path string, documents []OpenDocument,
}, nil
}
-func (s *ServerDbus) Parse(appid string, path string, dataPath string, cursor SourceLocation, options
map[string]dbus.Variant) (dbus.ObjectPath, *dbus.Error) {
+func (s *ServerDbus) Parse(appid string, path string, dataPath string, cursor SourceLocation, context
string, options map[string]dbus.Variant) (dbus.ObjectPath, *dbus.Error) {
documents := []OpenDocument{
{path, dataPath},
}
- ret, err := s.parse(appid, path, documents, cursor, options)
+ ret, err := s.parse(appid, path, documents, cursor, context, options)
if err != nil {
return "", err
@@ -222,8 +222,8 @@ func (s *ServerDbus) Parse(appid string, path string, dataPath string, cursor So
return "", nil
}
-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) ParseAll(appid string, path string, documents []OpenDocument, cursor SourceLocation,
context string, options map[string]dbus.Variant) ([]RemoteDocument, *dbus.Error) {
+ return s.parse(appid, path, documents, cursor, context, options)
}
func (s *ServerDbus) disposeApp(app *App) {
diff --git a/backends/go/service.go b/backends/go/service.go
index f6e0331..fe5b4cb 100644
--- a/backends/go/service.go
+++ b/backends/go/service.go
@@ -99,7 +99,7 @@ func (d *Document) process(parsed *Parsed) error {
return nil
}
-func (s *Service) Parse(doc *Document, unsaved []UnsavedDocument, options Options) error {
+func (s *Service) Parse(doc *Document, unsaved []UnsavedDocument, context string, options Options) error {
parsed, err := TheParser.Parse(doc.Path, doc.Cursor, unsaved, options)
if err != nil {
diff --git a/backends/js/main.js b/backends/js/main.js
index 4941a47..6a6ea58 100644
--- a/backends/js/main.js
+++ b/backends/js/main.js
@@ -32,7 +32,7 @@ Service.prototype = {
},
'org.gnome.CodeAssist.v1.Service': {
- parse: function(doc, options) {
+ parse: function(doc, context, options) {
var c = GLib.file_get_contents(doc.dataPath);
doc.diagnostics = [];
diff --git a/backends/jscommon/gnome/codeassistance/transport_dbus.js
b/backends/jscommon/gnome/codeassistance/transport_dbus.js
index 1df9686..7b41f2f 100644
--- a/backends/jscommon/gnome/codeassistance/transport_dbus.js
+++ b/backends/jscommon/gnome/codeassistance/transport_dbus.js
@@ -9,6 +9,7 @@ var ServiceIface = '<node>
<arg direction="in" type="s" name="path" /> \
<arg direction="in" type="s" name="dataPath" /> \
<arg direction="in" type="(xx)" name="cursor" /> \
+ <arg direction="in" type="s" name="context" /> \
<arg direction="in" type="a{sv}" name="options" /> \
<arg direction="out" type="o" name="documentPath"/> \
</method> \
@@ -24,6 +25,7 @@ var ProjectIface = '<node>
<arg direction="in" type="s" name="path" /> \
<arg direction="in" type="a(ss)" name="documents" /> \
<arg direction="in" type="(xx)" name="cursor" /> \
+ <arg direction="in" type="s" name="context" /> \
<arg direction="in" type="a{sv}" name="options" /> \
<arg direction="out" type="a(so)" name="documents" /> \
</method> \
@@ -135,12 +137,13 @@ Service.prototype = {
},
ParseAsync: function(args, invocation) {
- this.server.dbusAsync(args, invocation, function(sender, path, dataPath, cursor, options) {
+ this.server.dbusAsync(args, invocation, function(sender, path, dataPath, cursor, context, options) {
let app = this.ensureApp(sender);
let doc = this.ensureDocument(app, path, dataPath, Types.SourceLocation.fromTuple(cursor));
app.service['org.gnome.CodeAssist.v1.Service'].parse.call(app.service,
doc,
+ context,
options);
return this.documentPath(app, doc);
@@ -185,7 +188,7 @@ Project.prototype = {
},
ParseAllAsync: function(args, invocation) {
- this.server.dbusAsync(args, invocation, function(sender, path, cursor, documents, options) {
+ this.server.dbusAsync(args, invocation, function(sender, path, cursor, documents, context, options) {
let app = this.ensureApp(sender);
let doc = this.ensureDocument(app, path, '', Types.SourceLocation.fromTuple(cursor));
@@ -197,7 +200,7 @@ Project.prototype = {
return this.ensureDocument(app, d.path, d.dataPath);
});
- parsed = app.service['org.gnome.CodeAssist.v1.Project'].call(app.service, doc, docs, options);
+ parsed = app.service['org.gnome.CodeAssist.v1.Project'].call(app.service, doc, docs, context,
options);
return parsed.map(function(d) {
return (new RemoteDocument({
diff --git a/backends/json/__init__.py b/backends/json/__init__.py
index 0027b68..a096016 100644
--- a/backends/json/__init__.py
+++ b/backends/json/__init__.py
@@ -29,7 +29,7 @@ except ImportError:
class Service(transport.Service):
language = 'json'
- def parse(self, doc, options):
+ def parse(self, doc, context, options):
doc.diagnostics = []
try:
diff --git a/backends/pycommon/gnome/codeassistance/transport_dbus.py
b/backends/pycommon/gnome/codeassistance/transport_dbus.py
index a2dca4b..ff596a0 100644
--- a/backends/pycommon/gnome/codeassistance/transport_dbus.py
+++ b/backends/pycommon/gnome/codeassistance/transport_dbus.py
@@ -75,7 +75,7 @@ class Diagnostics(dbus.service.Object):
class Service:
language = None
- def parse(self, doc, options):
+ def parse(self, doc, context, options):
"""parse a single document.
parse should be implemented to parse the file located at @path
@@ -84,9 +84,11 @@ class Service:
@data_path will be equal to @path. However, if the document is being
edited, then @data_path will be a temporary file containing the modified
document. @cursor is the current location of the cursor in the document
- being edited. The @cursor can be used to gather autocompletion
- information. Finally @options contains backend specific options provided
- by a client.
+ being edited. @context provides a parsing context which can alter the
+ way in which the parse is done. For example, when @context is set
+ to 'completion', the parse should also result in a set of possible
+ completions at @doc.cursor. 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.
@@ -97,7 +99,7 @@ class Service:
pass
class Project:
- def parse_all(self, doc, docs, options):
+ def parse_all(self, doc, docs, context, options):
"""parse multiple documents.
parse_all potentially parses multiple documents at the same time.
@@ -118,6 +120,10 @@ class Project:
in the process of analysing doc. Note that docs always includes at
least doc.
+ context: the parsing context. For example, when set to 'completion',
+ possible completions at @doc.cursor should be calculated as a result
+ of the parse.
+
options: an implementation specific set of options passed by the client
Implementations should do the following steps:
@@ -246,13 +252,13 @@ class Server(dbus.service.Object):
class ServeService(dbus.service.Object):
@dbus.service.method('org.gnome.CodeAssist.v1.Service',
- in_signature='ss(xx)a{sv}', out_signature='o',
+ in_signature='ss(xx)sa{sv}', out_signature='o',
sender_keyword='sender')
- def Parse(self, path, data_path, cursor, options, sender=None):
+ def Parse(self, path, data_path, cursor, context, options, sender=None):
app = self.ensure_app(sender)
doc = self.ensure_document(app, path, data_path, types.SourceLocation.from_tuple(cursor))
- app.service.parse(doc, options)
+ app.service.parse(doc, context, options)
return doc._object_path
@@ -271,16 +277,17 @@ class ServeService(dbus.service.Object):
class ServeProject(dbus.service.Object):
@dbus.service.method('org.gnome.CodeAssist.v1.Project',
- in_signature='sa(ss)(xx)a{sv}', out_signature='a(so)',
+ in_signature='sa(ss)(xx)sa{sv}',
+ out_signature='a(so)',
sender_keyword='sender')
- def ParseAll(self, path, documents, cursor, options, sender=None):
+ def ParseAll(self, path, documents, cursor, context, 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]
- parsed = app.service.parse_all(doc, docs, options)
+ parsed = app.service.parse_all(doc, docs, context, options)
return [types.RemoteDocument(d.client_path, d._object_path).to_tuple() for d in parsed]
diff --git a/backends/python/__init__.py b/backends/python/__init__.py
index eaaa308..2793c17 100644
--- a/backends/python/__init__.py
+++ b/backends/python/__init__.py
@@ -25,7 +25,7 @@ from gnome.codeassistance import transport, types
class Service(transport.Service):
language = 'python'
- def parse(self, doc, options):
+ def parse(self, doc, context, options):
doc.diagnostics = []
try:
diff --git a/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
b/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
index a2c20c5..161276a 100644
--- a/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
+++ b/backends/rbcommon/gnome/codeassistance/transport/dbus.rb
@@ -85,11 +85,11 @@ module Gnome::CodeAssistance::DBus
module Service
dbus_interface 'org.gnome.CodeAssist.v1.Service' do
- 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|
+ dbus_method :Parse, "in path:s, in data_path:s, in cursor:(xx), in context:s, in options:a{sv},
out document:o" do |path, data_path, cursor, context, options|
app = ensure_app(@sender)
doc = ensure_document(app, path, data_path,
Gnome::CodeAssistance::SourceLocation.from_tuple(cursor))
- app.service.parse(doc, options)
+ app.service.parse(doc, context, options)
return doc._dbus.path
end
@@ -104,14 +104,14 @@ module Gnome::CodeAssistance::DBus
module Project
dbus_interface 'org.gnome.CodeAssist.v1.Project' do
- 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|
+ dbus_method :ParseAll, "in path:s, in docs:a(ss), in cursor:(xx), in context:s, in
options:a{sv}, out documents:a(so)" do |path, cursor, documents, context, options|
app = ensure_app(@sender)
doc = ensure_document(app, path, '',
Gnome::CodeAssistance::SourceLocation.from_tuple(cursor))
opendocs = documents.collect { |d| Gnome::CodeAssistance::OpenDocument.from_tuple(d) }
docs = opendocs.collect { |d| ensure_document(app, d.path, d.data_path) }
- parsed = app.service.parse_all(doc, docs, options)
+ parsed = app.service.parse_all(doc, docs, context, options)
return parsed.collect { |d| Gnome::CodeAssistance::RemoteDocument.new(d.client_path,
d._dbus.path).to_tuple }
end
diff --git a/backends/ruby/app.rb b/backends/ruby/app.rb
index 602fee9..85024b8 100644
--- a/backends/ruby/app.rb
+++ b/backends/ruby/app.rb
@@ -23,7 +23,7 @@ module Gnome::CodeAssistance
class Service < Service
@@language = 'ruby'
- def parse(doc, options)
+ def parse(doc, context, options)
doc.diagnostics = []
f = File.new(doc.data_path, 'r')
diff --git a/backends/sh/__init__.py b/backends/sh/__init__.py
index 32c844d..e00cae8 100644
--- a/backends/sh/__init__.py
+++ b/backends/sh/__init__.py
@@ -31,7 +31,7 @@ class Service(transport.Service):
pattern = re.compile("^.*line ([0-9]+).*: (.*)$")
- def parse(self, doc, options):
+ def parse(self, doc, context, options):
doc.diagnostics = []
try:
diff --git a/backends/vala/dbus.vala b/backends/vala/dbus.vala
index fbcac3a..ad94a34 100644
--- a/backends/vala/dbus.vala
+++ b/backends/vala/dbus.vala
@@ -69,9 +69,9 @@ public class ServiceIface : Object
d_server = server;
}
- public async ObjectPath parse(string path, string data_path, SourceLocation cursor, HashTable<string,
Variant> options, GLib.BusName sender) throws Error
+ public async ObjectPath parse(string path, string data_path, SourceLocation cursor, string context,
HashTable<string, Variant> options, GLib.BusName sender) throws Error
{
- return yield d_server.parse(path, data_path, cursor, options, sender);
+ return yield d_server.parse(path, data_path, cursor, context, options, sender);
}
public new void dispose(string path, GLib.BusName sender)
@@ -90,9 +90,9 @@ public class ProjectIface : Object
d_server = server;
}
- public async RemoteDocument[] parse_all(string path, OpenDocument[] documents, SourceLocation cursor,
HashTable<string, Variant> options, GLib.BusName sender) throws Error
+ public async RemoteDocument[] parse_all(string path, OpenDocument[] documents, SourceLocation cursor,
string context, HashTable<string, Variant> options, GLib.BusName sender) throws Error
{
- return yield d_server.parse_all(path, documents, cursor, options, sender);
+ return yield d_server.parse_all(path, documents, cursor, context, options, sender);
}
}
@@ -304,7 +304,7 @@ public class Server
return (ObjectPath)("/org/gnome/CodeAssist/v1/vala/%u/documents/%u".printf(app.id, doc.id));
}
- public async ObjectPath parse(string path, string data_path, SourceLocation cursor, HashTable<string,
Variant> options, GLib.BusName sender) throws Error
+ public async ObjectPath parse(string path, string data_path, SourceLocation cursor, string context,
HashTable<string, Variant> options, GLib.BusName sender) throws Error
{
App app;
ExportedDocument doc;
@@ -315,7 +315,7 @@ public class Server
doc = ensure_document(app, path, data_path, cursor);
}
- yield app.service.parse(doc.document, options);
+ yield app.service.parse(doc.document, context, options);
return remote_document_path(app, doc.document);
}
@@ -343,7 +343,7 @@ public class Server
}
}
- public async RemoteDocument[] parse_all(string path, OpenDocument[] documents, SourceLocation cursor,
HashTable<string, Variant> options, GLib.BusName sender) throws Error
+ public async RemoteDocument[] parse_all(string path, OpenDocument[] documents, SourceLocation cursor,
string context, HashTable<string, Variant> options, GLib.BusName sender) throws Error
{
App app;
ExportedDocument doc;
@@ -363,7 +363,7 @@ public class Server
}
}
- var retdocs = yield app.service.parse_all(doc.document, opendocs, options);
+ var retdocs = yield app.service.parse_all(doc.document, opendocs, context, options);
var ret = new RemoteDocument[retdocs.length];
diff --git a/backends/vala/service.vala b/backends/vala/service.vala
index 61f86a0..62eb80c 100644
--- a/backends/vala/service.vala
+++ b/backends/vala/service.vala
@@ -221,12 +221,12 @@ public class Service
return retdocs;
}
- public async void parse(Document doc, HashTable<string, Variant> options)
+ public async void parse(Document doc, string context, HashTable<string, Variant> options)
{
yield parse_impl(doc, new Document[] {doc}, options);
}
- public async Document[] parse_all(Document doc, Document[] documents, HashTable<string, Variant>
options)
+ public async Document[] parse_all(Document doc, Document[] documents, string context,
HashTable<string, Variant> options)
{
return yield parse_impl(doc, documents, options);
}
diff --git a/backends/xml/__init__.py b/backends/xml/__init__.py
index 2e5a394..2103759 100644
--- a/backends/xml/__init__.py
+++ b/backends/xml/__init__.py
@@ -102,7 +102,7 @@ class Service(transport.Service):
return (None, None, None)
- def parse(self, doc, options):
+ def parse(self, doc, context, options):
doc.diagnostics = []
doc_type = 'XML'
diff --git a/tests/interfaces.json b/tests/interfaces.json
index a82c508..9c62b5c 100644
--- a/tests/interfaces.json
+++ b/tests/interfaces.json
@@ -4,6 +4,7 @@
{"name": "path", "direction": "in", "type": "s"},
{"name": "data_path", "direction": "in", "type": "s"},
{"name": "cursor", "direction": "in", "type": "(xx)"},
+ {"name": "context", "direction": "in", "type": "s"},
{"name": "options", "direction": "in", "type": "a{sv}"},
{"name": "document", "direction": "out", "type": "o"}
],
@@ -17,6 +18,7 @@
{"name": "path", "direction": "in", "type": "s"},
{"name": "documents", "direction": "in", "type": "a(ss)"},
{"name": "cursor", "direction": "in", "type": "(xx)"},
+ {"name": "context", "direction": "in", "type": "s"},
{"name": "options", "direction": "in", "type": "a{sv}"},
{"name": "result", "direction": "out", "type": "a(so)"}
]
diff --git a/tests/service b/tests/service
index 10810a6..83ef98e 100755
--- a/tests/service
+++ b/tests/service
@@ -284,7 +284,7 @@ class ServiceTest:
obj = self.get_object('/')
iface = dbus.Interface(obj, 'org.gnome.CodeAssist.v1.Service')
- doc = iface.Parse(self.file_path(path), '', (0, 0), {})
+ doc = iface.Parse(self.file_path(path), '', (0, 0), '', {})
doc = doc[len(self.path):]
@@ -317,7 +317,7 @@ class ServiceTest:
docs.insert(0, gcatypes.OpenDocument(path))
iface = dbus.Interface(obj, 'org.gnome.CodeAssist.v1.Project')
- return iface.ParseAll(self.file_path(path), [d.to_tuple() for d in docs], (0, 0), {})
+ return iface.ParseAll(self.file_path(path), [d.to_tuple() for d in docs], (0, 0), '', {})
def verify_parse_diagnostics(self, path, obj, diagnostics):
with self.test_interface(path, 'org.gnome.CodeAssist.v1.Diagnostics') as t:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]