Skip to content

Commit 270c49c

Browse files
committed
Made logging color more coherent
1 parent be08b32 commit 270c49c

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

Diff for: ls/lsp_client_clangd.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/arduino/arduino-cli/executils"
1111
"github.com/arduino/arduino-language-server/streams"
1212
"github.com/arduino/go-paths-helper"
13+
"github.com/fatih/color"
1314
"go.bug.st/json"
1415
"go.bug.st/lsp"
1516
"go.bug.st/lsp/jsonrpc"
@@ -38,7 +39,11 @@ func NewClangdLSPClient(
3839
ls: inoLanguageServer,
3940
}
4041
client.conn = lsp.NewClient(clangdStdio, clangdStdio, client)
41-
client.conn.SetLogger(&LSPLogger{IncomingPrefix: "IDE LS <-- Clangd", OutgoingPrefix: "IDE LS --> Clangd"})
42+
client.conn.SetLogger(&LSPLogger{
43+
IncomingPrefix: "IDE LS <-- Clangd",
44+
OutgoingPrefix: "IDE LS --> Clangd",
45+
HiColor: color.HiRedString,
46+
LoColor: color.RedString})
4247
return client
4348
}
4449

Diff for: ls/lsp_logger.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,41 @@ import (
1111

1212
type LSPLogger struct {
1313
IncomingPrefix, OutgoingPrefix string
14+
HiColor, LoColor func(format string, a ...interface{}) string
1415
}
1516

1617
func (l *LSPLogger) LogOutgoingRequest(id string, method string, params json.RawMessage) {
17-
log.Print(color.HiGreenString("%s REQU %s %s", l.OutgoingPrefix, method, id))
18+
log.Print(l.HiColor("%s REQU %s %s", l.OutgoingPrefix, method, id))
1819
}
1920
func (l *LSPLogger) LogOutgoingCancelRequest(id string) {
20-
log.Print(color.GreenString("%s CANCEL %s", l.OutgoingPrefix, id))
21+
log.Print(l.LoColor("%s CANCEL %s", l.OutgoingPrefix, id))
2122
}
2223
func (l *LSPLogger) LogIncomingResponse(id string, method string, resp json.RawMessage, respErr *jsonrpc.ResponseError) {
23-
log.Print(color.GreenString("%s RESP %s %s", l.IncomingPrefix, method, id))
24+
log.Print(l.LoColor("%s RESP %s %s", l.IncomingPrefix, method, id))
2425
}
2526
func (l *LSPLogger) LogOutgoingNotification(method string, params json.RawMessage) {
26-
log.Print(color.HiGreenString("%s NOTIF %s", l.OutgoingPrefix, method))
27+
log.Print(l.HiColor("%s NOTIF %s", l.OutgoingPrefix, method))
2728
}
2829

2930
func (l *LSPLogger) LogIncomingRequest(id string, method string, params json.RawMessage) jsonrpc.FunctionLogger {
3031
spaces := " "
31-
log.Print(color.HiRedString(fmt.Sprintf("%s REQU %s %s", l.IncomingPrefix, method, id)))
32+
log.Print(l.HiColor(fmt.Sprintf("%s REQU %s %s", l.IncomingPrefix, method, id)))
3233
return &LSPFunctionLogger{
33-
colorFunc: color.HiRedString,
34+
colorFunc: l.HiColor,
3435
prefix: fmt.Sprintf("%s %s %s", spaces[:len(l.IncomingPrefix)], method, id),
3536
}
3637
}
3738
func (l *LSPLogger) LogIncomingCancelRequest(id string) {
38-
log.Print(color.RedString("%s CANCEL %s", l.IncomingPrefix, id))
39+
log.Print(l.LoColor("%s CANCEL %s", l.IncomingPrefix, id))
3940
}
4041
func (l *LSPLogger) LogOutgoingResponse(id string, method string, resp json.RawMessage, respErr *jsonrpc.ResponseError) {
41-
log.Print(color.RedString("%s RESP %s %s", l.OutgoingPrefix, method, id))
42+
log.Print(l.LoColor("%s RESP %s %s", l.OutgoingPrefix, method, id))
4243
}
4344
func (l *LSPLogger) LogIncomingNotification(method string, params json.RawMessage) jsonrpc.FunctionLogger {
4445
spaces := " "
45-
log.Print(color.HiRedString(fmt.Sprintf("%s NOTIF %s", l.IncomingPrefix, method)))
46+
log.Print(l.HiColor(fmt.Sprintf("%s NOTIF %s", l.IncomingPrefix, method)))
4647
return &LSPFunctionLogger{
47-
colorFunc: color.HiRedString,
48+
colorFunc: l.HiColor,
4849
prefix: fmt.Sprintf("%s %s", spaces[:len(l.IncomingPrefix)], method),
4950
}
5051
}

Diff for: ls/lsp_server_ide.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"io"
66

7+
"github.com/fatih/color"
78
"go.bug.st/json"
89
"go.bug.st/lsp"
910
"go.bug.st/lsp/jsonrpc"
@@ -19,7 +20,11 @@ func NewIDELSPServer(logger jsonrpc.FunctionLogger, in io.Reader, out io.Writer,
1920
ls: ls,
2021
}
2122
server.conn = lsp.NewServer(in, out, server)
22-
server.conn.SetLogger(&LSPLogger{IncomingPrefix: "IDE --> LS", OutgoingPrefix: "IDE <-- LS"})
23+
server.conn.SetLogger(&LSPLogger{
24+
IncomingPrefix: "IDE --> LS",
25+
OutgoingPrefix: "IDE <-- LS",
26+
HiColor: color.HiGreenString,
27+
LoColor: color.GreenString})
2328
return server
2429
}
2530

0 commit comments

Comments
 (0)