mirror of
https://github.com/laravel-ls/protocol.git
synced 2026-06-19 05:20:03 +02:00
README.md: fix indent in code example
This commit is contained in:
parent
3dcbf4fcbb
commit
39fb18c7ea
1 changed files with 23 additions and 23 deletions
46
README.md
46
README.md
|
|
@ -16,8 +16,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/sourcegraph/jsonrpc2"
|
"github.com/sourcegraph/jsonrpc2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handler(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error) {
|
func handler(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (any, error) {
|
||||||
|
|
@ -28,33 +28,33 @@ func handler(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (a
|
||||||
if err := json.Unmarshal(*req.Params, ¶ms); err != nil {
|
if err := json.Unmarshal(*req.Params, ¶ms); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// handle initialize
|
// handle initialize
|
||||||
case protocol.MethodTextDocumentDidChange:
|
case protocol.MethodTextDocumentDidChange:
|
||||||
var params protocol.DidChangeTextDocumentParams
|
var params protocol.DidChangeTextDocumentParams
|
||||||
if err := json.Unmarshal(*req.Params, ¶ms); err != nil {
|
if err := json.Unmarshal(*req.Params, ¶ms); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// handle did change
|
// handle did change
|
||||||
default:
|
default:
|
||||||
// Respond with a method not found error
|
// Respond with a method not found error
|
||||||
return nil, &jsonrpc2.Error{
|
return nil, &jsonrpc2.Error{
|
||||||
Code: jsonrpc2.CodeMethodNotFound,
|
Code: jsonrpc2.CodeMethodNotFound,
|
||||||
Message: fmt.Sprintf("Method %s not found", req.Method),
|
Message: fmt.Sprintf("Method %s not found", req.Method),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Server) Run(ctx context.Context, conn io.ReadWriteCloser) error {
|
func (s Server) Run(ctx context.Context, conn io.ReadWriteCloser) error {
|
||||||
stream := jsonrpc2.NewBufferedStream(conn, jsonrpc2.VSCodeObjectCodec{})
|
stream := jsonrpc2.NewBufferedStream(conn, jsonrpc2.VSCodeObjectCodec{})
|
||||||
rpc := jsonrpc2.NewConn(ctx, stream, jsonrpc2.HandlerWithError(s.dispatch))
|
rpc := jsonrpc2.NewConn(ctx, stream, jsonrpc2.HandlerWithError(s.dispatch))
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return fmt.Errorf("context closed")
|
return fmt.Errorf("context closed")
|
||||||
case <-rpc.DisconnectNotify():
|
case <-rpc.DisconnectNotify():
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue