mirror of
https://github.com/golang/go
synced 2024-11-18 11:14:39 -07:00
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 <rfindley@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
01e0872ccf
commit
da4261a3d0
@ -6,8 +6,11 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/lsprpc"
|
||||
"golang.org/x/tools/internal/tool"
|
||||
@ -89,18 +92,10 @@ func (c *listSessions) Run(ctx context.Context, args ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Server logfile: %s\n", state.Logfile)
|
||||
fmt.Printf("Server debug address: %v\n", state.DebugAddr)
|
||||
for _, c := range state.Clients {
|
||||
if c.ClientID == state.CurrentClientID {
|
||||
// This is the client for the listsessions command itself.
|
||||
continue
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Printf("Client %s:\n", c.ClientID)
|
||||
fmt.Printf("\tsession: %s:\n", c.SessionID)
|
||||
fmt.Printf("\tlogfile: %s:\n", c.Logfile)
|
||||
fmt.Printf("\tdebug address: %s:\n", c.DebugAddr)
|
||||
v, err := json.MarshalIndent(state, "", "\t")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Stdout.Write(v)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user