| 1 |
package lsp |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"encoding/base64" |
| 6 |
"encoding/binary" |
| 7 |
"encoding/json" |
| 8 |
"strings" |
| 9 |
) |
| 10 |
|
| 11 |
type None struct{} |
| 12 |
|
| 13 |
type InitializeParams struct { |
| 14 |
ProcessID int `json:"processId,omitempty"` |
| 15 |
|
| 16 |
|
| 17 |
RootPath string `json:"rootPath,omitempty"` |
| 18 |
|
| 19 |
RootURI DocumentURI `json:"rootUri,omitempty"` |
| 20 |
ClientInfo ClientInfo `json:"clientInfo,omitempty"` |
| 21 |
Trace Trace `json:"trace,omitempty"` |
| 22 |
InitializationOptions interface{} `json:"initializationOptions,omitempty"` |
| 23 |
Capabilities ClientCapabilities `json:"capabilities"` |
| 24 |
|
| 25 |
WorkDoneToken string `json:"workDoneToken,omitempty"` |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
func (p *InitializeParams) Root() DocumentURI { |
| 30 |
if p.RootURI != "" { |
| 31 |
return p.RootURI |
| 32 |
} |
| 33 |
if strings.HasPrefix(p.RootPath, "file://") { |
| 34 |
return DocumentURI(p.RootPath) |
| 35 |
} |
| 36 |
return DocumentURI("file://" + p.RootPath) |
| 37 |
} |
| 38 |
|
| 39 |
type DocumentURI string |
| 40 |
|
| 41 |
type ClientInfo struct { |
| 42 |
Name string `json:"name,omitempty"` |
| 43 |
Version string `json:"version,omitempty"` |
| 44 |
} |
| 45 |
|
| 46 |
type Trace string |
| 47 |
|
| 48 |
type ClientCapabilities struct { |
| 49 |
Workspace WorkspaceClientCapabilities `json:"workspace,omitempty"` |
| 50 |
TextDocument TextDocumentClientCapabilities `json:"textDocument,omitempty"` |
| 51 |
Window WindowClientCapabilities `json:"window,omitempty"` |
| 52 |
Experimental interface{} `json:"experimental,omitempty"` |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
XFilesProvider bool `json:"xfilesProvider,omitempty"` |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
XContentProvider bool `json:"xcontentProvider,omitempty"` |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
XCacheProvider bool `json:"xcacheProvider,omitempty"` |
| 68 |
} |
| 69 |
|
| 70 |
type WorkspaceClientCapabilities struct { |
| 71 |
WorkspaceEdit struct { |
| 72 |
DocumentChanges bool `json:"documentChanges,omitempty"` |
| 73 |
ResourceOperations []string `json:"resourceOperations,omitempty"` |
| 74 |
} `json:"workspaceEdit,omitempty"` |
| 75 |
|
| 76 |
ApplyEdit bool `json:"applyEdit,omitempty"` |
| 77 |
|
| 78 |
Symbol struct { |
| 79 |
SymbolKind struct { |
| 80 |
ValueSet []int `json:"valueSet,omitempty"` |
| 81 |
} `json:"symbolKind,omitEmpty"` |
| 82 |
} `json:"symbol,omitempty"` |
| 83 |
|
| 84 |
ExecuteCommand *struct { |
| 85 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 86 |
} `json:"executeCommand,omitempty"` |
| 87 |
|
| 88 |
DidChangeWatchedFiles *struct { |
| 89 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 90 |
} `json:"didChangeWatchedFiles,omitempty"` |
| 91 |
|
| 92 |
WorkspaceFolders bool `json:"workspaceFolders,omitempty"` |
| 93 |
|
| 94 |
Configuration bool `json:"configuration,omitempty"` |
| 95 |
} |
| 96 |
|
| 97 |
type TextDocumentClientCapabilities struct { |
| 98 |
Declaration *struct { |
| 99 |
LinkSupport bool `json:"linkSupport,omitempty"` |
| 100 |
} `json:"declaration,omitempty"` |
| 101 |
|
| 102 |
Definition *struct { |
| 103 |
LinkSupport bool `json:"linkSupport,omitempty"` |
| 104 |
} `json:"definition,omitempty"` |
| 105 |
|
| 106 |
Implementation *struct { |
| 107 |
LinkSupport bool `json:"linkSupport,omitempty"` |
| 108 |
|
| 109 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 110 |
} `json:"implementation,omitempty"` |
| 111 |
|
| 112 |
TypeDefinition *struct { |
| 113 |
LinkSupport bool `json:"linkSupport,omitempty"` |
| 114 |
} `json:"typeDefinition,omitempty"` |
| 115 |
|
| 116 |
Synchronization *struct { |
| 117 |
WillSave bool `json:"willSave,omitempty"` |
| 118 |
DidSave bool `json:"didSave,omitempty"` |
| 119 |
WillSaveWaitUntil bool `json:"willSaveWaitUntil,omitempty"` |
| 120 |
} `json:"synchronization,omitempty"` |
| 121 |
|
| 122 |
DocumentSymbol struct { |
| 123 |
SymbolKind struct { |
| 124 |
ValueSet []int `json:"valueSet,omitempty"` |
| 125 |
} `json:"symbolKind,omitEmpty"` |
| 126 |
|
| 127 |
HierarchicalDocumentSymbolSupport bool `json:"hierarchicalDocumentSymbolSupport,omitempty"` |
| 128 |
} `json:"documentSymbol,omitempty"` |
| 129 |
|
| 130 |
Formatting *struct { |
| 131 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 132 |
} `json:"formatting,omitempty"` |
| 133 |
|
| 134 |
RangeFormatting *struct { |
| 135 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 136 |
} `json:"rangeFormatting,omitempty"` |
| 137 |
|
| 138 |
Rename *struct { |
| 139 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 140 |
|
| 141 |
PrepareSupport bool `json:"prepareSupport,omitempty"` |
| 142 |
} `json:"rename,omitempty"` |
| 143 |
|
| 144 |
SemanticHighlightingCapabilities *struct { |
| 145 |
SemanticHighlighting bool `json:"semanticHighlighting,omitempty"` |
| 146 |
} `json:"semanticHighlightingCapabilities,omitempty"` |
| 147 |
|
| 148 |
CodeAction struct { |
| 149 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 150 |
|
| 151 |
IsPreferredSupport bool `json:"isPreferredSupport,omitempty"` |
| 152 |
|
| 153 |
CodeActionLiteralSupport struct { |
| 154 |
CodeActionKind struct { |
| 155 |
ValueSet []CodeActionKind `json:"valueSet,omitempty"` |
| 156 |
} `json:"codeActionKind,omitempty"` |
| 157 |
} `json:"codeActionLiteralSupport,omitempty"` |
| 158 |
} `json:"codeAction,omitempty"` |
| 159 |
|
| 160 |
Completion struct { |
| 161 |
CompletionItem struct { |
| 162 |
DocumentationFormat []DocumentationFormat `json:"documentationFormat,omitempty"` |
| 163 |
SnippetSupport bool `json:"snippetSupport,omitempty"` |
| 164 |
} `json:"completionItem,omitempty"` |
| 165 |
|
| 166 |
CompletionItemKind struct { |
| 167 |
ValueSet []CompletionItemKind `json:"valueSet,omitempty"` |
| 168 |
} `json:"completionItemKind,omitempty"` |
| 169 |
|
| 170 |
ContextSupport bool `json:"contextSupport,omitempty"` |
| 171 |
} `json:"completion,omitempty"` |
| 172 |
|
| 173 |
SignatureHelp *struct { |
| 174 |
SignatureInformation struct { |
| 175 |
ParameterInformation struct { |
| 176 |
LabelOffsetSupport bool `json:"labelOffsetSupport,omitempty"` |
| 177 |
} `json:"parameterInformation,omitempty"` |
| 178 |
} `json:"signatureInformation,omitempty"` |
| 179 |
} `json:"signatureHelp,omitempty"` |
| 180 |
|
| 181 |
DocumentLink *struct { |
| 182 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 183 |
|
| 184 |
TooltipSupport bool `json:"tooltipSupport,omitempty"` |
| 185 |
} `json:"documentLink,omitempty"` |
| 186 |
|
| 187 |
Hover *struct { |
| 188 |
ContentFormat []string `json:"contentFormat,omitempty"` |
| 189 |
} `json:"hover,omitempty"` |
| 190 |
|
| 191 |
FoldingRange *struct { |
| 192 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 193 |
|
| 194 |
RangeLimit interface{} `json:"rangeLimit,omitempty"` |
| 195 |
|
| 196 |
LineFoldingOnly bool `json:"lineFoldingOnly,omitempty"` |
| 197 |
} `json:"foldingRange,omitempty"` |
| 198 |
|
| 199 |
CallHierarchy *struct { |
| 200 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 201 |
} `json:"callHierarchy,omitempty"` |
| 202 |
|
| 203 |
ColorProvider *struct { |
| 204 |
DynamicRegistration bool `json:"dynamicRegistration,omitempty"` |
| 205 |
} `json:"colorProvider,omitempty"` |
| 206 |
} |
| 207 |
|
| 208 |
type WindowClientCapabilities struct { |
| 209 |
WorkDoneProgress bool `json:"workDoneProgress,omitempty"` |
| 210 |
} |
| 211 |
|
| 212 |
type InitializeResult struct { |
| 213 |
Capabilities ServerCapabilities `json:"capabilities,omitempty"` |
| 214 |
} |
| 215 |
|
| 216 |
type InitializeError struct { |
| 217 |
Retry bool `json:"retry"` |
| 218 |
} |
| 219 |
|
| 220 |
type ResourceOperation string |
| 221 |
|
| 222 |
const ( |
| 223 |
ROCreate ResourceOperation = "create" |
| 224 |
RODelete ResourceOperation = "delete" |
| 225 |
RORename ResourceOperation = "rename" |
| 226 |
) |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
type TextDocumentSyncKind int |
| 233 |
|
| 234 |
const ( |
| 235 |
TDSKNone TextDocumentSyncKind = 0 |
| 236 |
TDSKFull TextDocumentSyncKind = 1 |
| 237 |
TDSKIncremental TextDocumentSyncKind = 2 |
| 238 |
) |
| 239 |
|
| 240 |
type TextDocumentSyncOptions struct { |
| 241 |
OpenClose bool `json:"openClose,omitempty"` |
| 242 |
Change TextDocumentSyncKind `json:"change"` |
| 243 |
WillSave bool `json:"willSave,omitempty"` |
| 244 |
WillSaveWaitUntil bool `json:"willSaveWaitUntil,omitempty"` |
| 245 |
Save *SaveOptions `json:"save,omitempty"` |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
type TextDocumentSyncOptionsOrKind struct { |
| 252 |
Kind *TextDocumentSyncKind |
| 253 |
Options *TextDocumentSyncOptions |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
func (v *TextDocumentSyncOptionsOrKind) MarshalJSON() ([]byte, error) { |
| 258 |
if v == nil { |
| 259 |
return []byte("null"), nil |
| 260 |
} |
| 261 |
if v.Kind != nil { |
| 262 |
return json.Marshal(v.Kind) |
| 263 |
} |
| 264 |
return json.Marshal(v.Options) |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
func (v *TextDocumentSyncOptionsOrKind) UnmarshalJSON(data []byte) error { |
| 269 |
if bytes.Equal(data, []byte("null")) { |
| 270 |
*v = TextDocumentSyncOptionsOrKind{} |
| 271 |
return nil |
| 272 |
} |
| 273 |
var kind TextDocumentSyncKind |
| 274 |
if err := json.Unmarshal(data, &kind); err == nil { |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
*v = TextDocumentSyncOptionsOrKind{ |
| 281 |
Options: &TextDocumentSyncOptions{OpenClose: true, Change: kind}, |
| 282 |
Kind: &kind, |
| 283 |
} |
| 284 |
return nil |
| 285 |
} |
| 286 |
var tmp TextDocumentSyncOptions |
| 287 |
if err := json.Unmarshal(data, &tmp); err != nil { |
| 288 |
return err |
| 289 |
} |
| 290 |
*v = TextDocumentSyncOptionsOrKind{Options: &tmp} |
| 291 |
return nil |
| 292 |
} |
| 293 |
|
| 294 |
type SaveOptions struct { |
| 295 |
IncludeText bool `json:"includeText"` |
| 296 |
} |
| 297 |
|
| 298 |
type ServerCapabilities struct { |
| 299 |
TextDocumentSync *TextDocumentSyncOptionsOrKind `json:"textDocumentSync,omitempty"` |
| 300 |
HoverProvider bool `json:"hoverProvider,omitempty"` |
| 301 |
CompletionProvider *CompletionOptions `json:"completionProvider,omitempty"` |
| 302 |
SignatureHelpProvider *SignatureHelpOptions `json:"signatureHelpProvider,omitempty"` |
| 303 |
DefinitionProvider bool `json:"definitionProvider,omitempty"` |
| 304 |
TypeDefinitionProvider bool `json:"typeDefinitionProvider,omitempty"` |
| 305 |
ReferencesProvider bool `json:"referencesProvider,omitempty"` |
| 306 |
DocumentHighlightProvider bool `json:"documentHighlightProvider,omitempty"` |
| 307 |
DocumentSymbolProvider bool `json:"documentSymbolProvider,omitempty"` |
| 308 |
WorkspaceSymbolProvider bool `json:"workspaceSymbolProvider,omitempty"` |
| 309 |
ImplementationProvider bool `json:"implementationProvider,omitempty"` |
| 310 |
CodeActionProvider bool `json:"codeActionProvider,omitempty"` |
| 311 |
CodeLensProvider *CodeLensOptions `json:"codeLensProvider,omitempty"` |
| 312 |
DocumentFormattingProvider bool `json:"documentFormattingProvider,omitempty"` |
| 313 |
DocumentRangeFormattingProvider bool `json:"documentRangeFormattingProvider,omitempty"` |
| 314 |
DocumentOnTypeFormattingProvider *DocumentOnTypeFormattingOptions `json:"documentOnTypeFormattingProvider,omitempty"` |
| 315 |
RenameProvider bool `json:"renameProvider,omitempty"` |
| 316 |
ExecuteCommandProvider *ExecuteCommandOptions `json:"executeCommandProvider,omitempty"` |
| 317 |
SemanticHighlighting *SemanticHighlightingOptions `json:"semanticHighlighting,omitempty"` |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
XWorkspaceReferencesProvider bool `json:"xworkspaceReferencesProvider,omitempty"` |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
XDefinitionProvider bool `json:"xdefinitionProvider,omitempty"` |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
XWorkspaceSymbolByProperties bool `json:"xworkspaceSymbolByProperties,omitempty"` |
| 331 |
|
| 332 |
Experimental interface{} `json:"experimental,omitempty"` |
| 333 |
} |
| 334 |
|
| 335 |
type CompletionOptions struct { |
| 336 |
ResolveProvider bool `json:"resolveProvider,omitempty"` |
| 337 |
TriggerCharacters []string `json:"triggerCharacters,omitempty"` |
| 338 |
} |
| 339 |
|
| 340 |
type DocumentOnTypeFormattingOptions struct { |
| 341 |
FirstTriggerCharacter string `json:"firstTriggerCharacter"` |
| 342 |
MoreTriggerCharacter []string `json:"moreTriggerCharacter,omitempty"` |
| 343 |
} |
| 344 |
|
| 345 |
type CodeLensOptions struct { |
| 346 |
ResolveProvider bool `json:"resolveProvider,omitempty"` |
| 347 |
} |
| 348 |
|
| 349 |
type SignatureHelpOptions struct { |
| 350 |
TriggerCharacters []string `json:"triggerCharacters,omitempty"` |
| 351 |
} |
| 352 |
|
| 353 |
type ExecuteCommandOptions struct { |
| 354 |
Commands []string `json:"commands"` |
| 355 |
} |
| 356 |
|
| 357 |
type ExecuteCommandParams struct { |
| 358 |
Command string `json:"command"` |
| 359 |
Arguments []interface{} `json:"arguments,omitempty"` |
| 360 |
} |
| 361 |
|
| 362 |
type SemanticHighlightingOptions struct { |
| 363 |
Scopes [][]string `json:"scopes,omitempty"` |
| 364 |
} |
| 365 |
|
| 366 |
type CompletionItemKind int |
| 367 |
|
| 368 |
const ( |
| 369 |
_ CompletionItemKind = iota |
| 370 |
CIKText |
| 371 |
CIKMethod |
| 372 |
CIKFunction |
| 373 |
CIKConstructor |
| 374 |
CIKField |
| 375 |
CIKVariable |
| 376 |
CIKClass |
| 377 |
CIKInterface |
| 378 |
CIKModule |
| 379 |
CIKProperty |
| 380 |
CIKUnit |
| 381 |
CIKValue |
| 382 |
CIKEnum |
| 383 |
CIKKeyword |
| 384 |
CIKSnippet |
| 385 |
CIKColor |
| 386 |
CIKFile |
| 387 |
CIKReference |
| 388 |
CIKFolder |
| 389 |
CIKEnumMember |
| 390 |
CIKConstant |
| 391 |
CIKStruct |
| 392 |
CIKEvent |
| 393 |
CIKOperator |
| 394 |
CIKTypeParameter |
| 395 |
) |
| 396 |
|
| 397 |
func (c CompletionItemKind) String() string { |
| 398 |
return completionItemKindName[c] |
| 399 |
} |
| 400 |
|
| 401 |
var completionItemKindName = map[CompletionItemKind]string{ |
| 402 |
CIKText: "text", |
| 403 |
CIKMethod: "method", |
| 404 |
CIKFunction: "function", |
| 405 |
CIKConstructor: "constructor", |
| 406 |
CIKField: "field", |
| 407 |
CIKVariable: "variable", |
| 408 |
CIKClass: "class", |
| 409 |
CIKInterface: "interface", |
| 410 |
CIKModule: "module", |
| 411 |
CIKProperty: "property", |
| 412 |
CIKUnit: "unit", |
| 413 |
CIKValue: "value", |
| 414 |
CIKEnum: "enum", |
| 415 |
CIKKeyword: "keyword", |
| 416 |
CIKSnippet: "snippet", |
| 417 |
CIKColor: "color", |
| 418 |
CIKFile: "file", |
| 419 |
CIKReference: "reference", |
| 420 |
CIKFolder: "folder", |
| 421 |
CIKEnumMember: "enumMember", |
| 422 |
CIKConstant: "constant", |
| 423 |
CIKStruct: "struct", |
| 424 |
CIKEvent: "event", |
| 425 |
CIKOperator: "operator", |
| 426 |
CIKTypeParameter: "typeParameter", |
| 427 |
} |
| 428 |
|
| 429 |
type CompletionItem struct { |
| 430 |
Label string `json:"label"` |
| 431 |
Kind CompletionItemKind `json:"kind,omitempty"` |
| 432 |
Detail string `json:"detail,omitempty"` |
| 433 |
Documentation string `json:"documentation,omitempty"` |
| 434 |
SortText string `json:"sortText,omitempty"` |
| 435 |
FilterText string `json:"filterText,omitempty"` |
| 436 |
InsertText string `json:"insertText,omitempty"` |
| 437 |
InsertTextFormat InsertTextFormat `json:"insertTextFormat,omitempty"` |
| 438 |
TextEdit *TextEdit `json:"textEdit,omitempty"` |
| 439 |
Data interface{} `json:"data,omitempty"` |
| 440 |
} |
| 441 |
|
| 442 |
type CompletionList struct { |
| 443 |
IsIncomplete bool `json:"isIncomplete"` |
| 444 |
Items []CompletionItem `json:"items"` |
| 445 |
} |
| 446 |
|
| 447 |
type CompletionTriggerKind int |
| 448 |
|
| 449 |
const ( |
| 450 |
CTKInvoked CompletionTriggerKind = 1 |
| 451 |
CTKTriggerCharacter = 2 |
| 452 |
) |
| 453 |
|
| 454 |
type DocumentationFormat string |
| 455 |
|
| 456 |
const ( |
| 457 |
DFPlainText DocumentationFormat = "plaintext" |
| 458 |
) |
| 459 |
|
| 460 |
type CodeActionKind string |
| 461 |
|
| 462 |
const ( |
| 463 |
CAKEmpty CodeActionKind = "" |
| 464 |
CAKQuickFix CodeActionKind = "quickfix" |
| 465 |
CAKRefactor CodeActionKind = "refactor" |
| 466 |
CAKRefactorExtract CodeActionKind = "refactor.extract" |
| 467 |
CAKRefactorInline CodeActionKind = "refactor.inline" |
| 468 |
CAKRefactorRewrite CodeActionKind = "refactor.rewrite" |
| 469 |
CAKSource CodeActionKind = "source" |
| 470 |
CAKSourceOrganizeImports CodeActionKind = "source.organizeImports" |
| 471 |
) |
| 472 |
|
| 473 |
type InsertTextFormat int |
| 474 |
|
| 475 |
const ( |
| 476 |
ITFPlainText InsertTextFormat = 1 |
| 477 |
ITFSnippet = 2 |
| 478 |
) |
| 479 |
|
| 480 |
type CompletionContext struct { |
| 481 |
TriggerKind CompletionTriggerKind `json:"triggerKind"` |
| 482 |
TriggerCharacter string `json:"triggerCharacter,omitempty"` |
| 483 |
} |
| 484 |
|
| 485 |
type CompletionParams struct { |
| 486 |
TextDocumentPositionParams |
| 487 |
Context CompletionContext `json:"context,omitempty"` |
| 488 |
} |
| 489 |
|
| 490 |
type Hover struct { |
| 491 |
Contents []MarkedString `json:"contents"` |
| 492 |
Range *Range `json:"range,omitempty"` |
| 493 |
} |
| 494 |
|
| 495 |
type hover Hover |
| 496 |
|
| 497 |
func (h Hover) MarshalJSON() ([]byte, error) { |
| 498 |
if h.Contents == nil { |
| 499 |
return json.Marshal(hover{ |
| 500 |
Contents: []MarkedString{}, |
| 501 |
Range: h.Range, |
| 502 |
}) |
| 503 |
} |
| 504 |
return json.Marshal(hover(h)) |
| 505 |
} |
| 506 |
|
| 507 |
type MarkedString markedString |
| 508 |
|
| 509 |
type markedString struct { |
| 510 |
Language string `json:"language"` |
| 511 |
Value string `json:"value"` |
| 512 |
|
| 513 |
isRawString bool |
| 514 |
} |
| 515 |
|
| 516 |
func (m *MarkedString) UnmarshalJSON(data []byte) error { |
| 517 |
if d := strings.TrimSpace(string(data)); len(d) > 0 && d[0] == '"' { |
| 518 |
|
| 519 |
var s string |
| 520 |
if err := json.Unmarshal(data, &s); err != nil { |
| 521 |
return err |
| 522 |
} |
| 523 |
m.Value = s |
| 524 |
m.isRawString = true |
| 525 |
return nil |
| 526 |
} |
| 527 |
|
| 528 |
ms := (*markedString)(m) |
| 529 |
return json.Unmarshal(data, ms) |
| 530 |
} |
| 531 |
|
| 532 |
func (m MarkedString) MarshalJSON() ([]byte, error) { |
| 533 |
if m.isRawString { |
| 534 |
return json.Marshal(m.Value) |
| 535 |
} |
| 536 |
return json.Marshal((markedString)(m)) |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
func RawMarkedString(s string) MarkedString { |
| 542 |
return MarkedString{Value: s, isRawString: true} |
| 543 |
} |
| 544 |
|
| 545 |
type SignatureHelp struct { |
| 546 |
Signatures []SignatureInformation `json:"signatures"` |
| 547 |
ActiveSignature int `json:"activeSignature"` |
| 548 |
ActiveParameter int `json:"activeParameter"` |
| 549 |
} |
| 550 |
|
| 551 |
type SignatureInformation struct { |
| 552 |
Label string `json:"label"` |
| 553 |
Documentation string `json:"documentation,omitempty"` |
| 554 |
Parameters []ParameterInformation `json:"parameters,omitempty"` |
| 555 |
} |
| 556 |
|
| 557 |
type ParameterInformation struct { |
| 558 |
Label string `json:"label"` |
| 559 |
Documentation string `json:"documentation,omitempty"` |
| 560 |
} |
| 561 |
|
| 562 |
type ReferenceContext struct { |
| 563 |
IncludeDeclaration bool `json:"includeDeclaration"` |
| 564 |
|
| 565 |
|
| 566 |
XLimit int `json:"xlimit,omitempty"` |
| 567 |
} |
| 568 |
|
| 569 |
type ReferenceParams struct { |
| 570 |
TextDocumentPositionParams |
| 571 |
Context ReferenceContext `json:"context"` |
| 572 |
} |
| 573 |
|
| 574 |
type DocumentHighlightKind int |
| 575 |
|
| 576 |
const ( |
| 577 |
Text DocumentHighlightKind = 1 |
| 578 |
Read = 2 |
| 579 |
Write = 3 |
| 580 |
) |
| 581 |
|
| 582 |
type DocumentHighlight struct { |
| 583 |
Range Range `json:"range"` |
| 584 |
Kind int `json:"kind,omitempty"` |
| 585 |
} |
| 586 |
|
| 587 |
type DocumentSymbolParams struct { |
| 588 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 589 |
} |
| 590 |
|
| 591 |
type SymbolKind int |
| 592 |
|
| 593 |
|
| 594 |
const ( |
| 595 |
SKFile SymbolKind = 1 |
| 596 |
SKModule SymbolKind = 2 |
| 597 |
SKNamespace SymbolKind = 3 |
| 598 |
SKPackage SymbolKind = 4 |
| 599 |
SKClass SymbolKind = 5 |
| 600 |
SKMethod SymbolKind = 6 |
| 601 |
SKProperty SymbolKind = 7 |
| 602 |
SKField SymbolKind = 8 |
| 603 |
SKConstructor SymbolKind = 9 |
| 604 |
SKEnum SymbolKind = 10 |
| 605 |
SKInterface SymbolKind = 11 |
| 606 |
SKFunction SymbolKind = 12 |
| 607 |
SKVariable SymbolKind = 13 |
| 608 |
SKConstant SymbolKind = 14 |
| 609 |
SKString SymbolKind = 15 |
| 610 |
SKNumber SymbolKind = 16 |
| 611 |
SKBoolean SymbolKind = 17 |
| 612 |
SKArray SymbolKind = 18 |
| 613 |
SKObject SymbolKind = 19 |
| 614 |
SKKey SymbolKind = 20 |
| 615 |
SKNull SymbolKind = 21 |
| 616 |
SKEnumMember SymbolKind = 22 |
| 617 |
SKStruct SymbolKind = 23 |
| 618 |
SKEvent SymbolKind = 24 |
| 619 |
SKOperator SymbolKind = 25 |
| 620 |
SKTypeParameter SymbolKind = 26 |
| 621 |
) |
| 622 |
|
| 623 |
func (s SymbolKind) String() string { |
| 624 |
return symbolKindName[s] |
| 625 |
} |
| 626 |
|
| 627 |
var symbolKindName = map[SymbolKind]string{ |
| 628 |
SKFile: "File", |
| 629 |
SKModule: "Module", |
| 630 |
SKNamespace: "Namespace", |
| 631 |
SKPackage: "Package", |
| 632 |
SKClass: "Class", |
| 633 |
SKMethod: "Method", |
| 634 |
SKProperty: "Property", |
| 635 |
SKField: "Field", |
| 636 |
SKConstructor: "Constructor", |
| 637 |
SKEnum: "Enum", |
| 638 |
SKInterface: "Interface", |
| 639 |
SKFunction: "Function", |
| 640 |
SKVariable: "Variable", |
| 641 |
SKConstant: "Constant", |
| 642 |
SKString: "String", |
| 643 |
SKNumber: "Number", |
| 644 |
SKBoolean: "Boolean", |
| 645 |
SKArray: "Array", |
| 646 |
SKObject: "Object", |
| 647 |
SKKey: "Key", |
| 648 |
SKNull: "Null", |
| 649 |
SKEnumMember: "EnumMember", |
| 650 |
SKStruct: "Struct", |
| 651 |
SKEvent: "Event", |
| 652 |
SKOperator: "Operator", |
| 653 |
SKTypeParameter: "TypeParameter", |
| 654 |
} |
| 655 |
|
| 656 |
type SymbolInformation struct { |
| 657 |
Name string `json:"name"` |
| 658 |
Kind SymbolKind `json:"kind"` |
| 659 |
Location Location `json:"location"` |
| 660 |
ContainerName string `json:"containerName,omitempty"` |
| 661 |
} |
| 662 |
|
| 663 |
type WorkspaceSymbolParams struct { |
| 664 |
Query string `json:"query"` |
| 665 |
Limit int `json:"limit"` |
| 666 |
} |
| 667 |
|
| 668 |
type ConfigurationParams struct { |
| 669 |
Items []ConfigurationItem `json:"items"` |
| 670 |
} |
| 671 |
|
| 672 |
type ConfigurationItem struct { |
| 673 |
ScopeURI string `json:"scopeUri,omitempty"` |
| 674 |
Section string `json:"section,omitempty"` |
| 675 |
} |
| 676 |
|
| 677 |
type ConfigurationResult []interface{} |
| 678 |
|
| 679 |
type CodeActionContext struct { |
| 680 |
Diagnostics []Diagnostic `json:"diagnostics"` |
| 681 |
} |
| 682 |
|
| 683 |
type CodeActionParams struct { |
| 684 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 685 |
Range Range `json:"range"` |
| 686 |
Context CodeActionContext `json:"context"` |
| 687 |
} |
| 688 |
|
| 689 |
type CodeLensParams struct { |
| 690 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 691 |
} |
| 692 |
|
| 693 |
type CodeLens struct { |
| 694 |
Range Range `json:"range"` |
| 695 |
Command Command `json:"command,omitempty"` |
| 696 |
Data interface{} `json:"data,omitempty"` |
| 697 |
} |
| 698 |
|
| 699 |
type DocumentFormattingParams struct { |
| 700 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 701 |
Options FormattingOptions `json:"options"` |
| 702 |
} |
| 703 |
|
| 704 |
type FormattingOptions struct { |
| 705 |
TabSize int `json:"tabSize"` |
| 706 |
InsertSpaces bool `json:"insertSpaces"` |
| 707 |
Key string `json:"key"` |
| 708 |
} |
| 709 |
|
| 710 |
type RenameParams struct { |
| 711 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 712 |
Position Position `json:"position"` |
| 713 |
NewName string `json:"newName"` |
| 714 |
} |
| 715 |
|
| 716 |
type DidOpenTextDocumentParams struct { |
| 717 |
TextDocument TextDocumentItem `json:"textDocument"` |
| 718 |
} |
| 719 |
|
| 720 |
type DidChangeTextDocumentParams struct { |
| 721 |
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"` |
| 722 |
ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"` |
| 723 |
} |
| 724 |
|
| 725 |
type TextDocumentContentChangeEvent struct { |
| 726 |
Range *Range `json:"range,omitEmpty"` |
| 727 |
RangeLength uint `json:"rangeLength,omitEmpty"` |
| 728 |
Text string `json:"text"` |
| 729 |
} |
| 730 |
|
| 731 |
type DidCloseTextDocumentParams struct { |
| 732 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 733 |
} |
| 734 |
|
| 735 |
type DidSaveTextDocumentParams struct { |
| 736 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 737 |
} |
| 738 |
|
| 739 |
type MessageType int |
| 740 |
|
| 741 |
const ( |
| 742 |
MTError MessageType = 1 |
| 743 |
MTWarning = 2 |
| 744 |
Info = 3 |
| 745 |
Log = 4 |
| 746 |
) |
| 747 |
|
| 748 |
type ShowMessageParams struct { |
| 749 |
Type MessageType `json:"type"` |
| 750 |
Message string `json:"message"` |
| 751 |
} |
| 752 |
|
| 753 |
type MessageActionItem struct { |
| 754 |
Title string `json:"title"` |
| 755 |
} |
| 756 |
|
| 757 |
type ShowMessageRequestParams struct { |
| 758 |
Type MessageType `json:"type"` |
| 759 |
Message string `json:"message"` |
| 760 |
Actions []MessageActionItem `json:"actions"` |
| 761 |
} |
| 762 |
|
| 763 |
type LogMessageParams struct { |
| 764 |
Type MessageType `json:"type"` |
| 765 |
Message string `json:"message"` |
| 766 |
} |
| 767 |
|
| 768 |
type DidChangeConfigurationParams struct { |
| 769 |
Settings interface{} `json:"settings"` |
| 770 |
} |
| 771 |
|
| 772 |
type FileChangeType int |
| 773 |
|
| 774 |
const ( |
| 775 |
Created FileChangeType = 1 |
| 776 |
Changed = 2 |
| 777 |
Deleted = 3 |
| 778 |
) |
| 779 |
|
| 780 |
type FileEvent struct { |
| 781 |
URI DocumentURI `json:"uri"` |
| 782 |
Type int `json:"type"` |
| 783 |
} |
| 784 |
|
| 785 |
type DidChangeWatchedFilesParams struct { |
| 786 |
Changes []FileEvent `json:"changes"` |
| 787 |
} |
| 788 |
|
| 789 |
type PublishDiagnosticsParams struct { |
| 790 |
URI DocumentURI `json:"uri"` |
| 791 |
Diagnostics []Diagnostic `json:"diagnostics"` |
| 792 |
} |
| 793 |
|
| 794 |
type DocumentRangeFormattingParams struct { |
| 795 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 796 |
Range Range `json:"range"` |
| 797 |
Options FormattingOptions `json:"options"` |
| 798 |
} |
| 799 |
|
| 800 |
type DocumentOnTypeFormattingParams struct { |
| 801 |
TextDocument TextDocumentIdentifier `json:"textDocument"` |
| 802 |
Position Position `json:"position"` |
| 803 |
Ch string `json:"ch"` |
| 804 |
Options FormattingOptions `json:"formattingOptions"` |
| 805 |
} |
| 806 |
|
| 807 |
type CancelParams struct { |
| 808 |
ID ID `json:"id"` |
| 809 |
} |
| 810 |
|
| 811 |
type SemanticHighlightingParams struct { |
| 812 |
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"` |
| 813 |
Lines []SemanticHighlightingInformation `json:"lines"` |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
type SemanticHighlightingInformation struct { |
| 820 |
|
| 821 |
Line int `json:"line"` |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
Tokens SemanticHighlightingTokens `json:"tokens,omitempty"` |
| 829 |
} |
| 830 |
|
| 831 |
type semanticHighlightingInformation struct { |
| 832 |
Line int `json:"line"` |
| 833 |
Tokens *string `json:"tokens"` |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
func (v *SemanticHighlightingInformation) MarshalJSON() ([]byte, error) { |
| 838 |
tokens := string(v.Tokens.Serialize()) |
| 839 |
return json.Marshal(&semanticHighlightingInformation{ |
| 840 |
Line: v.Line, |
| 841 |
Tokens: &tokens, |
| 842 |
}) |
| 843 |
} |
| 844 |
|
| 845 |
|
| 846 |
func (v *SemanticHighlightingInformation) UnmarshalJSON(data []byte) error { |
| 847 |
var info semanticHighlightingInformation |
| 848 |
err := json.Unmarshal(data, &info) |
| 849 |
if err != nil { |
| 850 |
return err |
| 851 |
} |
| 852 |
|
| 853 |
if info.Tokens != nil { |
| 854 |
v.Tokens, err = DeserializeSemanticHighlightingTokens([]byte(*info.Tokens)) |
| 855 |
if err != nil { |
| 856 |
return err |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
v.Line = info.Line |
| 861 |
return nil |
| 862 |
} |
| 863 |
|
| 864 |
type SemanticHighlightingTokens []SemanticHighlightingToken |
| 865 |
|
| 866 |
func (v SemanticHighlightingTokens) Serialize() []byte { |
| 867 |
var chunks [][]byte |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
for _, token := range v { |
| 874 |
chunk := make([]byte, 8) |
| 875 |
binary.BigEndian.PutUint32(chunk[:4], token.Character) |
| 876 |
binary.BigEndian.PutUint16(chunk[4:6], token.Length) |
| 877 |
binary.BigEndian.PutUint16(chunk[6:], token.Scope) |
| 878 |
chunks = append(chunks, chunk) |
| 879 |
} |
| 880 |
|
| 881 |
src := make([]byte, len(chunks)*8) |
| 882 |
for i, chunk := range chunks { |
| 883 |
copy(src[i*8:i*8+8], chunk) |
| 884 |
} |
| 885 |
|
| 886 |
dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) |
| 887 |
base64.StdEncoding.Encode(dst, src) |
| 888 |
return dst |
| 889 |
} |
| 890 |
|
| 891 |
func DeserializeSemanticHighlightingTokens(src []byte) (SemanticHighlightingTokens, error) { |
| 892 |
dst := make([]byte, base64.StdEncoding.DecodedLen(len(src))) |
| 893 |
n, err := base64.StdEncoding.Decode(dst, src) |
| 894 |
if err != nil { |
| 895 |
return nil, err |
| 896 |
} |
| 897 |
|
| 898 |
var chunks [][]byte |
| 899 |
for i := 7; i < len(dst[:n]); i += 8 { |
| 900 |
chunks = append(chunks, dst[i-7:i+1]) |
| 901 |
} |
| 902 |
|
| 903 |
var tokens SemanticHighlightingTokens |
| 904 |
for _, chunk := range chunks { |
| 905 |
tokens = append(tokens, SemanticHighlightingToken{ |
| 906 |
Character: binary.BigEndian.Uint32(chunk[:4]), |
| 907 |
Length: binary.BigEndian.Uint16(chunk[4:6]), |
| 908 |
Scope: binary.BigEndian.Uint16(chunk[6:]), |
| 909 |
}) |
| 910 |
} |
| 911 |
|
| 912 |
return tokens, nil |
| 913 |
} |
| 914 |
|
| 915 |
type SemanticHighlightingToken struct { |
| 916 |
Character uint32 |
| 917 |
Length uint16 |
| 918 |
Scope uint16 |
| 919 |
} |