Skip to content

Commit 70e8ff8

Browse files
authored
Merge pull request #12 from nametake/show-linter-name
Show linter name
2 parents 2f15f53 + 35ae2d2 commit 70e8ff8

File tree

4 files changed

+48
-26
lines changed

4 files changed

+48
-26
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ golangci-lint-langserver is [golangci-lint](https://github.com/golangci/golangci
1111
go get github.com/nametake/golangci-lint-langserver
1212
```
1313

14+
## Options
15+
16+
```console
17+
-debug
18+
output debug log
19+
-nolintername
20+
don't show a linter name in message
21+
```
22+
1423
## Configuration
1524

1625
You need to set golangci-lint command to initializationOptions with `--out-format json`.

golangci-lint.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package main
22

3+
type Issue struct {
4+
FromLinter string `json:"FromLinter"`
5+
Text string `json:"Text"`
6+
SourceLines []string `json:"SourceLines"`
7+
Replacement interface{} `json:"Replacement"`
8+
Pos struct {
9+
Filename string `json:"Filename"`
10+
Offset int `json:"Offset"`
11+
Line int `json:"Line"`
12+
Column int `json:"Column"`
13+
} `json:"Pos"`
14+
LineRange struct {
15+
From int `json:"From"`
16+
To int `json:"To"`
17+
} `json:"LineRange,omitempty"`
18+
}
19+
320
//nolint:unused,deadcode
421
type GolangCILintResult struct {
5-
Issues []struct {
6-
FromLinter string `json:"FromLinter"`
7-
Text string `json:"Text"`
8-
SourceLines []string `json:"SourceLines"`
9-
Replacement interface{} `json:"Replacement"`
10-
Pos struct {
11-
Filename string `json:"Filename"`
12-
Offset int `json:"Offset"`
13-
Line int `json:"Line"`
14-
Column int `json:"Column"`
15-
} `json:"Pos"`
16-
LineRange struct {
17-
From int `json:"From"`
18-
To int `json:"To"`
19-
} `json:"LineRange,omitempty"`
20-
} `json:"Issues"`
22+
Issues []Issue `json:"Issues"`
2123
Report struct {
2224
Linters []struct {
2325
Name string `json:"Name"`

handler.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ import (
1010
"github.com/sourcegraph/jsonrpc2"
1111
)
1212

13-
func NewHandler(logger logger) jsonrpc2.Handler {
13+
func NewHandler(logger logger, noLinterName bool) jsonrpc2.Handler {
1414
handler := &langHandler{
15-
logger: logger,
16-
request: make(chan DocumentURI),
15+
logger: logger,
16+
request: make(chan DocumentURI),
17+
noLinterName: noLinterName,
1718
}
1819
go handler.linter()
1920

2021
return jsonrpc2.HandlerWithError(handler.handle)
2122
}
2223

2324
type langHandler struct {
24-
logger logger
25-
conn *jsonrpc2.Conn
26-
request chan DocumentURI
27-
command []string
25+
logger logger
26+
conn *jsonrpc2.Conn
27+
request chan DocumentURI
28+
command []string
29+
noLinterName bool
2830

2931
rootURI string
3032
}
@@ -66,14 +68,22 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
6668
},
6769
Severity: DSWarning,
6870
Source: &issue.FromLinter,
69-
Message: issue.Text,
71+
Message: h.diagnosticMessage(&issue),
7072
}
7173
diagnostics = append(diagnostics, d)
7274
}
7375

7476
return diagnostics, nil
7577
}
7678

79+
func (h *langHandler) diagnosticMessage(issue *Issue) string {
80+
if h.noLinterName {
81+
return issue.Text
82+
}
83+
84+
return fmt.Sprintf("%s: %s", issue.FromLinter, issue.Text)
85+
}
86+
7787
func (h *langHandler) linter() {
7888
for {
7989
uri, ok := <-h.request

main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import (
99
)
1010

1111
func main() {
12-
debug := flag.Bool("debug", false, "show debug log")
12+
debug := flag.Bool("debug", false, "output debug log")
13+
noLinterName := flag.Bool("nolintername", false, "don't show a linter name in message")
1314

1415
flag.Parse()
1516

1617
logger := newStdLogger(*debug)
1718

18-
handler := NewHandler(logger)
19+
handler := NewHandler(logger, *noLinterName)
1920

2021
var connOpt []jsonrpc2.ConnOpt
2122

0 commit comments

Comments
 (0)