Skip to content

Commit ef2e6e3

Browse files
committed
Upgrade Go to 1.20
- Update the version in `go.mod` - Change from `interface{}` to `any` - Stop using `io/ioutil`
1 parent c7ef2b1 commit ef2e6e3

26 files changed

+63
-77
lines changed

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ jobs:
1414
- name: Checkout code
1515
uses: actions/checkout@v3
1616
- name: Setup Go
17-
uses: actions/setup-go@v3
17+
uses: actions/setup-go@v4
1818
with:
1919
go-version: 1.x
2020
- name: Lint
2121
uses: golangci/golangci-lint-action@v3
2222
with:
23-
version: v1.50.1
2423
args: --verbose
2524
- name: Test
2625
run: make test

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Checkout code
1414
uses: actions/checkout@master
1515
- name: Setup Go
16-
uses: actions/setup-go@v2
16+
uses: actions/setup-go@v4
1717
with:
1818
go-version: 1.x
1919
- name: Cross build

.golangci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ linters-settings:
2525
arguments:
2626
- maxLitCount: "3"
2727
allowStrs: '""'
28-
allowInts: "0,1,2,3,4,5,0700,0660"
28+
allowInts: "0,1,2,3,4,5,0700,0660,0o700,0o660"
2929
allowFloats: "0.0,0.,1.0,1.,2.0,2."
3030
- name: blank-imports
3131
- name: context-as-argument

go.mod

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
module github.com/mattn/efm-langserver
22

3-
go 1.13
3+
go 1.20
44

55
require (
6-
github.com/kr/pretty v0.1.0 // indirect
76
github.com/mattn/go-unicodeclass v0.0.1
87
github.com/reviewdog/errorformat v0.0.0-20220309155058-b075c45b6d9a
98
github.com/sourcegraph/jsonrpc2 v0.1.0
10-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
119
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
1210
)
11+
12+
require (
13+
github.com/kr/pretty v0.1.0 // indirect
14+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
15+
)

