Skip to content

Commit f185e1a

Browse files
committed
refactor: modernize code with Go 1.18 idioms
Replace interface{} with the any type alias throughout the codebase, as recommended since Go 1.18. Also improve logging by replacing the Debugf method with more structured DebugJSON calls and removing redundant newlines in format strings.
1 parent 2dc3177 commit f185e1a

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

golangci-lint.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package main
33
import "strings"
44

55
type Issue struct {
6-
FromLinter string `json:"FromLinter"`
7-
Text string `json:"Text"`
8-
Severity string `json:"Severity"`
9-
SourceLines []string `json:"SourceLines"`
10-
Replacement interface{} `json:"Replacement"`
6+
FromLinter string `json:"FromLinter"`
7+
Text string `json:"Text"`
8+
Severity string `json:"Severity"`
9+
SourceLines []string `json:"SourceLines"`
10+
Replacement any `json:"Replacement"`
1111
Pos struct {
1212
Filename string `json:"Filename"`
1313
Offset int `json:"Offset"`

handler.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
6464
} else {
6565
cmd.Dir = dir
6666
}
67-
h.logger.Debugf("golangci-lint-langserver: golingci-lint cmd: %v\n", cmd)
67+
68+
h.logger.DebugJSON("golangci-lint-langserver: golingci-lint cmd:", cmd.Args)
6869

6970
b, err := cmd.Output()
7071
if err == nil {
@@ -151,7 +152,7 @@ func (h *langHandler) linter() {
151152
}
152153
}
153154

154-
func (h *langHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
155+
func (h *langHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
155156
h.logger.DebugJSON("golangci-lint-langserver: request:", req)
156157

157158
switch req.Method {
@@ -176,7 +177,7 @@ func (h *langHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *json
176177
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeMethodNotFound, Message: fmt.Sprintf("method not supported: %s", req.Method)}
177178
}
178179

179-
func (h *langHandler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
180+
func (h *langHandler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
180181
var params InitializeParams
181182
if err := json.Unmarshal(*req.Params, &params); err != nil {
182183
return nil, err
@@ -198,13 +199,13 @@ func (h *langHandler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, r
198199
}, nil
199200
}
200201

201-
func (h *langHandler) handleShutdown(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (result interface{}, err error) {
202+
func (h *langHandler) handleShutdown(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (result any, err error) {
202203
close(h.request)
203204

204205
return nil, nil
205206
}
206207

207-
func (h *langHandler) handleTextDocumentDidOpen(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
208+
func (h *langHandler) handleTextDocumentDidOpen(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
208209
var params DidOpenTextDocumentParams
209210
if err := json.Unmarshal(*req.Params, &params); err != nil {
210211
return nil, err
@@ -215,15 +216,15 @@ func (h *langHandler) handleTextDocumentDidOpen(_ context.Context, _ *jsonrpc2.C
215216
return nil, nil
216217
}
217218

218-
func (h *langHandler) handleTextDocumentDidClose(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (result interface{}, err error) {
219+
func (h *langHandler) handleTextDocumentDidClose(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (result any, err error) {
219220
return nil, nil
220221
}
221222

222-
func (h *langHandler) handleTextDocumentDidChange(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (result interface{}, err error) {
223+
func (h *langHandler) handleTextDocumentDidChange(_ context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request) (result any, err error) {
223224
return nil, nil
224225
}
225226

226-
func (h *langHandler) handleTextDocumentDidSave(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
227+
func (h *langHandler) handleTextDocumentDidSave(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
227228
var params DidSaveTextDocumentParams
228229
if err := json.Unmarshal(*req.Params, &params); err != nil {
229230
return nil, err
@@ -234,6 +235,6 @@ func (h *langHandler) handleTextDocumentDidSave(_ context.Context, _ *jsonrpc2.C
234235
return nil, nil
235236
}
236237

237-
func (h *langHandler) handlerWorkspaceDidChangeConfiguration(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
238+
func (h *langHandler) handlerWorkspaceDidChangeConfiguration(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
238239
return nil, nil
239240
}

logger.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import (
99
var _ logger = (*stdLogger)(nil)
1010

1111
type logger interface {
12-
Printf(format string, args ...interface{})
13-
Debugf(format string, args ...interface{})
14-
DebugJSON(label string, arg interface{})
12+
Printf(format string, args ...any)
13+
DebugJSON(label string, arg any)
1514
}
1615

1716
type stdLogger struct {
@@ -26,15 +25,11 @@ func newStdLogger(debug bool) *stdLogger {
2625
}
2726
}
2827

29-
func (l *stdLogger) Printf(format string, args ...interface{}) {
28+
func (l *stdLogger) Printf(format string, args ...any) {
3029
l.stderr.Printf(format, args...)
3130
}
3231

33-
func (l *stdLogger) Debugf(format string, args ...interface{}) {
34-
l.stderr.Printf(format, args...)
35-
}
36-
37-
func (l *stdLogger) DebugJSON(label string, arg interface{}) {
32+
func (l *stdLogger) DebugJSON(label string, arg any) {
3833
if !l.debug {
3934
return
4035
}

0 commit comments

Comments
 (0)