Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

JSON rpc

Fredrik Ehnbom edited this page Mar 30, 2015 · 2 revisions

Daemonize

First launch in daemon mode in one shell:

$ ./completion daemon
2014/05/10 15:20:26 method Get has wrong number of ins: 2
2014/05/10 15:20:26 method MarshalJSON has wrong number of ins: 1
2014/05/10 15:20:26 method Set reply type not a pointer: interface {}
2014/05/10 15:20:26 method UnmarshalJSON has wrong number of ins: 2

The application should not give you the shell back, if it does something went wrong and due to a bug in the log library the application closed before it was able to print the error message out.

Drivers

Lacking ideas for a better name, I've simply referred to the different language backends as "drivers". Query the daemon's init function for up to date information on which drivers are available. (There should be a json-rpc method to figuring this out at some point.. Pull requests please)

Operations

Each Driver implement different Operations, methods, interfaces or whatever you want to call them.

Open up a second shell and try to complete something

echo '{"method":"Net.Complete","params":[{"Location":{"Absolute":"net://type/System.Int32"}}]}' | nc -U /tmp/completion.rpc
echo '{"method":"Java.Complete","params":[{"Location":{"Absolute":"java://type/java.lang.String"}}]}' | nc -U /tmp/completion.rpc

This would be the Complete operation where the params are derived from the CompleteArgs structure.

There's also a CompleteAt operation where the parameter is the CompleteAtArgs structure.

echo "class Hello { void hello() {System.Console." > /tmp/Hello.cs
echo '{"method":"Net.CompleteAt","params":[{"Location":{"File":{"Name":"/tmp/Hello.cs"},"Line":1,"Column":44}}]}' | nc -U /tmp/completion.rpc

The contents of the file can also be provided:

echo '{"method":"Net.CompleteAt","params":[{"Location":{"File":{"Name":"does_not_exist.cs","Contents":"class Goodbye { void goodbye() {System.Console.\n"},"Line":1,"Column":48}}]}' | nc -U /tmp/completion.rpc

Settings

Each Driver can be configured with settings such as compiler flags, class paths, .net assemblies to load etc. These settings can be sent together with each json rpc call:

echo "class Hello { void hello() {}}" > /tmp/Hello.java
javac /tmp/Hello.java
echo '{"method":"Java.Complete","params":[{"Location":{"Absolute":"java://type/Hello"},"SessionOverrides": {"java_classpath":["/tmp"]}}]}' | nc -U /tmp/completion.rpc

In the future there should be a json rpc call to query the settings each driver has (Pull request please), in the mean time please refer to each driver's source code

Session

Settings can alternatively be set once in a "session" and then future json rpc calls can simply refer to this session id.

To register a session, the Session Driver's Register operation is invoked, which takes a SessionRegisterArgs structure as its parameter.

echo '{"method":"Session.Register","params":[{"SessionId":"mysession","Settings":{"java_classpath":["/tmp"]}}]}' | nc localhost 12345
echo '{"method":"Java.Complete","params":[{"Location":{"Absolute":"java://type/Hello"}, "SessionId":"mysession"}]}' | nc -U /tmp/completion.rpc

When the session is no longer needed, it can be unregistered:

echo '{"method":"Session.Unregister","params":["mysession"]}' | nc -U /tmp/completion.rpc
Clone this wiki locally