Skip to content

Commit da4261a

Browse files
committed
internal/lsp/cmd: use JSON output for the inspect subcommand
I've been using the inspect command to find data about the daemon and its various sessions while debugging gopls. In practice, however, I don't simply want to view the debug information: I want to script it. This change removes the custom output formatting in favor of indented JSON, so that we can do things like the following: tail -f $(gopls inspect sessions | gq -r .logfile) Which tails the daemon logs for the current gopls binary version. Change-Id: I8895644b1493862f027e6c4b06e32612a4f3927d Reviewed-on: https://go-review.googlesource.com/c/tools/+/233357 Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 01e0872 commit da4261a

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

internal/lsp/cmd/inspect.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ package cmd
66

77
import (
88
"context"
9+
"encoding/json"
910
"flag"
1011
"fmt"
12+
"log"
13+
"os"
1114

1215
"golang.org/x/tools/internal/lsp/lsprpc"
1316
"golang.org/x/tools/internal/tool"
@@ -89,18 +92,10 @@ func (c *listSessions) Run(ctx context.Context, args ...string) error {
8992
if err != nil {
9093
return err
9194
}
92-
fmt.Printf("Server logfile: %s\n", state.Logfile)
93-
fmt.Printf("Server debug address: %v\n", state.DebugAddr)
94-
for _, c := range state.Clients {
95-
if c.ClientID == state.CurrentClientID {
96-
// This is the client for the listsessions command itself.
97-
continue
98-
}
99-
fmt.Println()
100-
fmt.Printf("Client %s:\n", c.ClientID)
101-
fmt.Printf("\tsession: %s:\n", c.SessionID)
102-
fmt.Printf("\tlogfile: %s:\n", c.Logfile)
103-
fmt.Printf("\tdebug address: %s:\n", c.DebugAddr)
95+
v, err := json.MarshalIndent(state, "", "\t")
96+
if err != nil {
97+
log.Fatal(err)
10498
}
99+
os.Stdout.Write(v)
105100
return nil
106101
}

0 commit comments

Comments
 (0)