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

Commit

Permalink
Add links to 3rdparty libs. Cleanups. Basic rpc server hooked up.
Browse files Browse the repository at this point in the history
  • Loading branch information
quarnster committed May 8, 2013
1 parent 9504c28 commit dd46beb
Show file tree
Hide file tree
Showing 21 changed files with 281 additions and 419 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ java/descriptors/descriptors.go
java/signatures/signatures.go
clang/parser/parser.go
util/expression/expression.go
*.pyc
45 changes: 24 additions & 21 deletions 3rdparty/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
close ('127.0.0.1', 31415)
Client with JsonRPC2.0 and an abstract Unix Domain Socket::
>>> proxy = ServerProxy( JsonRpc20(), TransportUnixSocket(addr="\\x00.rpcsocket") )
>>> proxy.hi( message="hello" ) #named parameters
u'hi there'
Expand All @@ -56,7 +56,7 @@
u'hello world'
Server with JsonRPC2.0 and abstract Unix Domain Socket with a logfile::
>>> server = Server( JsonRpc20(), TransportUnixSocket(addr="\\x00.rpcsocket", logfunc=log_file("mylog.txt")) )
>>> def echo( s ):
... return s
Expand Down Expand Up @@ -168,7 +168,7 @@
PERMISSION_DENIED : "Permission denied.",
INVALID_PARAM_VALUES: "Invalid parameter values."
}

#----------------------
# exceptions

Expand All @@ -183,7 +183,7 @@ class RPCTimeoutError(RPCTransportError):

class RPCFault(RPCError):
"""RPC error/fault package received.
This exception can also be used as a class, to generate a
RPC-error/fault message.
Expand Down Expand Up @@ -254,8 +254,11 @@ def __init__(self, error_data=None):
try:
import simplejson
except ImportError, err:
print "FATAL: json-module 'simplejson' is missing (%s)" % (err)
sys.exit(1)
try:
import json as simplejson
except ImportError, err:
print "FATAL: json-module 'simplejson' is missing (%s)" % (err)
sys.exit(1)

#----------------------
#
Expand Down Expand Up @@ -304,7 +307,7 @@ def dumps_request( self, method, params=(), id=0 ):
- id: if id=None, this results in a Notification
:Returns: | {"method": "...", "params": ..., "id": ...}
| "method", "params" and "id" are always in this order.
:Raises: TypeError if method/params is of wrong type or
:Raises: TypeError if method/params is of wrong type or
not JSON-serializable
"""
if not isinstance(method, (str, unicode)):
Expand Down Expand Up @@ -346,7 +349,7 @@ def dumps_error( self, error, id=None ):
Since JSON-RPC 1.0 does not define an error-object, this uses the
JSON-RPC 2.0 error-object.
:Parameters:
- error: a RPCFault instance
:Returns: | {"result": null, "error": {"code": error_code, "message": error_message, "data": error_data}, "id": ...}
Expand Down Expand Up @@ -481,7 +484,7 @@ def dumps_request( self, method, params=(), id=0 ):
:Returns: | {"jsonrpc": "2.0", "method": "...", "params": ..., "id": ...}
| "jsonrpc", "method", "params" and "id" are always in this order.
| "params" is omitted if empty
:Raises: TypeError if method/params is of wrong type or
:Raises: TypeError if method/params is of wrong type or
not JSON-serializable
"""
if not isinstance(method, (str, unicode)):
Expand Down Expand Up @@ -528,7 +531,7 @@ def dumps_response( self, result, id=None ):

def dumps_error( self, error, id=None ):
"""serialize a JSON-RPC-Response-error
:Parameters:
- error: a RPCFault instance
:Returns: | {"jsonrpc": "2.0", "error": {"code": error_code, "message": error_message, "data": error_data}, "id": ...}
Expand Down Expand Up @@ -676,7 +679,7 @@ def logfile( message ):

class Transport:
"""generic Transport-interface.
This class, and especially its methods and docstrings,
define the Transport-Interface.
"""
Expand All @@ -696,7 +699,7 @@ def sendrecv( self, string ):
return self.recv()
def serve( self, handler, n=None ):
"""serve (forever or for n communicaions).
- receive data
- call result = handler(data)
- send back result if not None
Expand Down Expand Up @@ -737,7 +740,7 @@ def recv(self):
import socket, select
class TransportSocket(Transport):
"""Transport via socket.
:SeeAlso: python-module socket
:TODO:
- documentation
Expand Down Expand Up @@ -772,7 +775,7 @@ def close( self ):
self.s = None
def __repr__(self):
return "<TransportSocket, %s>" % repr(self.addr)

def send( self, string ):
if self.s is None:
self.connect()
Expand All @@ -799,7 +802,7 @@ def sendrecv( self, string ):
self.close()
def serve(self, handler, n=None):
"""open socket, wait for incoming connections and handle them.
:Parameters:
- n: serve n requests, None=forever
"""
Expand Down Expand Up @@ -829,7 +832,7 @@ def serve(self, handler, n=None):


if hasattr(socket, 'AF_UNIX'):

