Skip to content

Commit 07dcae9

Browse files
committed
WIP2
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 900487d commit 07dcae9

File tree

10 files changed

+2146
-1034
lines changed

10 files changed

+2146
-1034
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ linters:
8585
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.
8686
- stylecheck # Stylecheck is a replacement for golint
8787
- tagalign # check that struct tags are well aligned
88-
- tagliatelle # Checks the struct tags.
8988
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
9089
- testableexamples # linter checks if examples are testable (have an expected output)
9190
- thelper # thelper detects Go test helpers without t.Helper() call and checks the consistency of test helpers

client.go

Lines changed: 200 additions & 136 deletions
Large diffs are not rendered by default.

client_interface.go

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
// Copyright 2024 The Go Language Server Authors
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
package protocol
5+
6+
import (
7+
"context"
8+
9+
"go.lsp.dev/jsonrpc2"
10+
)
11+
12+
const (
13+
MethodClientCancelRequest ClientMethod = "$/cancelRequest" // bidirect client notification
14+
MethodClientProgress ClientMethod = "$/progress" // bidirect client notification
15+
MethodLogTrace ClientMethod = "$/logTrace" // client notification
16+
MethodTelemetryEvent ClientMethod = "telemetry/event" // client notification
17+
MethodTextDocumentPublishDiagnostics ClientMethod = "textDocument/publishDiagnostics" // client notification
18+
MethodWindowLogMessage ClientMethod = "window/logMessage" // client notification
19+
MethodWindowShowMessage ClientMethod = "window/showMessage" // client notification
20+
MethodClientRegisterCapability ClientMethod = "client/registerCapability" // client request
21+
MethodClientUnregisterCapability ClientMethod = "client/unregisterCapability" // client request
22+
MethodWindowShowDocument ClientMethod = "window/showDocument" // client request
23+
MethodWindowShowMessageRequest ClientMethod = "window/showMessageRequest" // client request
24+
MethodWindowWorkDoneProgressCreate ClientMethod = "window/workDoneProgress/create" // client request
25+
MethodWorkspaceApplyEdit ClientMethod = "workspace/applyEdit" // client request
26+
MethodWorkspaceCodeLensRefresh ClientMethod = "workspace/codeLens/refresh" // client request
27+
MethodWorkspaceConfiguration ClientMethod = "workspace/configuration" // client request
28+
MethodWorkspaceDiagnosticRefresh ClientMethod = "workspace/diagnostic/refresh" // client request
29+
MethodWorkspaceFoldingRangeRefresh ClientMethod = "workspace/foldingRange/refresh" // client request
30+
MethodWorkspaceInlayHintRefresh ClientMethod = "workspace/inlayHint/refresh" // client request
31+
MethodWorkspaceInlineValueRefresh ClientMethod = "workspace/inlineValue/refresh" // client request
32+
MethodWorkspaceSemanticTokensRefresh ClientMethod = "workspace/semanticTokens/refresh" // client request
33+
MethodWorkspaceWorkspaceFolders ClientMethod = "workspace/workspaceFolders" // client request
34+
)
35+
36+
type Client interface {
37+
CancelRequest(ctx context.Context, params *CancelParams) error
38+
39+
Progress(ctx context.Context, params *ProgressParams) error
40+
41+
LogTrace(ctx context.Context, params *LogTraceParams) error
42+
43+
// TelemetryEvent the telemetry event notification is sent from the server to the client to ask the client to log telemetry data.
44+
TelemetryEvent(ctx context.Context, params any) error
45+
46+
// TextDocumentPublishDiagnostics diagnostics notification are sent from the server to the client to signal results of validation runs.
47+
TextDocumentPublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error
48+
49+
// WindowLogMessage the log message notification is sent from the server to the client to ask the client to log a particular message.
50+
WindowLogMessage(ctx context.Context, params *LogMessageParams) error
51+
52+
// WindowShowMessage the show message notification is sent from a server to a client to ask the client to display a particular message in the user interface.
53+
WindowShowMessage(ctx context.Context, params *ShowMessageParams) error
54+
// ClientRegisterCapability the `client/registerCapability` request is sent from the server to the client to register a new capability handler on the client side.
55+
ClientRegisterCapability(ctx context.Context, params *RegistrationParams) error
56+
57+
// ClientUnregisterCapability the `client/unregisterCapability` request is sent from the server to the client to unregister a previously registered capability handler on the client side.
58+
ClientUnregisterCapability(ctx context.Context, params *UnregistrationParams) error
59+
60+
// WindowShowDocument a request to show a document. This request might open an external program depending on the value of the URI to open. For example a request to open `https://code.visualstudio.com/` will very likely open the URI in a WEB browser.
61+
//
62+
// @since 3.16.0
63+
WindowShowDocument(ctx context.Context, params *ShowDocumentParams) (*ShowDocumentResult, error)
64+
65+
// WindowShowMessageRequest the show message request is sent from the server to the client to show a message and a set of options actions to the user.
66+
WindowShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem, error)
67+
68+
// WindowWorkDoneProgressCreate the `window/workDoneProgress/create` request is sent from the server to the client to initiate progress reporting from the server.
69+
WindowWorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error
70+
71+
// WorkspaceApplyEdit a request sent from the server to the client to modified certain resources.
72+
WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResult, error)
73+
74+
// WorkspaceCodeLensRefresh a request to refresh all code actions
75+
//
76+
// @since 3.16.0
77+
WorkspaceCodeLensRefresh(ctx context.Context) error
78+
79+
// WorkspaceConfiguration the 'workspace/configuration' request is sent from the server to the client to fetch a certain configuration setting. This pull model replaces the old push model were the client signaled configuration
80+
// change via an event. If the server still needs to react to configuration changes (since the server caches the result of `workspace/configuration` requests) the server should register for an empty configuration change event and empty the cache if such an event is received.
81+
WorkspaceConfiguration(ctx context.Context, params *ConfigurationParams) ([]any, error)
82+
83+
// WorkspaceDiagnosticRefresh the diagnostic refresh request definition.
84+
//
85+
// @since 3.17.0
86+
WorkspaceDiagnosticRefresh(ctx context.Context) error
87+
88+
// WorkspaceFoldingRangeRefresh.
89+
//
90+
// @since 3.18.0 proposed
91+
WorkspaceFoldingRangeRefresh(ctx context.Context) error
92+
93+
// WorkspaceInlayHintRefresh.
94+
//
95+
// @since 3.17.0
96+
WorkspaceInlayHintRefresh(ctx context.Context) error
97+
98+
// WorkspaceInlineValueRefresh.
99+
//
100+
// @since 3.17.0
101+
WorkspaceInlineValueRefresh(ctx context.Context) error
102+
103+
// WorkspaceSemanticTokensRefresh.
104+
//
105+
// @since 3.16.0
106+
WorkspaceSemanticTokensRefresh(ctx context.Context) error
107+
108+
// WorkspaceWorkspaceFolders the `workspace/workspaceFolders` is sent from the server to the client to fetch the open workspace folders.
109+
WorkspaceWorkspaceFolders(ctx context.Context) ([]*WorkspaceFolder, error)
110+
}
111+
112+
// UnimplementedClient should be embedded to have forward compatible implementations.
113+
type UnimplementedClient struct{}
114+
115+
func (UnimplementedClient) CancelRequest(ctx context.Context, params *CancelParams) error {
116+
return jsonrpc2.ErrInternal
117+
}
118+
119+
func (UnimplementedClient) Progress(ctx context.Context, params *ProgressParams) error {
120+
return jsonrpc2.ErrInternal
121+
}
122+
123+
func (UnimplementedClient) LogTrace(ctx context.Context, params *LogTraceParams) error {
124+
return jsonrpc2.ErrInternal
125+
}
126+
127+
func (UnimplementedClient) TelemetryEvent(ctx context.Context, params any) error {
128+
return jsonrpc2.ErrInternal
129+
}
130+
131+
func (UnimplementedClient) TextDocumentPublishDiagnostics(ctx context.Context, params *PublishDiagnosticsParams) error {
132+
return jsonrpc2.ErrInternal
133+
}
134+
135+
func (UnimplementedClient) WindowLogMessage(ctx context.Context, params *LogMessageParams) error {
136+
return jsonrpc2.ErrInternal
137+
}
138+
139+
func (UnimplementedClient) WindowShowMessage(ctx context.Context, params *ShowMessageParams) error {
140+
return jsonrpc2.ErrInternal
141+
}
142+
143+
func (UnimplementedClient) ClientRegisterCapability(ctx context.Context, params *RegistrationParams) error {
144+
return jsonrpc2.ErrInternal
145+
}
146+
147+
func (UnimplementedClient) ClientUnregisterCapability(ctx context.Context, params *UnregistrationParams) error {
148+
return jsonrpc2.ErrInternal
149+
}
150+
151+
func (UnimplementedClient) WindowShowDocument(ctx context.Context, params *ShowDocumentParams) (*ShowDocumentResult, error) {
152+
return nil, jsonrpc2.ErrInternal
153+
}
154+
155+
func (UnimplementedClient) WindowShowMessageRequest(ctx context.Context, params *ShowMessageRequestParams) (*MessageActionItem, error) {
156+
return nil, jsonrpc2.ErrInternal
157+
}
158+
159+
func (UnimplementedClient) WindowWorkDoneProgressCreate(ctx context.Context, params *WorkDoneProgressCreateParams) error {
160+
return jsonrpc2.ErrInternal
161+
}
162+
163+
func (UnimplementedClient) WorkspaceApplyEdit(ctx context.Context, params *ApplyWorkspaceEditParams) (*ApplyWorkspaceEditResult, error) {
164+
return nil, jsonrpc2.ErrInternal
165+
}
166+
167+
func (UnimplementedClient) WorkspaceCodeLensRefresh(ctx context.Context) error {
168+
return jsonrpc2.ErrInternal
169+
}
170+
171+
func (UnimplementedClient) WorkspaceConfiguration(ctx context.Context, params *ConfigurationParams) ([]any, error) {
172+
return nil, jsonrpc2.ErrInternal
173+
}
174+
175+
func (UnimplementedClient) WorkspaceDiagnosticRefresh(ctx context.Context) error {
176+
return jsonrpc2.ErrInternal
177+
}
178+
179+
func (UnimplementedClient) WorkspaceFoldingRangeRefresh(ctx context.Context) error {
180+
return jsonrpc2.ErrInternal
181+
}
182+
183+
func (UnimplementedClient) WorkspaceInlayHintRefresh(ctx context.Context) error {
184+
return jsonrpc2.ErrInternal
185+
}
186+
187+
func (UnimplementedClient) WorkspaceInlineValueRefresh(ctx context.Context) error {
188+
return jsonrpc2.ErrInternal
189+
}
190+
191+
func (UnimplementedClient) WorkspaceSemanticTokensRefresh(ctx context.Context) error {
192+
return jsonrpc2.ErrInternal
193+
}
194+
195+
func (UnimplementedClient) WorkspaceWorkspaceFolders(ctx context.Context) ([]*WorkspaceFolder, error) {
196+
return nil, jsonrpc2.ErrInternal
197+
}