langserver/duration.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (d Duration) MarshalJSON() ([]byte, error) {
1616

1717
// UnmarshalJSON method Unmash duration from string or decimal
1818
func (d *Duration) UnmarshalJSON(b []byte) error {
19-
var v interface{}
19+
var v any
2020
if err := json.Unmarshal(b, &v); err != nil {
2121
return err
2222
}
@@ -37,7 +37,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
3737
}
3838

3939
// UnmarshalYAML method Unmash duration from string or decimal
40-
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
40+
func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error {
4141
var s string
4242
if err := unmarshal(&s); err != nil {
4343
return err

langserver/handle_initialize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/sourcegraph/jsonrpc2"
1010
)
1111

12-
func (h *langHandler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
12+
func (h *langHandler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1313
if req.Params == nil {
1414
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1515
}

langserver/handle_shutdown.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/sourcegraph/jsonrpc2"
77
)
88

9-
func (h *langHandler) handleShutdown(_ context.Context, conn *jsonrpc2.Conn, _ *jsonrpc2.Request) (result interface{}, err error) {
9+
func (h *langHandler) handleShutdown(_ context.Context, conn *jsonrpc2.Conn, _ *jsonrpc2.Request) (result any, err error) {
1010
if h.lintTimer != nil {
1111
h.lintTimer.Stop()
1212
}

langserver/handle_text_document_code_action.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/sourcegraph/jsonrpc2"
1515
)
1616

17-
func (h *langHandler) handleTextDocumentCodeAction(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
17+
func (h *langHandler) handleTextDocumentCodeAction(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1818
if req.Params == nil {
1919
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
2020
}
@@ -27,7 +27,7 @@ func (h *langHandler) handleTextDocumentCodeAction(_ context.Context, _ *jsonrpc
2727
return h.codeAction(params.TextDocument.URI, &params)
2828
}
2929

30-
func (h *langHandler) executeCommand(params *ExecuteCommandParams) (interface{}, error) {
30+
func (h *langHandler) executeCommand(params *ExecuteCommandParams) (any, error) {
3131
if len(params.Arguments) != 1 {
3232
return nil, fmt.Errorf("invalid command")
3333
}
@@ -170,7 +170,7 @@ func filterCommands(uri DocumentURI, commands []Command) []Command {
170170
results = append(results, Command{
171171
Title: v.Title,
172172
Command: fmt.Sprintf("efm-langserver\t%s\t%s", v.Command, string(uri)),
173-
Arguments: []interface{}{string(uri)},
173+
Arguments: []any{string(uri)},
174174
})
175175
}
176176
return results

langserver/handle_text_document_completion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/sourcegraph/jsonrpc2"
1616
)
1717

18-
func (h *langHandler) handleTextDocumentCompletion(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
18+
func (h *langHandler) handleTextDocumentCompletion(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1919
if req.Params == nil {
2020
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
2121
}

langserver/handle_text_document_definition.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"io/ioutil"
98
"os"
109
"path/filepath"
1110
"runtime"
@@ -17,7 +16,7 @@ import (
1716
"github.com/sourcegraph/jsonrpc2"
1817
)
1918

20-
func (h *langHandler) handleTextDocumentDefinition(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
19+
func (h *langHandler) handleTextDocumentDefinition(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
2120
if req.Params == nil {
2221
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
2322
}
@@ -51,7 +50,7 @@ func (h *langHandler) findTag(fname string, tag string) ([]Location, error) {
5150
if token[0] == tag {
5251
token[2] = strings.TrimRight(token[2], `;"`)
5352
fullpath := filepath.Clean(filepath.Join(h.rootPath, token[1]))
54-
b, err := ioutil.ReadFile(fullpath)
53+
b, err := os.ReadFile(fullpath)
5554
if err != nil {
5655
continue
5756
}

langserver/handle_text_document_did_change.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleTextDocumentDidChange(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleTextDocumentDidChange(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}

langserver/handle_text_document_did_close.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleTextDocumentDidClose(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleTextDocumentDidClose(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}

langserver/handle_text_document_did_open.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleTextDocumentDidOpen(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleTextDocumentDidOpen(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}

langserver/handle_text_document_did_save.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleTextDocumentDidSave(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleTextDocumentDidSave(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}

langserver/handle_text_document_formatting.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/sourcegraph/jsonrpc2"
1717
)
1818

19-
func (h *langHandler) handleTextDocumentFormatting(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
19+
func (h *langHandler) handleTextDocumentFormatting(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
2020
if req.Params == nil {
2121
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
2222
}

langserver/handle_text_document_hover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/sourcegraph/jsonrpc2"
1616
)
1717

18-
func (h *langHandler) handleTextDocumentHover(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
18+
func (h *langHandler) handleTextDocumentHover(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1919
if req.Params == nil {
2020
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
2121
}

langserver/handle_text_document_symbol.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/sourcegraph/jsonrpc2"
1717
)
1818

19-
func (h *langHandler) handleTextDocumentSymbol(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
19+
func (h *langHandler) handleTextDocumentSymbol(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
2020
if req.Params == nil {
2121
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
2222
}

langserver/handle_workspace_did_change_configuration.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/sourcegraph/jsonrpc2"
99
)
1010

11-
func (h *langHandler) handleWorkspaceDidChangeConfiguration(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
11+
func (h *langHandler) handleWorkspaceDidChangeConfiguration(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1212
if req.Params == nil {
1313
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1414
}
@@ -21,7 +21,7 @@ func (h *langHandler) handleWorkspaceDidChangeConfiguration(_ context.Context, _
2121
return h.didChangeConfiguration(&params.Settings)
2222
}
2323

24-
func (h *langHandler) didChangeConfiguration(config *Config) (interface{}, error) {
24+
func (h *langHandler) didChangeConfiguration(config *Config) (any, error) {
2525
if config.Languages != nil {
2626
h.configs = *config.Languages
2727
}

langserver/handle_workspace_did_change_workspace_folders.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleDidChangeWorkspaceWorkspaceFolders(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleDidChangeWorkspaceWorkspaceFolders(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}
@@ -20,7 +20,7 @@ func (h *langHandler) handleDidChangeWorkspaceWorkspaceFolders(_ context.Context
2020
return h.didChangeWorkspaceFolders(&params)
2121
}
2222

23-
func (h *langHandler) didChangeWorkspaceFolders(params *DidChangeWorkspaceFoldersParams) (result interface{}, err error) {
23+
func (h *langHandler) didChangeWorkspaceFolders(params *DidChangeWorkspaceFoldersParams) (result any, err error) {
2424
var folders []string
2525
for _, removed := range params.Event.Removed {
2626
for _, folder := range h.folders {

langserver/handle_workspace_execute_command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleWorkspaceExecuteCommand(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleWorkspaceExecuteCommand(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}

langserver/handle_workspace_workspace_folders.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"github.com/sourcegraph/jsonrpc2"
88
)
99

10-
func (h *langHandler) handleWorkspaceWorkspaceFolders(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
10+
func (h *langHandler) handleWorkspaceWorkspaceFolders(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
1111
if req.Params == nil {
1212
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
1313
}
1414

1515
return h.workspaceFolders()
1616
}
1717

18-
func (h *langHandler) workspaceFolders() (result interface{}, err error) {
18+
func (h *langHandler) workspaceFolders() (result any, err error) {
1919
workspaces := []WorkspaceFolder{}
2020
for _, workspace := range h.folders {
2121
workspaces = append(workspaces, WorkspaceFolder{

langserver/handler.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
87
"log"
98
"net/url"
109
"os"
@@ -285,7 +284,7 @@ func matchRootPath(fname string, markers []string) string {
285284
dir := filepath.Dir(filepath.Clean(fname))
286285
var prev string
287286
for dir != prev {
288-
files, _ := ioutil.ReadDir(dir)
287+
files, _ := os.ReadDir(dir)
289288
for _, file := range files {
290289
name := file.Name()
291290
isDir := file.IsDir()
@@ -627,7 +626,7 @@ func (h *langHandler) addFolder(folder string) {
627626
}
628627
}
629628

630-
func (h *langHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
629+
func (h *langHandler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) {
631630
switch req.Method {
632631
case "initialize":
633632
return h.handleInitialize(ctx, conn, req)
@@ -677,3 +676,10 @@ func replaceCommandInputFilename(command, fname, rootPath string) string {
677676

678677
return command
679678
}
679+
680+
func succeeded(err error) bool {
681+
exitErr, ok := err.(*exec.ExitError)
682+
// When the context is canceled, the process is killed,
683+
// and the exit code is -1
684+
return ok && exitErr.ExitCode() < 0
685+
}

langserver/handler_go112.go

-7
This file was deleted.

langserver/handler_go113.go

-14
This file was deleted.

0 commit comments

Comments
 (0)