class TransportUnixSocket(TransportSocket):
"""Transport via Unix Domain Socket.
"""
Expand Down Expand Up @@ -941,7 +944,7 @@ def __call__(self, *args, **kwargs):
class Server:
"""RPC-server.
It works with different data/serializers and
It works with different data/serializers and
with different transports.
:Example:
Expand Down Expand Up @@ -982,7 +985,7 @@ def log(self, message):

def register_instance(self, myinst, name=None):
"""Add all functions of a class-instance to the RPC-services.
All entries of the instance which do not begin with '_' are added.
:Parameters:
Expand All @@ -1002,7 +1005,7 @@ def register_instance(self, myinst, name=None):
self.register_function( getattr(myinst, e), name="%s.%s" % (name, e) )
def register_function(self, function, name=None):
"""Add a function to the RPC-services.
:Parameters:
- function: function to add
- name: RPC-name for the function. If omitted/None, the original
Expand All @@ -1012,7 +1015,7 @@ def register_function(self, function, name=None):
self.funcs[function.__name__] = function
else:
self.funcs[name] = function

def handle(self, rpcstr):
"""Handle a RPC-Request.
Expand Down Expand Up @@ -1066,7 +1069,7 @@ def handle(self, rpcstr):

def serve(self, n=None):
"""serve (forever or for n communicaions).
:See: Transport
"""
self.__transport.serve( self.handle, n )
Expand Down
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Goals

This project aims to implement an editor and language agnostic backend with the initial
scope of supporting:

Expand All @@ -21,6 +23,8 @@ Collaborators wanting to aid the project are welcome to submit pull requests and
open up a new issue number for discussing implementation details not already discussed
in the [existing issues](https://github.com/quarnster/completion/issues?state=open) list.

# License

The license of the project is the 2-clause BSD license:

```
Expand All @@ -47,3 +51,78 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

# Third party libraries used:

[Roland Koebler's json.py](http://www.simple-is-better.org/rpc/) (slightly modified, see [commit history](https://github.com/quarnster/completion/commits/master/3rdparty/jsonrpc.py))
```
Copyright (c) 2007-2008 by Roland Koebler (rk(at)simple-is-better.org)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

[Kyle Lemons' log4go](https://code.google.com/p/log4go/)
```
Copyright (c) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

[fsnotify](https://github.com/howeyc/fsnotify)
```
Copyright (c) 2012 The Go Authors. All rights reserved.
Copyright (c) 2012 fsnotify Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```
3 changes: 1 addition & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"runtime"
)

var ignore = regexp.MustCompile(`\.git|build|testdata`)
var ignore = regexp.MustCompile(`\.git|build|testdata|3rdparty`)
var verbose bool

func adddirs(pkg, path string, dirs []string) []string {
Expand Down Expand Up @@ -103,7 +103,6 @@ func main() {
if verbose {
tests = append(tests, "-v")
}
tests = append(tests, "github.com/quarnster/completion")
tests = adddirs("github.com/quarnster/completion", "..", tests)
c = exec.Command("go", tests...)
r, err := c.StdoutPipe()
Expand Down
21 changes: 15 additions & 6 deletions clang/clang.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package clang

import (
"code.google.com/p/log4go"
"fmt"
cp "github.com/quarnster/completion/clang/parser"
"github.com/quarnster/completion/content"
Expand All @@ -10,7 +11,7 @@ import (

func RunClang(args ...string) ([]byte, error) {
cmd := exec.Command("clang", args...)
fmt.Println("cmd:", cmd.Args)
log4go.Trace("Running clang command: %v", cmd)
return cmd.CombinedOutput()
}

Expand Down Expand Up @@ -70,12 +71,20 @@ func parseresult(in string) (ret content.CompletionResult, err error) {
return
}

func CompleteAt(args []string, loc content.SourceLocation) (ret content.CompletionResult, err error) {
args = append([]string{"-fsyntax-only", "-Xclang", fmt.Sprintf("-code-completion-at=%s:%d:%d", loc.File.Name, loc.Line, loc.Column)}, args...)
args = append(args, loc.File.Name)
type Clang struct {
}

func (c *Clang) CompleteAt(a *content.CompleteAtArgs, ret *content.CompletionResult) error {
args, _ := a.Settings().Get("compiler_flags").([]string)

args = append([]string{"-fsyntax-only", "-Xclang", fmt.Sprintf("-code-completion-at=%s:%d:%d", a.Location.File.Name, a.Location.Line, a.Location.Column)}, args...)
args = append(args, a.Location.File.Name)
if out, err := RunClang(args...); err != nil {
return ret, err
return err
} else if r, err := parseresult(string(out)); err != nil {
return err
} else {
return parseresult(string(out))
*ret = r
return nil
}
}
19 changes: 14 additions & 5 deletions clang/clang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ func TestClang(t *testing.T) {
if _, err := RunClang("-v"); err != nil {
t.Skipf("Couldn't launch clang: %s", err)
}
loc := content.SourceLocation{}
loc.Column = 1
loc.Line = 10
loc.File.Name = "testdata/hello.cpp"
t.Log(CompleteAt([]string{}, loc))
var (
a content.CompleteAtArgs
b content.CompletionResult
c Clang
)

a.Location.Column = 1
a.Location.Line = 4
a.Location.File.Name = "testdata/hello.cpp"
if err := c.CompleteAt(&a, &b); err != nil {
t.Error(err)
} else {
t.Log(b)
}
}

func TestParseResult(t *testing.T) {
Expand Down
Loading

0 comments on commit dd46beb

Please sign in to comment.