From 40960b6deb8ecdb8bcde6a8f44722731939b8ddc Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 5 Feb 2019 17:27:35 -0500 Subject: [PATCH] internal/lsp/cmd: fix a nil pointer and some minor clean-up This change fixes a nil error, in addition to cleaning up a spacing error and a typo. It also fixes the golint errors in internal/lsp/cmd. Updates golang/go#30091 Change-Id: I24867bb878fda4e341f87d31bbec701a3814a341 Reviewed-on: https://go-review.googlesource.com/c/161220 Reviewed-by: Ian Cottrell Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/cmd/cmd.go | 1 + internal/lsp/cmd/location.go | 36 ++++++++++++++++++------------------ internal/lsp/cmd/query.go | 2 +- internal/lsp/cmd/server.go | 5 ++++- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index b054dcf2..694f8590 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -12,6 +12,7 @@ import ( "flag" "fmt" "go/token" + "golang.org/x/tools/go/packages" "golang.org/x/tools/internal/tool" ) diff --git a/internal/lsp/cmd/location.go b/internal/lsp/cmd/location.go index 35e25806..29372b76 100644 --- a/internal/lsp/cmd/location.go +++ b/internal/lsp/cmd/location.go @@ -99,43 +99,43 @@ func parseLocation(value string) (Location, error) { } loc.Filename = m[posReFile] if m[posReSLine] != "" { - if v, err := strconv.ParseInt(m[posReSLine], 10, 32); err != nil { + v, err := strconv.ParseInt(m[posReSLine], 10, 32) + if err != nil { return loc, err - } else { - loc.Start.Line = int(v) } - if v, err := strconv.ParseInt(m[posReSCol], 10, 32); err != nil { + loc.Start.Line = int(v) + v, err = strconv.ParseInt(m[posReSCol], 10, 32) + if err != nil { return loc, err - } else { - loc.Start.Column = int(v) } + loc.Start.Column = int(v) } else { - if v, err := strconv.ParseInt(m[posReSOff], 10, 32); err != nil { + v, err := strconv.ParseInt(m[posReSOff], 10, 32) + if err != nil { return loc, err - } else { - loc.Start.Offset = int(v) } + loc.Start.Offset = int(v) } if m[posReEnd] == "" { loc.End = loc.Start } else { if m[posReELine] != "" { - if v, err := strconv.ParseInt(m[posReELine], 10, 32); err != nil { + v, err := strconv.ParseInt(m[posReELine], 10, 32) + if err != nil { return loc, err - } else { - loc.End.Line = int(v) } - if v, err := strconv.ParseInt(m[posReECol], 10, 32); err != nil { + loc.End.Line = int(v) + v, err = strconv.ParseInt(m[posReECol], 10, 32) + if err != nil { return loc, err - } else { - loc.End.Column = int(v) } + loc.End.Column = int(v) } else { - if v, err := strconv.ParseInt(m[posReEOff], 10, 32); err != nil { + v, err := strconv.ParseInt(m[posReEOff], 10, 32) + if err != nil { return loc, err - } else { - loc.End.Offset = int(v) } + loc.End.Offset = int(v) } } return loc, nil diff --git a/internal/lsp/cmd/query.go b/internal/lsp/cmd/query.go index 3d0bf30f..5ab520f9 100644 --- a/internal/lsp/cmd/query.go +++ b/internal/lsp/cmd/query.go @@ -24,7 +24,7 @@ const ( // query implements the query command. type query struct { JSON bool `flag:"json" help:"emit output in JSON format"` - Emulate string `flag:"emulate" help:"compatability mode, causes gopls to emulate another tool.\nvalues depend on the operation being performed"` + Emulate string `flag:"emulate" help:"compatibility mode, causes gopls to emulate another tool.\nvalues depend on the operation being performed"` app *Application } diff --git a/internal/lsp/cmd/server.go b/internal/lsp/cmd/server.go index e205052f..72993e6f 100644 --- a/internal/lsp/cmd/server.go +++ b/internal/lsp/cmd/server.go @@ -101,7 +101,10 @@ func (s *Server) Run(ctx context.Context, args ...string) error { msec := int(elapsed.Round(time.Millisecond) / time.Millisecond) fmt.Fprintf(outx, " in %dms", msec) } - params := string(*payload) + params := "null" + if payload != nil { + params = string(*payload) + } if params == "null" { params = "{}" }