Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools / gopls@v0.5.2 / integration / parse / protocol.go
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package parse
6
7 import (
8         "log"
9
10         p "golang.org/x/tools/internal/lsp/protocol"
11 )
12
13 // Requests and notifications are fixed types
14 // Responses may be one of several types
15
16 // Requests returns a pointer to a type suitable for Unmarshal
17 func Requests(m string) interface{} {
18         // these are in the documentation's order
19         switch m {
20         case "initialize":
21                 return new(p.InitializeParams)
22         case "shutdown":
23                 return new(struct{})
24         case "window/showMessgeRequest":
25                 return new(p.ShowMessageRequestParams)
26         case "client/registerCapability":
27                 return new(p.RegistrationParams)
28         case "client/unregisterCapability":
29                 return new(p.UnregistrationParams)
30         case "workspace/workspaceFolders":
31                 return nil
32         case "workspace/configuration":
33                 return new(p.ConfigurationParams)
34         case "workspace/symbol":
35                 return new(p.WorkspaceSymbolParams)
36         case "workspace/executeCommand":
37                 return new(p.ExecuteCommandParams)
38         case "workspace/applyEdit":
39                 return new(p.ApplyWorkspaceEditParams)
40         case "textDocument/willSaveWaitUntil":
41                 return new(p.WillSaveTextDocumentParams)
42         case "textDocument/completion":
43                 return new(p.CompletionParams)
44         case "completionItem/resolve":
45                 return new(p.CompletionItem)
46         case "textDocument/hover":
47                 return new(p.TextDocumentPositionParams)
48         case "textDocument/signatureHelp":
49                 return new(p.TextDocumentPositionParams)
50         case "textDocument/declaration":
51                 return new(p.TextDocumentPositionParams)
52         case "textDocument/definition":
53                 return new(p.TextDocumentPositionParams)
54         case "textDocument/typeDefinition":
55                 return new(p.TextDocumentPositionParams)
56         case "textDocument/implementation":
57                 return new(p.TextDocumentPositionParams)
58         case "textDocument/references":
59                 return new(p.ReferenceParams)
60         case "textDocument/documentHighlight":
61                 return new(p.TextDocumentPositionParams)
62         case "textDocument/documentSymbol":
63                 return new(p.DocumentSymbolParams)
64         case "textDocument/codeAction":
65                 return new(p.CodeActionParams)
66         case "textDocument/codeLens":
67                 return new(p.CodeLensParams)
68         case "codeLens/resolve":
69                 return new(p.CodeLens)
70         case "textDocument/documentLink":
71                 return new(p.DocumentLinkParams)
72         case "documentLink/resolve":
73                 return new(p.DocumentLink)
74         case "textDocument/documentColor":
75                 return new(p.DocumentColorParams)
76         case "textDocument/colorPressentation":
77                 return new(p.ColorPresentationParams)
78         case "textDocument/formatting":
79                 return new(p.DocumentFormattingParams)
80         case "textDocument/rangeFormatting":
81                 return new(p.DocumentRangeFormattingParams)
82         case "textDocument/typeFormatting":
83                 return new(p.DocumentOnTypeFormattingParams)
84         case "textDocument/rename":
85                 return new(p.RenameParams)
86         case "textDocument/prepareRename":
87                 return new(p.TextDocumentPositionParams)
88         case "textDocument/foldingRange":
89                 return new(p.FoldingRangeParams)
90         case "textDocument/incomingCalls":
91                 return new(p.CallHierarchyIncomingCallsParams)
92         case "textDocument/outgoingCalls":
93                 return new(p.CallHierarchyOutgoingCallsParams)
94         }
95         log.Fatalf("request(%s) undefined", m)
96         return ""
97 }
98
99 // Notifs returns a pointer to a type suitable for Unmarshal
100 func Notifs(m string) interface{} {
101         switch m {
102         case "$/cancelRequest":
103                 return new(p.CancelParams)
104         case "$/setTraceNotification":
105                 return new(struct{ Value string })
106         case "client/registerCapability": // why is this a notification? (serer->client rpc)
107                 return new(p.RegistrationParams)
108         case "initialized":
109                 return new(p.InitializedParams)
110         case "exit":
111                 return nil
112         case "window/showMessage":
113                 return new(p.ShowMessageParams)
114         case "window/logMessage":
115                 return new(p.LogMessageParams)
116         case "telemetry/event":
117                 return new(interface{}) // any
118         case "workspace/didChangeWorkspaceFolders":
119                 return new(p.DidChangeWorkspaceFoldersParams)
120         case "workspace/didChangeConfiguration":
121                 return new(p.DidChangeConfigurationParams)
122         case "workspace/didChangeWatchedFiles":
123                 return new(p.DidChangeWatchedFilesParams)
124         case "textDocument/didOpen":
125                 return new(p.DidOpenTextDocumentParams)
126         case "textDocument/didChange":
127                 return new(p.DidChangeTextDocumentParams)
128         case "textDocument/willSave":
129                 return new(p.WillSaveTextDocumentParams)
130         case "textDocument/didSave":
131                 return new(p.DidSaveTextDocumentParams)
132         case "textDocument/didClose":
133                 return new(p.DidCloseTextDocumentParams)
134         case "textDocument/willClose":
135                 return new(p.DidCloseTextDocumentParams)
136         case "textDocument/publishDiagnostics":
137                 return new(p.PublishDiagnosticsParams)
138         }
139         log.Fatalf("notif(%s) undefined", m)
140         return ""
141 }
142
143 // Responses returns a slice of types, one of which should be
144 // suitable for Unmarshal
145 func Responses(m string) []interface{} {
146         switch m {
147         case "initialize":
148                 return []interface{}{new(p.InitializeResult)}
149         case "shutdown":
150                 return []interface{}{nil}
151         case "window/showMessageRequest":
152                 return []interface{}{new(p.MessageActionItem), nil}
153         case "client/registerCapability":
154                 return []interface{}{nil}
155         case "client/unregisterCapability":
156                 return []interface{}{nil}
157         case "workspace/workspaceFolder":
158                 return []interface{}{new([]p.WorkspaceFolder), nil}
159         case "workspace/configuration":
160                 return []interface{}{new([]interface{}), new(interface{})}
161         case "workspace/symbol":
162                 return []interface{}{new([]p.SymbolInformation), nil}
163         case "workspace/executeCommand":
164                 return []interface{}{new(interface{}), nil}
165         case "workspace/applyEdit":
166                 return []interface{}{new(p.ApplyWorkspaceEditResponse)}
167         case "textDocument/willSaveWaitUntil":
168                 return []interface{}{new([]p.TextEdit), nil}
169         case "textDocument/completion":
170                 return []interface{}{new(p.CompletionList), new([]p.CompletionItem), nil}
171         case "completionItem/resolve":
172                 return []interface{}{new(p.CompletionItem)}
173         case "textDocument/hover":
174                 return []interface{}{new(p.Hover), nil}
175         case "textDocument/signatureHelp":
176                 return []interface{}{new(p.SignatureHelp), nil}
177         case "textDocument/declaration":
178                 return []interface{}{new(p.Location), new([]p.Location), new([]p.LocationLink), nil}
179         case "textDocument/definition":
180                 return []interface{}{new([]p.Location), new([]p.Location), new([]p.LocationLink), nil}
181         case "textDocument/typeDefinition":
182                 return []interface{}{new([]p.Location), new([]p.LocationLink), new(p.Location), nil}
183         case "textDocument/implementation":
184                 return []interface{}{new(p.Location), new([]p.Location), new([]p.LocationLink), nil}
185         case "textDocument/references":
186                 return []interface{}{new([]p.Location), nil}
187         case "textDocument/documentHighlight":
188                 return []interface{}{new([]p.DocumentHighlight), nil}
189         case "textDocument/documentSymbol":
190                 return []interface{}{new([]p.DocumentSymbol), new([]p.SymbolInformation), nil}
191         case "textDocument/codeAction":
192                 return []interface{}{new([]p.CodeAction), new(p.Command), nil}
193         case "textDocument/codeLens":
194                 return []interface{}{new([]p.CodeLens), nil}
195         case "codelens/resolve":
196                 return []interface{}{new(p.CodeLens)}
197         case "textDocument/documentLink":
198                 return []interface{}{new([]p.DocumentLink), nil}
199         case "documentLink/resolve":
200                 return []interface{}{new(p.DocumentLink)}
201         case "textDocument/documentColor":
202                 return []interface{}{new([]p.ColorInformation)}
203         case "textDocument/colorPresentation":
204                 return []interface{}{new([]p.ColorPresentation)}
205         case "textDocument/formatting":
206                 return []interface{}{new([]p.TextEdit), nil}
207         case "textDocument/rangeFormatting":
208                 return []interface{}{new([]p.TextEdit), nil}
209         case "textDocument/onTypeFormatting":
210                 return []interface{}{new([]p.TextEdit), nil}
211         case "textDocument/rename":
212                 return []interface{}{new(p.WorkspaceEdit), nil}
213         case "textDocument/prepareRename":
214                 return []interface{}{new(p.Range), nil}
215         case "textDocument/foldingRange":
216                 return []interface{}{new([]p.FoldingRange), nil}
217         case "callHierarchy/incomingCalls":
218                 return []interface{}{new([]p.CallHierarchyIncomingCall), nil}
219         case "callHierarchy/outgoingCalls":
220                 return []interface{}{new([]p.CallHierarchyOutgoingCall), nil}
221         }
222         log.Fatalf("responses(%q) undefined", m)
223         return nil
224 }
225
226 // Msgtype given method names. Note that mSrv|mCl is possible
227 type Msgtype int
228
229 const (
230         // Mnot for notifications
231         Mnot Msgtype = 1
232         // Mreq for requests
233         Mreq Msgtype = 2
234         // Msrv for messages from the server
235         Msrv Msgtype = 4
236         // Mcl for messages from the client
237         Mcl Msgtype = 8
238 )
239
240 // IsNotify says if the message is a notification
241 func IsNotify(msg string) bool {
242         m, ok := fromMethod[msg]
243         if !ok {
244                 log.Fatalf("%q", msg)
245         }
246         return m&Mnot != 0
247 }
248
249 // FromServer says if the message is from the server
250 func FromServer(msg string) bool {
251         m, ok := fromMethod[msg]
252         if !ok {
253                 log.Fatalf("%q", msg)
254         }
255         return m&Msrv != 0
256 }
257
258 // FromClient says if the message is from the client
259 func FromClient(msg string) bool {
260         m, ok := fromMethod[msg]
261         if !ok {
262                 log.Fatalf("%q", msg)
263         }
264         return m&Mcl != 0
265 }
266
267 // rpc name to message type
268 var fromMethod = map[string]Msgtype{
269         "$/cancelRequest":             Mnot | Msrv | Mcl,
270         "initialize":                  Mreq | Msrv,
271         "initialized":                 Mnot | Mcl,
272         "shutdown":                    Mreq | Mcl,
273         "exit":                        Mnot | Mcl,
274         "window/showMessage":          Mreq | Msrv,
275         "window/logMessage":           Mnot | Msrv,
276         "telemetry'event":             Mnot | Msrv,
277         "client/registerCapability":   Mreq | Msrv,
278         "client/unregisterCapability": Mreq | Msrv,
279         "workspace/workspaceFolders":  Mreq | Msrv,
280         "workspace/workspaceDidChangeWorkspaceFolders": Mnot | Mcl,
281         "workspace/didChangeConfiguration":             Mnot | Mcl,
282         "workspace/configuration":                      Mreq | Msrv,
283         "workspace/didChangeWatchedFiles":              Mnot | Mcl,
284         "workspace/symbol":                             Mreq | Mcl,
285         "workspace/executeCommand":                     Mreq | Mcl,
286         "workspace/applyEdit":                          Mreq | Msrv,
287         "textDocument/didOpen":                         Mnot | Mcl,
288         "textDocument/didChange":                       Mnot | Mcl,
289         "textDocument/willSave":                        Mnot | Mcl,
290         "textDocument/willSaveWaitUntil":               Mreq | Mcl,
291         "textDocument/didSave":                         Mnot | Mcl,
292         "textDocument/didClose":                        Mnot | Mcl,
293         "textDocument/publishDiagnostics":              Mnot | Msrv,
294         "textDocument/completion":                      Mreq | Mcl,
295         "completionItem/resolve":                       Mreq | Mcl,
296         "textDocument/hover":                           Mreq | Mcl,
297         "textDocument/signatureHelp":                   Mreq | Mcl,
298         "textDocument/declaration":                     Mreq | Mcl,
299         "textDocument/definition":                      Mreq | Mcl,
300         "textDocument/typeDefinition":                  Mreq | Mcl,
301         "textDocument/implementation":                  Mreq | Mcl,
302         "textDocument/references":                      Mreq | Mcl,
303         "textDocument/documentHighlight":               Mreq | Mcl,
304         "textDocument/documentSymbol":                  Mreq | Mcl,
305         "textDocument/codeAction":                      Mreq | Mcl,
306         "textDocument/codeLens":                        Mreq | Mcl,
307         "codeLens/resolve":                             Mreq | Mcl,
308         "textDocument/documentLink":                    Mreq | Mcl,
309         "documentLink/resolve":                         Mreq | Mcl,
310         "textDocument/documentColor":                   Mreq | Mcl,
311         "textDocument/colorPresentation":               Mreq | Mcl,
312         "textDocument/formatting":                      Mreq | Mcl,
313         "textDocument/rangeFormatting":                 Mreq | Mcl,
314         "textDocument/onTypeFormatting":                Mreq | Mcl,
315         "textDocument/rename":                          Mreq | Mcl,
316         "textDocument/prepareRename":                   Mreq | Mcl,
317         "textDocument/foldingRange":                    Mreq | Mcl,
318         "callHierarchy/incomingCalls":                  Mreq | Mcl,
319         "callHierarchy/outgoingCalls":                  Mreq | Mcl,
320 }