aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp
diff options
context:
space:
mode:
authorIan Cottrell <iancottrell@google.com>2020-04-07 15:58:08 -0400
committerIan Cottrell <iancottrell@google.com>2020-04-10 13:25:36 +0000
commitc92aeb74389475d257b9748cb0c92d7fe45efc51 (patch)
treee204b44b4014eab2c9e592f794a5438df8f6826f /internal/lsp
parent3bd20875a2eb847946c4063e1ee3e39aad6b67ad (diff)
downloadgolang-x-tools-c92aeb74389475d257b9748cb0c92d7fe45efc51.tar.gz
internal/lsp: improve ID formatting
Replace the String method with a Format method so we can use it for extra formats. Add some tests to make sure it is all correct Change-Id: I39f361ffba036fad99c93f8c0944164f7cf199ec Reviewed-on: https://go-review.googlesource.com/c/tools/+/227486 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'internal/lsp')
-rw-r--r--internal/lsp/protocol/log.go17
1 files changed, 2 insertions, 15 deletions
diff --git a/internal/lsp/protocol/log.go b/internal/lsp/protocol/log.go
index 30fa54953..d073fd2ae 100644
--- a/internal/lsp/protocol/log.go
+++ b/internal/lsp/protocol/log.go
@@ -106,17 +106,6 @@ func (m *mapped) setServer(id string, r req) {
const eor = "\r\n\r\n\r\n"
-func strID(x *jsonrpc2.ID) string {
- if x == nil {
- // should never happen, but we need a number
- return "999999999"
- }
- if x.Name != "" {
- return x.Name
- }
- return fmt.Sprintf("%d", x.Number)
-}
-
func logCommon(outfd io.Writer, data []byte) (*Combined, time.Time, string) {
if outfd == nil {
return nil, time.Time{}, ""
@@ -141,13 +130,12 @@ func logOut(outfd io.Writer, data []byte) {
if v == nil {
return
}
+ id := fmt.Sprint(v.ID)
if v.Error != nil {
- id := strID(v.ID)
fmt.Fprintf(outfd, "[Error - %s] Received #%s %s%s", tmfmt, id, v.Error, eor)
return
}
buf := strings.Builder{}
- id := strID(v.ID)
fmt.Fprintf(&buf, "[Trace - %s] ", tmfmt) // common beginning
if v.ID != nil && v.Method != "" && v.Params != nil {
fmt.Fprintf(&buf, "Received request '%s - (%s)'.\n", v.Method, id)
@@ -194,16 +182,15 @@ func logIn(outfd io.Writer, data []byte) {
if v == nil {
return
}
+ id := fmt.Sprint(v.ID)
// ID Method Params => Sending request
// ID !Method Result(might be null, but !Params) => Sending response (could we get an Error?)
// !ID Method Params => Sending notification
if v.Error != nil { // does this ever happen?
- id := strID(v.ID)
fmt.Fprintf(outfd, "[Error - %s] Sent #%s %s%s", tmfmt, id, v.Error, eor)
return
}
buf := strings.Builder{}
- id := strID(v.ID)
fmt.Fprintf(&buf, "[Trace - %s] ", tmfmt) // common beginning
if v.ID != nil && v.Method != "" && (v.Params != nil || v.Method == "shutdown") {
fmt.Fprintf(&buf, "Sending request '%s - (%s)'.\n", v.Method, id)