Skip to content

Commit 7837af4

Browse files
committed
Created Go module, moved handler code to subpackage
1 parent 38cf645 commit 7837af4

File tree

11 files changed

+48
-27
lines changed

11 files changed

+48
-27
lines changed

go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module github.com/bcmi-labs/arduino-language-server
2+
3+
go 1.12
4+
5+
require (
6+
github.com/gorilla/websocket v1.4.0 // indirect
7+
github.com/sourcegraph/go-lsp v0.0.0-20181119182933-0c7d621186c1
8+
github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a
9+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
2+
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
3+
github.com/sourcegraph/go-lsp v0.0.0-20181119182933-0c7d621186c1 h1:O1d7nVzpGmP5pGAZBSlp9TSpjNwwI0xThxhPd9oVJuU=
4+
github.com/sourcegraph/go-lsp v0.0.0-20181119182933-0c7d621186c1/go.mod h1:tpps84QRlOVVLYk5QpKYX8Tr289D1v/UTWDLqeguiqM=
5+
github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a h1:jTZwOlrDhmk4Ez2vhWh7kA0eKUahp1lCO2uyM4fi/Qk=
6+
github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a/go.mod h1:eESpbCslcLDs8j2D7IEdGVgul7xuk9odqDTaor30IUU=

builder.go renamed to handler/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"bufio"

handler.go renamed to handler/handler.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package main
1+
package handler
22

33
import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"io"
78
"log"
89
"net/url"
910
"path/filepath"
@@ -13,16 +14,29 @@ import (
1314
"github.com/sourcegraph/jsonrpc2"
1415
)
1516

16-
func newInoHandler() *InoHandler {
17-
return &InoHandler{
17+
var enableLogging bool
18+
19+
// NewInoHandler creates and configures an InoHandler.
20+
func NewInoHandler(stdin io.ReadCloser, stdout io.WriteCloser, stdinLog, stdoutLog io.Writer,
21+
clangdIn io.ReadCloser, clangdOut io.WriteCloser, clangdinLog, clangdoutLog io.Writer,
22+
logging bool) *InoHandler {
23+
enableLogging = logging
24+
handler := &InoHandler{
1825
data: make(map[lsp.DocumentURI]*FileData),
1926
}
27+
clangdStream := jsonrpc2.NewBufferedStream(StreamReadWrite{clangdIn, clangdOut, clangdinLog, clangdoutLog}, jsonrpc2.VSCodeObjectCodec{})
28+
clangdHandler := jsonrpc2.HandlerWithError(handler.FromClangd)
29+
handler.ClangdConn = jsonrpc2.NewConn(context.Background(), clangdStream, clangdHandler)
30+
stdStream := jsonrpc2.NewBufferedStream(StreamReadWrite{stdin, stdout, stdinLog, stdoutLog}, jsonrpc2.VSCodeObjectCodec{})
31+
stdHandler := jsonrpc2.HandlerWithError(handler.FromStdio)
32+
handler.StdioConn = jsonrpc2.NewConn(context.Background(), stdStream, stdHandler)
33+
return handler
2034
}
2135

2236
// InoHandler is a JSON-RPC handler that delegates messages to clangd.
2337
type InoHandler struct {
24-
stdioConn *jsonrpc2.Conn
25-
clangdConn *jsonrpc2.Conn
38+
StdioConn *jsonrpc2.Conn
39+
ClangdConn *jsonrpc2.Conn
2640
data map[lsp.DocumentURI]*FileData
2741
}
2842

@@ -44,9 +58,9 @@ func (handler *InoHandler) FromStdio(ctx context.Context, conn *jsonrpc2.Conn, r
4458
}
4559
var result interface{}
4660
if req.Notif {
47-
err = handler.clangdConn.Notify(ctx, req.Method, params)
61+
err = handler.ClangdConn.Notify(ctx, req.Method, params)
4862
} else {
49-
result, err = sendRequest(ctx, handler.clangdConn, req.Method, params)
63+
result, err = sendRequest(ctx, handler.ClangdConn, req.Method, params)
5064
}
5165
if err != nil {
5266
log.Println("From stdio: Method:", req.Method, "Params:", params, "Error:", err)
@@ -304,9 +318,9 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
304318
}
305319
var result interface{}
306320
if req.Notif {
307-
err = handler.stdioConn.Notify(ctx, req.Method, params)
321+
err = handler.StdioConn.Notify(ctx, req.Method, params)
308322
} else {
309-
result, err = sendRequest(ctx, handler.stdioConn, req.Method, params)
323+
result, err = sendRequest(ctx, handler.StdioConn, req.Method, params)
310324
}
311325
if err != nil {
312326
log.Println("From clangd: Method:", req.Method, "Params:", params, "Error:", err)

properties.go renamed to handler/properties.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"bufio"

properties_test.go renamed to handler/properties_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"reflect"

protocol.go renamed to handler/protocol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"context"

sourcemap.go renamed to handler/sourcemap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"bufio"

sourcemap_test.go renamed to handler/sourcemap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"reflect"

stream.go renamed to handler/stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package handler
22

33
import (
44
"io"

0 commit comments

Comments
 (0)