Skip to content

Commit 0073fd3

Browse files
committed
Added error color in loggin to make errors more visible
1 parent df25ec5 commit 0073fd3

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Diff for: ls/lsp_client_clangd.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func NewClangdLSPClient(
4343
IncomingPrefix: "IDE LS <-- Clangd",
4444
OutgoingPrefix: "IDE LS --> Clangd",
4545
HiColor: color.HiRedString,
46-
LoColor: color.RedString})
46+
LoColor: color.RedString,
47+
ErrorColor: color.New(color.BgHiMagenta, color.FgHiWhite, color.BlinkSlow).Sprintf,
48+
})
4749
return client
4850
}
4951

Diff for: ls/lsp_logger.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
type LSPLogger struct {
1313
IncomingPrefix, OutgoingPrefix string
1414
HiColor, LoColor func(format string, a ...interface{}) string
15+
ErrorColor func(format string, a ...interface{}) string
1516
}
1617

1718
func (l *LSPLogger) LogOutgoingRequest(id string, method string, params json.RawMessage) {
@@ -21,7 +22,11 @@ func (l *LSPLogger) LogOutgoingCancelRequest(id string) {
2122
log.Print(l.LoColor("%s CANCEL %s", l.OutgoingPrefix, id))
2223
}
2324
func (l *LSPLogger) LogIncomingResponse(id string, method string, resp json.RawMessage, respErr *jsonrpc.ResponseError) {
24-
log.Print(l.LoColor("%s RESP %s %s", l.IncomingPrefix, method, id))
25+
e := ""
26+
if respErr != nil {
27+
e = l.ErrorColor(" ERROR: %s", respErr.AsError())
28+
}
29+
log.Print(l.LoColor("%s RESP %s %s%s", l.IncomingPrefix, method, id, e))
2530
}
2631
func (l *LSPLogger) LogOutgoingNotification(method string, params json.RawMessage) {
2732
log.Print(l.HiColor("%s NOTIF %s", l.OutgoingPrefix, method))
@@ -39,7 +44,11 @@ func (l *LSPLogger) LogIncomingCancelRequest(id string) {
3944
log.Print(l.LoColor("%s CANCEL %s", l.IncomingPrefix, id))
4045
}
4146
func (l *LSPLogger) LogOutgoingResponse(id string, method string, resp json.RawMessage, respErr *jsonrpc.ResponseError) {
42-
log.Print(l.LoColor("%s RESP %s %s", l.OutgoingPrefix, method, id))
47+
e := ""
48+
if respErr != nil {
49+
e = l.ErrorColor(" ERROR: %s", respErr.AsError())
50+
}
51+
log.Print(l.LoColor("%s RESP %s %s%s", l.OutgoingPrefix, method, id, e))
4352
}
4453
func (l *LSPLogger) LogIncomingNotification(method string, params json.RawMessage) jsonrpc.FunctionLogger {
4554
spaces := " "

Diff for: ls/lsp_server_ide.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func NewIDELSPServer(logger jsonrpc.FunctionLogger, in io.Reader, out io.Writer,
2424
IncomingPrefix: "IDE --> LS",
2525
OutgoingPrefix: "IDE <-- LS",
2626
HiColor: color.HiGreenString,
27-
LoColor: color.GreenString})
27+
LoColor: color.GreenString,
28+
ErrorColor: color.New(color.BgHiMagenta, color.FgHiWhite, color.BlinkSlow).Sprintf,
29+
})
2830
return server
2931
}
3032

0 commit comments

Comments
 (0)