doc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
// It is a literal transcription, with unmodified comments, and only the changes
1010
// required to make it Go code.
1111
//
12-
// - Names are uppercased to export them.
12+
// Names are uppercased to export them.
1313
//
14-
// - All fields have JSON tags added to correct the names.
14+
// All fields have JSON tags added to correct the names.
1515
//
16-
// - Fields marked with a ? are also marked as "omitempty".
16+
// Fields marked with a ? are also marked as "omitempty".
1717
//
18-
// - Fields that are "|| null" are made pointers.
18+
// Fields that are "|| null" are made pointers.
1919
//
20-
// - Fields that are string or number are left as string.
20+
// Fields that are string or number are left as string.
2121
//
22-
// - Fields that are type "number" are made float64.
22+
// Fields that are type "number" are made float64.
2323
package protocol // import "go.lsp.dev/protocol"

errors.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// SPDX-FileCopyrightText: 2021 The Go Language Server Authors
1+
// Copyright 2024 The Go Language Server Authors
22
// SPDX-License-Identifier: BSD-3-Clause
33

44
package protocol
55

6-
import "go.lsp.dev/jsonrpc2"
6+
import (
7+
"go.lsp.dev/jsonrpc2"
8+
)
79

810
const (
911
// LSPReservedErrorRangeStart is the start range of LSP reserved error codes.

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ module go.lsp.dev/protocol
33
go 1.22.2
44

55
require (
6-
github.com/google/go-cmp v0.6.0
7-
github.com/segmentio/encoding v0.4.0
86
go.lsp.dev/jsonrpc2 v0.10.0
9-
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2
107
go.lsp.dev/uri v0.3.0
118
go.uber.org/zap v1.27.0
129
)
1310

1411
require (
12+
github.com/google/go-cmp v0.6.0 // indirect
1513
github.com/segmentio/asm v1.1.3 // indirect
14+
github.com/segmentio/encoding v0.4.0 // indirect
1615
go.uber.org/multierr v1.10.0 // indirect
1716
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect
1817
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
1313
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
1414
go.lsp.dev/jsonrpc2 v0.10.0 h1:Pr/YcXJoEOTMc/b6OTmcR1DPJ3mSWl/SWiU1Cct6VmI=
1515
go.lsp.dev/jsonrpc2 v0.10.0/go.mod h1:fmEzIdXPi/rf6d4uFcayi8HpFP1nBF99ERP1htC72Ac=
16-
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2 h1:hCzQgh6UcwbKgNSRurYWSqh8MufqRRPODRBblutn4TE=
17-
go.lsp.dev/pkg v0.0.0-20210717090340-384b27a52fb2/go.mod h1:gtSHRuYfbCT0qnbLnovpie/WEmqyJ7T4n6VXiFMBtcw=
1816
go.lsp.dev/uri v0.3.0 h1:KcZJmh6nFIBeJzTugn5JTU6OOyG0lDOo3R9KwTxTYbo=
1917
go.lsp.dev/uri v0.3.0/go.mod h1:P5sbO1IQR+qySTWOCnhnK7phBx+W3zbLqSMDJNTw88I=
2018
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=

protocol.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,79 @@ package protocol
55

66
import (
77
"context"
8+
"encoding/json"
9+
"io"
810

911
"go.uber.org/zap"
1012

1113
"go.lsp.dev/jsonrpc2"
1214
)
1315

16+
// MarshalFunc function type of marshal JSON data.
17+
//
18+
// Default is used [json.Marshal].
19+
type MarshalFunc func(v any) ([]byte, error)
20+
21+
var marshal MarshalFunc = json.Marshal
22+
23+
func RegiserMarshaler(fn MarshalFunc) {
24+
marshal = fn
25+
}
26+
27+
// UnmarshalFunc function type of unmarshal JSON data.
28+
//
29+
// Default is used [json.Unmarshal].
30+
type UnmarshalFunc func(data []byte, v any) error
31+
32+
var unmarshal UnmarshalFunc = json.Unmarshal
33+
34+
func RegiserUnmarshaler(fn UnmarshalFunc) {
35+
unmarshal = fn
36+
}
37+
38+
// JSONEncoder encodes and writes to the underlying data stream.
39+
type JSONEncoder interface {
40+
Encode(any) error
41+
}
42+
43+
// EncoderFunc function type of JSONEncoder.
44+
//
45+
// Default is used [json.NewEncoder] with SetEscapeHTML to false.
46+
type EncoderFunc func(io.Writer) JSONEncoder
47+
48+
var newEncoder EncoderFunc = defaultEncoder
49+
50+
func defaultEncoder(w io.Writer) JSONEncoder {
51+
enc := json.NewEncoder(w)
52+
enc.SetEscapeHTML(false)
53+
return enc
54+
}
55+
56+
func RegiserEncoder(fn EncoderFunc) {
57+
newEncoder = fn
58+
}
59+
60+
// JSONDecoder decodes and reads to the underlying data stream.
61+
type JSONDecoder interface {
62+
Decode(v any) error
63+
}
64+
65+
// DecoderFunc function type of JSONDecoder.
66+
//
67+
// Default is used [json.NewDecoder].
68+
type DecoderFunc func(io.Reader) JSONDecoder
69+
70+
var newDecoder DecoderFunc = defaultDecoder
71+
72+
func defaultDecoder(r io.Reader) JSONDecoder {
73+
dec := json.NewDecoder(r)
74+
return dec
75+
}
76+
77+
func RegiserDecoder(fn DecoderFunc) {
78+
newDecoder = fn
79+
}
80+
1481
// NewServer returns the context in which client is embedded, jsonrpc2.Conn, and the Client.
1582
func NewServer(ctx context.Context, server Server, stream jsonrpc2.Stream, logger *zap.Logger) (context.Context, jsonrpc2.Conn, Client) {
1683
conn := jsonrpc2.NewConn(stream)

0 commit comments

Comments
 (0)