Skip to content

Commit

Permalink
cmd/acme-lsp: add -rpc.trace flag
Browse files Browse the repository at this point in the history
This helps with debugging LSP servers that don't do tracing.
  • Loading branch information
fhs committed Jan 11, 2020
1 parent c13a25a commit 91db24d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/lsp/acmelsp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net"
"os"
"path/filepath"
"sync"

Expand Down Expand Up @@ -99,6 +100,7 @@ type ClientConfig struct {
*config.Server
RootDirectory string // used to compute RootURI in initialization
HideDiag bool // don't write diagnostics to DiagWriter
RPCTrace bool // print LSP rpc trace to stderr
DiagWriter DiagnosticsWriter // notification handler writes diagnostics here
Workspaces []protocol.WorkspaceFolder // initial workspace folders
Logger *log.Logger
Expand All @@ -121,6 +123,9 @@ func NewClient(conn net.Conn, cfg *ClientConfig) (*Client, error) {
func (c *Client) init(conn net.Conn, cfg *ClientConfig) error {
ctx := context.Background()
stream := jsonrpc2.NewHeaderStream(conn, conn)
if cfg.RPCTrace {
stream = protocol.LoggingStream(stream, os.Stderr)
}
ctx, rpc, server := protocol.NewClient(ctx, stream, &clientHandler{
cfg: cfg,
hideDiag: cfg.HideDiag,
Expand Down
4 changes: 4 additions & 0 deletions internal/lsp/acmelsp/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type File struct {
// Format file when Put is executed in a window.
FormatOnPut bool

// Print to stderr the full rpc trace in lsp inspector format
RPCTrace bool

// LSP code actions to run when Put is executed in a window.
CodeActionsOnPut []protocol.CodeActionKind

Expand Down Expand Up @@ -247,6 +250,7 @@ func (cfg *Config) ParseFlags(flags Flags, f *flag.FlagSet, arguments []string)
f.BoolVar(&cfg.Verbose, "debug", cfg.Verbose, "turn on debugging prints (deprecated: use -v)")
f.StringVar(&cfg.RootDirectory, "rootdir", cfg.RootDirectory, "root directory used for LSP initialization")
f.BoolVar(&cfg.HideDiagnostics, "hidediag", false, "hide diagnostics sent by LSP server")
f.BoolVar(&cfg.RPCTrace, "rpc.trace", false, "print the full rpc trace in lsp inspector format")
f.StringVar(&workspaces, "workspaces", "", "colon-separated list of initial workspace directories")
f.Var(&userServers, "server", `language server command for filename match (e.g. '\.go$:gopls')`)
f.Var(&dialServers, "dial", `language server address for filename match (e.g. '\.go$:localhost:4389')`)
Expand Down
1 change: 1 addition & 0 deletions internal/lsp/acmelsp/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (ss *ServerSet) ClientConfig(info *ServerInfo) *ClientConfig {
Server: info.Server,
RootDirectory: ss.cfg.RootDirectory,
HideDiag: ss.cfg.HideDiagnostics,
RPCTrace: ss.cfg.RPCTrace,
DiagWriter: ss.diagWriter,
Workspaces: ss.Workspaces(),
Logger: info.Logger,
Expand Down

0 comments on commit 91db24d

Please sign in to comment.