| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/doc_data.h" |
| 34 |
#include "core/object/class_db.h" |
| 35 |
#include "core/templates/list.h" |
| 36 |
|
| 37 |
namespace LSP { |
| 38 |
|
| 39 |
typedef String DocumentUri; |
| 40 |
|
| 41 |
|
| 42 |
static String marked_documentation(const String &p_bbcode); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
struct TextDocumentIdentifier { |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
DocumentUri uri; |
| 52 |
|
| 53 |
_FORCE_INLINE_ void load(const Dictionary &p_params) { |
| 54 |
uri = p_params["uri"]; |
| 55 |
} |
| 56 |
|
| 57 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 58 |
Dictionary dict; |
| 59 |
dict["uri"] = uri; |
| 60 |
return dict; |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
tor. |
| 67 |
|
| 68 |
|
| 69 |
struct Position { |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
int line = 0; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
int character = 0; |
| 84 |
|
| 85 |
_FORCE_INLINE_ bool operator==(const Position &p_other) const { |
| 86 |
return line == p_other.line && character == p_other.character; |
| 87 |
} |
| 88 |
|
| 89 |
String to_string() const { |
| 90 |
return vformat("(%d,%d)", line, character); |
| 91 |
} |
| 92 |
|
| 93 |
_FORCE_INLINE_ void load(const Dictionary &p_params) { |
| 94 |
line = p_params["line"]; |
| 95 |
character = p_params["character"]; |
| 96 |
} |
| 97 |
|
| 98 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 99 |
Dictionary dict; |
| 100 |
dict["line"] = line; |
| 101 |
dict["character"] = character; |
| 102 |
return dict; |
| 103 |
} |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
struct Range { |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
Position start; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
Position end; |
| 121 |
|
| 122 |
_FORCE_INLINE_ bool operator==(const Range &p_other) const { |
| 123 |
return start == p_other.start && end == p_other.end; |
| 124 |
} |
| 125 |
|
| 126 |
bool contains(const Position &p_pos) const { |
| 127 |
|
| 128 |
if (start.line <= p_pos.line && p_pos.line <= end.line) { |
| 129 |
|
| 130 |
bool start_ok = p_pos.line == start.line ? start.character <= p_pos.character : true; |
| 131 |
|
| 132 |
bool end_ok = p_pos.line == end.line ? p_pos.character <= end.character : true; |
| 133 |
return start_ok && end_ok; |
| 134 |
} else { |
| 135 |
return false; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
String to_string() const { |
| 140 |
return vformat("[%s:%s]", start.to_string(), end.to_string()); |
| 141 |
} |
| 142 |
|
| 143 |
_FORCE_INLINE_ void load(const Dictionary &p_params) { |
| 144 |
start.load(p_params["start"]); |
| 145 |
end.load(p_params["end"]); |
| 146 |
} |
| 147 |
|
| 148 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 149 |
Dictionary dict; |
| 150 |
dict["start"] = start.to_json(); |
| 151 |
dict["end"] = end.to_json(); |
| 152 |
return dict; |
| 153 |
} |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
struct Location { |
| 160 |
DocumentUri uri; |
| 161 |
Range range; |
| 162 |
|
| 163 |
_FORCE_INLINE_ void load(const Dictionary &p_params) { |
| 164 |
uri = p_params["uri"]; |
| 165 |
range.load(p_params["range"]); |
| 166 |
} |
| 167 |
|
| 168 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 169 |
Dictionary dict; |
| 170 |
dict["uri"] = uri; |
| 171 |
dict["range"] = range.to_json(); |
| 172 |
return dict; |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
struct LocationLink { |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
Range *originSelectionRange = nullptr; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
String targetUri; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
Range targetRange; |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
Range targetSelectionRange; |
| 205 |
}; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
struct TextDocumentPositionParams { |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
TextDocumentIdentifier textDocument; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
Position position; |
| 220 |
|
| 221 |
_FORCE_INLINE_ void load(const Dictionary &p_params) { |
| 222 |
textDocument.load(p_params["textDocument"]); |
| 223 |
position.load(p_params["position"]); |
| 224 |
} |
| 225 |
|
| 226 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 227 |
Dictionary dict; |
| 228 |
dict["textDocument"] = textDocument.to_json(); |
| 229 |
dict["position"] = position.to_json(); |
| 230 |
return dict; |
| 231 |
} |
| 232 |
}; |
| 233 |
|
| 234 |
struct ReferenceContext { |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
bool includeDeclaration = false; |
| 239 |
}; |
| 240 |
|
| 241 |
struct ShowMessageParams { |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
int type; |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
String message; |
| 251 |
|
| 252 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 253 |
Dictionary dict; |
| 254 |
dict["type"] = type; |
| 255 |
dict["message"] = message; |
| 256 |
return dict; |
| 257 |
} |
| 258 |
}; |
| 259 |
|
| 260 |
struct ReferenceParams : TextDocumentPositionParams { |
| 261 |
ReferenceContext context; |
| 262 |
}; |
| 263 |
|
| 264 |
struct DocumentLinkParams { |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
TextDocumentIdentifier textDocument; |
| 269 |
|
| 270 |
_FORCE_INLINE_ void load(const Dictionary &p_params) { |
| 271 |
textDocument.load(p_params["textDocument"]); |
| 272 |
} |
| 273 |
}; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
struct DocumentLink { |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
Range range; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
DocumentUri target; |
| 289 |
|
| 290 |
Dictionary to_json() const { |
| 291 |
Dictionary dict; |
| 292 |
dict["range"] = range.to_json(); |
| 293 |
dict["target"] = target; |
| 294 |
return dict; |
| 295 |
} |
| 296 |
}; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
struct TextEdit { |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
Range range; |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
String newText; |
| 313 |
}; |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
struct WorkspaceEdit { |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
HashMap<String, Vector<TextEdit>> changes; |
| 323 |
|
| 324 |
_FORCE_INLINE_ void add_edit(const String &uri, const TextEdit &edit) { |
| 325 |
if (changes.has(uri)) { |
| 326 |
changes[uri].push_back(edit); |
| 327 |
} else { |
| 328 |
Vector<TextEdit> edits; |
| 329 |
edits.push_back(edit); |
| 330 |
changes[uri] = edits; |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 335 |
Dictionary dict; |
| 336 |
|
| 337 |
Dictionary out_changes; |
| 338 |
for (const KeyValue<String, Vector<TextEdit>> &E : changes) { |
| 339 |
Array edits; |
| 340 |
for (int i = 0; i < E.value.size(); ++i) { |
| 341 |
Dictionary text_edit; |
| 342 |
text_edit["range"] = E.value[i].range.to_json(); |
| 343 |
text_edit["newText"] = E.value[i].newText; |
| 344 |
edits.push_back(text_edit); |
| 345 |
} |
| 346 |
out_changes[E.key] = edits; |
| 347 |
} |
| 348 |
dict["changes"] = out_changes; |
| 349 |
|
| 350 |
return dict; |
| 351 |
} |
| 352 |
|
| 353 |
_FORCE_INLINE_ void add_change(const String &uri, const int &line, const int &start_character, const int &end_character, const String &new_text) { |
| 354 |
TextEdit new_edit; |
| 355 |
new_edit.newText = new_text; |
| 356 |
new_edit.range.start.line = line; |
| 357 |
new_edit.range.start.character = start_character; |
| 358 |
new_edit.range.end.line = line; |
| 359 |
new_edit.range.end.character = end_character; |
| 360 |
|
| 361 |
if (HashMap<String, Vector<TextEdit>>::Iterator E = changes.find(uri)) { |
| 362 |
E->value.push_back(new_edit); |
| 363 |
} else { |
| 364 |
Vector<TextEdit> edit_list; |
| 365 |
edit_list.push_back(new_edit); |
| 366 |
changes.insert(uri, edit_list); |
| 367 |
} |
| 368 |
} |
| 369 |
}; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
s. |
| 377 |
|
| 378 |
struct Command { |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
String title; |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
String command; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
Array arguments; |
| 392 |
|
| 393 |
Dictionary to_json() const { |
| 394 |
Dictionary dict; |
| 395 |
dict["title"] = title; |
| 396 |
dict["command"] = command; |
| 397 |
if (arguments.size()) { |
| 398 |
dict["arguments"] = arguments; |
| 399 |
} |
| 400 |
return dict; |
| 401 |
} |
| 402 |
}; |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
namespace TextDocumentSyncKind { |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
static const int None = 0; |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
static const int Full = 1; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
static const int Incremental = 2; |
| 425 |
}; |
| 426 |
|
| 427 |
namespace MessageType { |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
static const int Error = 1; |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
static const int Warning = 2; |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
static const int Info = 3; |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
static const int Log = 4; |
| 444 |
}; |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
struct CompletionOptions { |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
bool resolveProvider = true; |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
Vector<String> triggerCharacters; |
| 460 |
|
| 461 |
CompletionOptions() { |
| 462 |
triggerCharacters.push_back("."); |
| 463 |
triggerCharacters.push_back("$"); |
| 464 |
triggerCharacters.push_back("'"); |
| 465 |
triggerCharacters.push_back("\""); |
| 466 |
} |
| 467 |
|
| 468 |
Dictionary to_json() const { |
| 469 |
Dictionary dict; |
| 470 |
dict["resolveProvider"] = resolveProvider; |
| 471 |
dict["triggerCharacters"] = triggerCharacters; |
| 472 |
return dict; |
| 473 |
} |
| 474 |
}; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
struct SignatureHelpOptions { |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
Vector<String> triggerCharacters; |
| 485 |
|
| 486 |
Dictionary to_json() { |
| 487 |
Dictionary dict; |
| 488 |
dict["triggerCharacters"] = triggerCharacters; |
| 489 |
return dict; |
| 490 |
} |
| 491 |
}; |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
struct CodeLensOptions { |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
bool resolveProvider = false; |
| 501 |
|
| 502 |
Dictionary to_json() { |
| 503 |
Dictionary dict; |
| 504 |
dict["resolveProvider"] = resolveProvider; |
| 505 |
return dict; |
| 506 |
} |
| 507 |
}; |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
struct RenameOptions { |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
bool prepareProvider = true; |
| 517 |
|
| 518 |
Dictionary to_json() { |
| 519 |
Dictionary dict; |
| 520 |
dict["prepareProvider"] = prepareProvider; |
| 521 |
return dict; |
| 522 |
} |
| 523 |
}; |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
struct DocumentLinkOptions { |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
bool resolveProvider = false; |
| 533 |
|
| 534 |
Dictionary to_json() { |
| 535 |
Dictionary dict; |
| 536 |
dict["resolveProvider"] = resolveProvider; |
| 537 |
return dict; |
| 538 |
} |
| 539 |
}; |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
struct ExecuteCommandOptions { |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
Vector<String> commands; |
| 549 |
|
| 550 |
Dictionary to_json() { |
| 551 |
Dictionary dict; |
| 552 |
dict["commands"] = commands; |
| 553 |
return dict; |
| 554 |
} |
| 555 |
}; |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
struct SaveOptions { |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
bool includeText = true; |
| 565 |
|
| 566 |
Dictionary to_json() { |
| 567 |
Dictionary dict; |
| 568 |
dict["includeText"] = includeText; |
| 569 |
return dict; |
| 570 |
} |
| 571 |
}; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
struct ColorProviderOptions { |
| 577 |
Dictionary to_json() { |
| 578 |
return Dictionary(); |
| 579 |
} |
| 580 |
}; |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
struct FoldingRangeProviderOptions { |
| 586 |
Dictionary to_json() { |
| 587 |
return Dictionary(); |
| 588 |
} |
| 589 |
}; |
| 590 |
|
| 591 |
struct TextDocumentSyncOptions { |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
bool openClose = true; |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
int change = TextDocumentSyncKind::Full; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
bool willSave = false; |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
bool willSaveWaitUntil = true; |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
SaveOptions save; |
| 621 |
|
| 622 |
Dictionary to_json() { |
| 623 |
Dictionary dict; |
| 624 |
dict["willSaveWaitUntil"] = willSaveWaitUntil; |
| 625 |
dict["willSave"] = willSave; |
| 626 |
dict["openClose"] = openClose; |
| 627 |
dict["change"] = change; |
| 628 |
dict["save"] = save.to_json(); |
| 629 |
return dict; |
| 630 |
} |
| 631 |
}; |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
struct StaticRegistrationOptions { |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
String id; |
| 642 |
}; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
struct DocumentOnTypeFormattingOptions { |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
String firstTriggerCharacter; |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
Vector<String> moreTriggerCharacter; |
| 657 |
|
| 658 |
Dictionary to_json() { |
| 659 |
Dictionary dict; |
| 660 |
dict["firstTriggerCharacter"] = firstTriggerCharacter; |
| 661 |
dict["moreTriggerCharacter"] = moreTriggerCharacter; |
| 662 |
return dict; |
| 663 |
} |
| 664 |
}; |
| 665 |
|
| 666 |
enum class LanguageId { |
| 667 |
GDSCRIPT, |
| 668 |
OTHER, |
| 669 |
}; |
| 670 |
|
| 671 |
struct TextDocumentItem { |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
DocumentUri uri; |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
LanguageId languageId; |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
int version = 0; |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
String text; |
| 692 |
|
| 693 |
void load(const Dictionary &p_dict) { |
| 694 |
uri = p_dict["uri"]; |
| 695 |
version = p_dict["version"]; |
| 696 |
text = p_dict["text"]; |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
String rawLanguageId = p_dict["languageId"]; |
| 703 |
if (rawLanguageId == "gdscript" || rawLanguageId == "gd" || rawLanguageId == "godot") { |
| 704 |
languageId = LanguageId::GDSCRIPT; |
| 705 |
} else { |
| 706 |
languageId = LanguageId::OTHER; |
| 707 |
} |
| 708 |
} |
| 709 |
}; |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
struct TextDocumentContentChangeEvent { |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
String text; |
| 719 |
|
| 720 |
void load(const Dictionary &p_params) { |
| 721 |
text = p_params["text"]; |
| 722 |
} |
| 723 |
}; |
| 724 |
|
| 725 |
|
| 726 |
namespace DiagnosticSeverity { |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
static const int Error = 1; |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
static const int Warning = 2; |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
static const int Information = 3; |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
static const int Hint = 4; |
| 743 |
}; |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
struct DiagnosticRelatedInformation { |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
Location location; |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
String message; |
| 760 |
|
| 761 |
Dictionary to_json() const { |
| 762 |
Dictionary dict; |
| 763 |
dict["location"] = location.to_json(); |
| 764 |
dict["message"] = message; |
| 765 |
return dict; |
| 766 |
} |
| 767 |
}; |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
struct Diagnostic { |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
Range range; |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
int severity = 0; |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
int code = 0; |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
String source; |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
String message; |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
Vector<DiagnosticRelatedInformation> relatedInformation; |
| 806 |
|
| 807 |
Dictionary to_json() const { |
| 808 |
Dictionary dict; |
| 809 |
dict["range"] = range.to_json(); |
| 810 |
dict["code"] = code; |
| 811 |
dict["severity"] = severity; |
| 812 |
dict["message"] = message; |
| 813 |
dict["source"] = source; |
| 814 |
if (!relatedInformation.is_empty()) { |
| 815 |
Array arr; |
| 816 |
arr.resize(relatedInformation.size()); |
| 817 |
for (int i = 0; i < relatedInformation.size(); i++) { |
| 818 |
arr[i] = relatedInformation[i].to_json(); |
| 819 |
} |
| 820 |
dict["relatedInformation"] = arr; |
| 821 |
} |
| 822 |
return dict; |
| 823 |
} |
| 824 |
}; |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
namespace MarkupKind { |
| 835 |
static const String PlainText = "plaintext"; |
| 836 |
static const String Markdown = "markdown"; |
| 837 |
}; |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
struct MarkupContent { |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
String kind; |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
String value; |
| 873 |
|
| 874 |
MarkupContent() { |
| 875 |
kind = MarkupKind::Markdown; |
| 876 |
} |
| 877 |
|
| 878 |
MarkupContent(const String &p_value) { |
| 879 |
value = p_value; |
| 880 |
kind = MarkupKind::Markdown; |
| 881 |
} |
| 882 |
|
| 883 |
Dictionary to_json() const { |
| 884 |
Dictionary dict; |
| 885 |
dict["kind"] = kind; |
| 886 |
dict["value"] = value; |
| 887 |
return dict; |
| 888 |
} |
| 889 |
}; |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
namespace CompletionItemKind { |
| 898 |
static const int Text = 1; |
| 899 |
static const int Method = 2; |
| 900 |
static const int Function = 3; |
| 901 |
static const int Constructor = 4; |
| 902 |
static const int Field = 5; |
| 903 |
static const int Variable = 6; |
| 904 |
static const int Class = 7; |
| 905 |
static const int Interface = 8; |
| 906 |
static const int Module = 9; |
| 907 |
static const int Property = 10; |
| 908 |
static const int Unit = 11; |
| 909 |
static const int Value = 12; |
| 910 |
static const int Enum = 13; |
| 911 |
static const int Keyword = 14; |
| 912 |
static const int Snippet = 15; |
| 913 |
static const int Color = 16; |
| 914 |
static const int File = 17; |
| 915 |
static const int RefCounted = 18; |
| 916 |
static const int Folder = 19; |
| 917 |
static const int EnumMember = 20; |
| 918 |
static const int Constant = 21; |
| 919 |
static const int Struct = 22; |
| 920 |
static const int Event = 23; |
| 921 |
static const int Operator = 24; |
| 922 |
static const int TypeParameter = 25; |
| 923 |
}; |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
namespace InsertTextFormat { |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
static const int PlainText = 1; |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
static const int Snippet = 2; |
| 945 |
}; |
| 946 |
|
| 947 |
struct CompletionItem { |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
String label; |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
int kind = 0; |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
String detail; |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
MarkupContent documentation; |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
bool deprecated = false; |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
bool preselect = false; |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
String sortText; |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
String filterText; |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
String insertText; |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
int insertTextFormat = 0; |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
TextEdit textEdit; |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
Vector<TextEdit> additionalTextEdits; |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
Vector<String> commitCharacters; |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
Command command; |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
Variant data; |
| 1061 |
|
| 1062 |
_FORCE_INLINE_ Dictionary to_json(bool resolved = false) const { |
| 1063 |
Dictionary dict; |
| 1064 |
dict["label"] = label; |
| 1065 |
dict["kind"] = kind; |
| 1066 |
dict["data"] = data; |
| 1067 |
if (!insertText.is_empty()) { |
| 1068 |
dict["insertText"] = insertText; |
| 1069 |
} |
| 1070 |
if (resolved) { |
| 1071 |
dict["detail"] = detail; |
| 1072 |
dict["documentation"] = documentation.to_json(); |
| 1073 |
dict["deprecated"] = deprecated; |
| 1074 |
dict["preselect"] = preselect; |
| 1075 |
if (!sortText.is_empty()) { |
| 1076 |
dict["sortText"] = sortText; |
| 1077 |
} |
| 1078 |
if (!filterText.is_empty()) { |
| 1079 |
dict["filterText"] = filterText; |
| 1080 |
} |
| 1081 |
if (commitCharacters.size()) { |
| 1082 |
dict["commitCharacters"] = commitCharacters; |
| 1083 |
} |
| 1084 |
if (!command.command.is_empty()) { |
| 1085 |
dict["command"] = command.to_json(); |
| 1086 |
} |
| 1087 |
} |
| 1088 |
return dict; |
| 1089 |
} |
| 1090 |
|
| 1091 |
void load(const Dictionary &p_dict) { |
| 1092 |
if (p_dict.has("label")) { |
| 1093 |
label = p_dict["label"]; |
| 1094 |
} |
| 1095 |
if (p_dict.has("kind")) { |
| 1096 |
kind = p_dict["kind"]; |
| 1097 |
} |
| 1098 |
if (p_dict.has("detail")) { |
| 1099 |
detail = p_dict["detail"]; |
| 1100 |
} |
| 1101 |
if (p_dict.has("documentation")) { |
| 1102 |
Variant doc = p_dict["documentation"]; |
| 1103 |
if (doc.is_string()) { |
| 1104 |
documentation.value = doc; |
| 1105 |
} else if (doc.get_type() == Variant::DICTIONARY) { |
| 1106 |
Dictionary v = doc; |
| 1107 |
documentation.value = v["value"]; |
| 1108 |
} |
| 1109 |
} |
| 1110 |
if (p_dict.has("deprecated")) { |
| 1111 |
deprecated = p_dict["deprecated"]; |
| 1112 |
} |
| 1113 |
if (p_dict.has("preselect")) { |
| 1114 |
preselect = p_dict["preselect"]; |
| 1115 |
} |
| 1116 |
if (p_dict.has("sortText")) { |
| 1117 |
sortText = p_dict["sortText"]; |
| 1118 |
} |
| 1119 |
if (p_dict.has("filterText")) { |
| 1120 |
filterText = p_dict["filterText"]; |
| 1121 |
} |
| 1122 |
if (p_dict.has("insertText")) { |
| 1123 |
insertText = p_dict["insertText"]; |
| 1124 |
} |
| 1125 |
if (p_dict.has("data")) { |
| 1126 |
data = p_dict["data"]; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
}; |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
struct CompletionList { |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
bool isIncomplete = false; |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
Vector<CompletionItem> items; |
| 1146 |
}; |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
namespace SymbolKind { |
| 1155 |
static const int File = 1; |
| 1156 |
static const int Module = 2; |
| 1157 |
static const int Namespace = 3; |
| 1158 |
static const int Package = 4; |
| 1159 |
static const int Class = 5; |
| 1160 |
static const int Method = 6; |
| 1161 |
static const int Property = 7; |
| 1162 |
static const int Field = 8; |
| 1163 |
static const int Constructor = 9; |
| 1164 |
static const int Enum = 10; |
| 1165 |
static const int Interface = 11; |
| 1166 |
static const int Function = 12; |
| 1167 |
static const int Variable = 13; |
| 1168 |
static const int Constant = 14; |
| 1169 |
static const int String = 15; |
| 1170 |
static const int Number = 16; |
| 1171 |
static const int Boolean = 17; |
| 1172 |
static const int Array = 18; |
| 1173 |
static const int Object = 19; |
| 1174 |
static const int Key = 20; |
| 1175 |
static const int Null = 21; |
| 1176 |
static const int EnumMember = 22; |
| 1177 |
static const int Struct = 23; |
| 1178 |
static const int Event = 24; |
| 1179 |
static const int Operator = 25; |
| 1180 |
static const int TypeParameter = 26; |
| 1181 |
}; |
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
struct DocumentSymbol { |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
String name; |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
String detail; |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
String documentation; |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
String native_class; |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
int kind = SymbolKind::File; |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
bool deprecated = false; |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
bool local = false; |
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
Range range; |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
Range selectionRange; |
| 1239 |
|
| 1240 |
DocumentUri uri; |
| 1241 |
String script_path; |
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
Vector<DocumentSymbol> children; |
| 1247 |
|
| 1248 |
Dictionary to_json(bool with_doc = false) const { |
| 1249 |
Dictionary dict; |
| 1250 |
dict["name"] = name; |
| 1251 |
dict["detail"] = detail; |
| 1252 |
dict["kind"] = kind; |
| 1253 |
dict["deprecated"] = deprecated; |
| 1254 |
dict["range"] = range.to_json(); |
| 1255 |
dict["selectionRange"] = selectionRange.to_json(); |
| 1256 |
if (with_doc) { |
| 1257 |
dict["documentation"] = documentation; |
| 1258 |
dict["native_class"] = native_class; |
| 1259 |
} |
| 1260 |
if (!children.is_empty()) { |
| 1261 |
Array arr; |
| 1262 |
for (int i = 0; i < children.size(); i++) { |
| 1263 |
if (children[i].local) { |
| 1264 |
continue; |
| 1265 |
} |
| 1266 |
arr.push_back(children[i].to_json(with_doc)); |
| 1267 |
} |
| 1268 |
if (!children.is_empty()) { |
| 1269 |
dict["children"] = arr; |
| 1270 |
} |
| 1271 |
} |
| 1272 |
return dict; |
| 1273 |
} |
| 1274 |
|
| 1275 |
_FORCE_INLINE_ MarkupContent render() const { |
| 1276 |
MarkupContent markdown; |
| 1277 |
if (detail.length()) { |
| 1278 |
markdown.value = "\t" + detail + "\n\n"; |
| 1279 |
} |
| 1280 |
if (documentation.length()) { |
| 1281 |
markdown.value += marked_documentation(documentation) + "\n\n"; |
| 1282 |
} |
| 1283 |
if (script_path.length()) { |
| 1284 |
markdown.value += "Defined in [" + script_path + "](" + uri + ")"; |
| 1285 |
} |
| 1286 |
return markdown; |
| 1287 |
} |
| 1288 |
|
| 1289 |
_FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const { |
| 1290 |
LSP::CompletionItem item; |
| 1291 |
item.label = name; |
| 1292 |
|
| 1293 |
if (resolved) { |
| 1294 |
item.documentation = render(); |
| 1295 |
} |
| 1296 |
|
| 1297 |
switch (kind) { |
| 1298 |
case LSP::SymbolKind::Enum: |
| 1299 |
item.kind = LSP::CompletionItemKind::Enum; |
| 1300 |
break; |
| 1301 |
case LSP::SymbolKind::Class: |
| 1302 |
item.kind = LSP::CompletionItemKind::Class; |
| 1303 |
break; |
| 1304 |
case LSP::SymbolKind::Property: |
| 1305 |
item.kind = LSP::CompletionItemKind::Property; |
| 1306 |
break; |
| 1307 |
case LSP::SymbolKind::Method: |
| 1308 |
case LSP::SymbolKind::Function: |
| 1309 |
item.kind = LSP::CompletionItemKind::Method; |
| 1310 |
break; |
| 1311 |
case LSP::SymbolKind::Event: |
| 1312 |
item.kind = LSP::CompletionItemKind::Event; |
| 1313 |
break; |
| 1314 |
case LSP::SymbolKind::Constant: |
| 1315 |
item.kind = LSP::CompletionItemKind::Constant; |
| 1316 |
break; |
| 1317 |
case LSP::SymbolKind::Variable: |
| 1318 |
item.kind = LSP::CompletionItemKind::Variable; |
| 1319 |
break; |
| 1320 |
case LSP::SymbolKind::File: |
| 1321 |
item.kind = LSP::CompletionItemKind::File; |
| 1322 |
break; |
| 1323 |
default: |
| 1324 |
item.kind = LSP::CompletionItemKind::Text; |
| 1325 |
break; |
| 1326 |
} |
| 1327 |
|
| 1328 |
return item; |
| 1329 |
} |
| 1330 |
}; |
| 1331 |
|
| 1332 |
struct ApplyWorkspaceEditParams { |
| 1333 |
WorkspaceEdit edit; |
| 1334 |
|
| 1335 |
Dictionary to_json() { |
| 1336 |
Dictionary dict; |
| 1337 |
|
| 1338 |
dict["edit"] = edit.to_json(); |
| 1339 |
|
| 1340 |
return dict; |
| 1341 |
} |
| 1342 |
}; |
| 1343 |
|
| 1344 |
struct NativeSymbolInspectParams { |
| 1345 |
String native_class; |
| 1346 |
String symbol_name; |
| 1347 |
|
| 1348 |
void load(const Dictionary &p_params) { |
| 1349 |
native_class = p_params["native_class"]; |
| 1350 |
symbol_name = p_params["symbol_name"]; |
| 1351 |
} |
| 1352 |
}; |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
namespace FoldingRangeKind { |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
static const String Comment = "comment"; |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
static const String Imports = "imports"; |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
static const String Region = "region"; |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
struct FoldingRange { |
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
int startLine = 0; |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
int startCharacter = 0; |
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
int endLine = 0; |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
int endCharacter = 0; |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
String kind = FoldingRangeKind::Region; |
| 1402 |
|
| 1403 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 1404 |
Dictionary dict; |
| 1405 |
dict["startLine"] = startLine; |
| 1406 |
dict["startCharacter"] = startCharacter; |
| 1407 |
dict["endLine"] = endLine; |
| 1408 |
dict["endCharacter"] = endCharacter; |
| 1409 |
return dict; |
| 1410 |
} |
| 1411 |
}; |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
namespace CompletionTriggerKind { |
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
static const int Invoked = 1; |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
static const int TriggerCharacter = 2; |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
static const int TriggerForIncompleteCompletions = 3; |
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
struct CompletionContext { |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
int triggerKind = CompletionTriggerKind::Invoked; |
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
String triggerCharacter; |
| 1450 |
|
| 1451 |
void load(const Dictionary &p_params) { |
| 1452 |
triggerKind = int(p_params["triggerKind"]); |
| 1453 |
triggerCharacter = p_params.get("triggerCharacter", ""); |
| 1454 |
} |
| 1455 |
}; |
| 1456 |
|
| 1457 |
struct CompletionParams : public TextDocumentPositionParams { |
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
CompletionContext context; |
| 1463 |
|
| 1464 |
void load(const Dictionary &p_params) { |
| 1465 |
TextDocumentPositionParams::load(p_params); |
| 1466 |
|
| 1467 |
if (p_params.has("context")) { |
| 1468 |
context.load(p_params["context"]); |
| 1469 |
} |
| 1470 |
} |
| 1471 |
|
| 1472 |
Dictionary to_json() { |
| 1473 |
Dictionary ctx; |
| 1474 |
ctx["triggerCharacter"] = context.triggerCharacter; |
| 1475 |
ctx["triggerKind"] = context.triggerKind; |
| 1476 |
|
| 1477 |
Dictionary dict; |
| 1478 |
dict = TextDocumentPositionParams::to_json(); |
| 1479 |
dict["context"] = ctx; |
| 1480 |
return dict; |
| 1481 |
} |
| 1482 |
}; |
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
struct Hover { |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
MarkupContent contents; |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
Range range; |
| 1498 |
|
| 1499 |
_FORCE_INLINE_ Dictionary to_json() const { |
| 1500 |
Dictionary dict; |
| 1501 |
dict["range"] = range.to_json(); |
| 1502 |
dict["contents"] = contents.to_json(); |
| 1503 |
return dict; |
| 1504 |
} |
| 1505 |
}; |
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
struct ParameterInformation { |
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
String label; |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
MarkupContent documentation; |
| 1529 |
|
| 1530 |
Dictionary to_json() const { |
| 1531 |
Dictionary dict; |
| 1532 |
dict["label"] = label; |
| 1533 |
dict["documentation"] = documentation.to_json(); |
| 1534 |
return dict; |
| 1535 |
} |
| 1536 |
}; |
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
struct SignatureInformation { |
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
String label; |
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
MarkupContent documentation; |
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
Vector<ParameterInformation> parameters; |
| 1560 |
|
| 1561 |
Dictionary to_json() const { |
| 1562 |
Dictionary dict; |
| 1563 |
dict["label"] = label; |
| 1564 |
dict["documentation"] = documentation.to_json(); |
| 1565 |
Array args; |
| 1566 |
for (int i = 0; i < parameters.size(); i++) { |
| 1567 |
args.push_back(parameters[i].to_json()); |
| 1568 |
} |
| 1569 |
dict["parameters"] = args; |
| 1570 |
return dict; |
| 1571 |
} |
| 1572 |
}; |
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
struct SignatureHelp { |
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
Vector<SignatureInformation> signatures; |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
int activeSignature = 0; |
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
int activeParameter = 0; |
| 1606 |
|
| 1607 |
Dictionary to_json() const { |
| 1608 |
Dictionary dict; |
| 1609 |
Array sigs; |
| 1610 |
for (int i = 0; i < signatures.size(); i++) { |
| 1611 |
sigs.push_back(signatures[i].to_json()); |
| 1612 |
} |
| 1613 |
dict["signatures"] = sigs; |
| 1614 |
dict["activeSignature"] = activeSignature; |
| 1615 |
dict["activeParameter"] = activeParameter; |
| 1616 |
return dict; |
| 1617 |
} |
| 1618 |
}; |
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
struct FileOperationPattern { |
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
String glob = "** |
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
String matches = "file"; |
| 1636 |
|
| 1637 |
Dictionary to_json() const { |
| 1638 |
Dictionary dict; |
| 1639 |
|
| 1640 |
dict["glob"] = glob; |
| 1641 |
dict["matches"] = matches; |
| 1642 |
|
| 1643 |
return dict; |
| 1644 |
} |
| 1645 |
}; |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
struct FileOperationFilter { |
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
FileOperationPattern pattern; |
| 1656 |
|
| 1657 |
Dictionary to_json() const { |
| 1658 |
Dictionary dict; |
| 1659 |
|
| 1660 |
dict["pattern"] = pattern.to_json(); |
| 1661 |
|
| 1662 |
return dict; |
| 1663 |
} |
| 1664 |
}; |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
struct FileOperationRegistrationOptions { |
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
Vector<FileOperationFilter> filters; |
| 1674 |
|
| 1675 |
FileOperationRegistrationOptions() { |
| 1676 |
filters.push_back(FileOperationFilter()); |
| 1677 |
} |
| 1678 |
|
| 1679 |
Dictionary to_json() const { |
| 1680 |
Dictionary dict; |
| 1681 |
|
| 1682 |
Array filts; |
| 1683 |
for (int i = 0; i < filters.size(); i++) { |
| 1684 |
filts.push_back(filters[i].to_json()); |
| 1685 |
} |
| 1686 |
dict["filters"] = filts; |
| 1687 |
|
| 1688 |
return dict; |
| 1689 |
} |
| 1690 |
}; |
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
struct FileOperations { |
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
FileOperationRegistrationOptions didDelete; |
| 1700 |
|
| 1701 |
Dictionary to_json() const { |
| 1702 |
Dictionary dict; |
| 1703 |
|
| 1704 |
dict["didDelete"] = didDelete.to_json(); |
| 1705 |
|
| 1706 |
return dict; |
| 1707 |
} |
| 1708 |
}; |
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
struct Workspace { |
| 1714 |
Dictionary to_json() const { |
| 1715 |
Dictionary dict; |
| 1716 |
return dict; |
| 1717 |
} |
| 1718 |
}; |
| 1719 |
|
| 1720 |
struct ServerCapabilities { |
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
TextDocumentSyncOptions textDocumentSync; |
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
bool hoverProvider = true; |
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
CompletionOptions completionProvider; |
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
SignatureHelpOptions signatureHelpProvider; |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
bool definitionProvider = true; |
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
bool typeDefinitionProvider = false; |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
bool implementationProvider = false; |
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
bool referencesProvider = true; |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
bool documentHighlightProvider = false; |
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
bool documentSymbolProvider = true; |
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
bool workspaceSymbolProvider = false; |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
Workspace workspace; |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
bool codeActionProvider = false; |
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
CodeLensOptions codeLensProvider; |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
bool documentFormattingProvider = false; |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
bool documentRangeFormattingProvider = false; |
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider; |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
RenameOptions renameProvider; |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
DocumentLinkOptions documentLinkProvider; |
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
ColorProviderOptions colorProvider; |
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
FoldingRangeProviderOptions foldingRangeProvider; |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
bool declarationProvider = true; |
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
ExecuteCommandOptions executeCommandProvider; |
| 1850 |
|
| 1851 |
_FORCE_INLINE_ Dictionary to_json() { |
| 1852 |
Dictionary dict; |
| 1853 |
dict["textDocumentSync"] = textDocumentSync.to_json(); |
| 1854 |
dict["completionProvider"] = completionProvider.to_json(); |
| 1855 |
signatureHelpProvider.triggerCharacters.push_back(","); |
| 1856 |
signatureHelpProvider.triggerCharacters.push_back("("); |
| 1857 |
dict["signatureHelpProvider"] = signatureHelpProvider.to_json(); |
| 1858 |
|
| 1859 |
dict["documentOnTypeFormattingProvider"] = documentOnTypeFormattingProvider.to_json(); |
| 1860 |
dict["renameProvider"] = renameProvider.to_json(); |
| 1861 |
dict["documentLinkProvider"] = documentLinkProvider.to_json(); |
| 1862 |
dict["colorProvider"] = false; |
| 1863 |
dict["foldingRangeProvider"] = false; |
| 1864 |
dict["executeCommandProvider"] = executeCommandProvider.to_json(); |
| 1865 |
dict["hoverProvider"] = hoverProvider; |
| 1866 |
dict["definitionProvider"] = definitionProvider; |
| 1867 |
dict["typeDefinitionProvider"] = typeDefinitionProvider; |
| 1868 |
dict["implementationProvider"] = implementationProvider; |
| 1869 |
dict["referencesProvider"] = referencesProvider; |
| 1870 |
dict["documentHighlightProvider"] = documentHighlightProvider; |
| 1871 |
dict["documentSymbolProvider"] = documentSymbolProvider; |
| 1872 |
dict["workspaceSymbolProvider"] = workspaceSymbolProvider; |
| 1873 |
dict["workspace"] = workspace.to_json(); |
| 1874 |
dict["codeActionProvider"] = codeActionProvider; |
| 1875 |
dict["documentFormattingProvider"] = documentFormattingProvider; |
| 1876 |
dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider; |
| 1877 |
dict["declarationProvider"] = declarationProvider; |
| 1878 |
return dict; |
| 1879 |
} |
| 1880 |
}; |
| 1881 |
|
| 1882 |
struct InitializeResult { |
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
ServerCapabilities capabilities; |
| 1887 |
|
| 1888 |
_FORCE_INLINE_ Dictionary to_json() { |
| 1889 |
Dictionary dict; |
| 1890 |
dict["capabilities"] = capabilities.to_json(); |
| 1891 |
return dict; |
| 1892 |
} |
| 1893 |
}; |
| 1894 |
|
| 1895 |
struct GodotNativeClassInfo { |
| 1896 |
String name; |
| 1897 |
const DocData::ClassDoc *class_doc = nullptr; |
| 1898 |
const ClassDB::ClassInfo *class_info = nullptr; |
| 1899 |
|
| 1900 |
Dictionary to_json() const { |
| 1901 |
Dictionary dict; |
| 1902 |
dict["name"] = name; |
| 1903 |
dict["inherits"] = class_doc->inherits; |
| 1904 |
return dict; |
| 1905 |
} |
| 1906 |
}; |
| 1907 |
|
| 1908 |
|
| 1909 |
struct GodotCapabilities { |
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
List<GodotNativeClassInfo> native_classes; |
| 1914 |
|
| 1915 |
Dictionary to_json() const { |
| 1916 |
Dictionary dict; |
| 1917 |
Array classes; |
| 1918 |
for (const GodotNativeClassInfo &native_class : native_classes) { |
| 1919 |
classes.push_back(native_class.to_json()); |
| 1920 |
} |
| 1921 |
dict["native_classes"] = classes; |
| 1922 |
return dict; |
| 1923 |
} |
| 1924 |
}; |
| 1925 |
|
| 1926 |
|
| 1927 |
static String marked_documentation(const String &p_bbcode) { |
| 1928 |
String markdown = p_bbcode.strip_edges(); |
| 1929 |
|
| 1930 |
Vector<String> lines = markdown.split("\n"); |
| 1931 |
bool in_codeblock_tag = false; |
| 1932 |
|
| 1933 |
bool in_codeblocks_tag = false; |
| 1934 |
bool in_codeblocks_gdscript_tag = false; |
| 1935 |
|
| 1936 |
markdown = ""; |
| 1937 |
for (int i = 0; i < lines.size(); i++) { |
| 1938 |
String line = lines[i]; |
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
if (line.contains("[codeblocks]")) { |
| 1944 |
in_codeblocks_tag = true; |
| 1945 |
continue; |
| 1946 |
} |
| 1947 |
if (in_codeblocks_tag && line.contains("[/codeblocks]")) { |
| 1948 |
in_codeblocks_tag = false; |
| 1949 |
continue; |
| 1950 |
} |
| 1951 |
if (in_codeblocks_tag) { |
| 1952 |
if (line.contains("[gdscript]")) { |
| 1953 |
in_codeblocks_gdscript_tag = true; |
| 1954 |
line = "```gdscript"; |
| 1955 |
} else if (in_codeblocks_gdscript_tag && line.contains("[/gdscript]")) { |
| 1956 |
line = "```"; |
| 1957 |
in_codeblocks_gdscript_tag = false; |
| 1958 |
} else if (!in_codeblocks_gdscript_tag) { |
| 1959 |
continue; |
| 1960 |
} |
| 1961 |
} |
| 1962 |
|
| 1963 |
|
| 1964 |
String codeblock_lang = "gdscript"; |
| 1965 |
int block_start = line.find("[codeblock"); |
| 1966 |
if (block_start != -1) { |
| 1967 |
int bracket_pos = line.find_char(']', block_start); |
| 1968 |
if (bracket_pos != -1) { |
| 1969 |
int lang_start = line.find("lang=", block_start); |
| 1970 |
if (lang_start != -1 && lang_start < bracket_pos) { |
| 1971 |
constexpr int LANG_PARAM_LENGTH = 5; |
| 1972 |
int lang_value_start = lang_start + LANG_PARAM_LENGTH; |
| 1973 |
int lang_end = bracket_pos; |
| 1974 |
if (lang_value_start < lang_end) { |
| 1975 |
codeblock_lang = line.substr(lang_value_start, lang_end - lang_value_start); |
| 1976 |
} |
| 1977 |
} |
| 1978 |
in_codeblock_tag = true; |
| 1979 |
line = "```" + codeblock_lang; |
| 1980 |
} |
| 1981 |
} |
| 1982 |
|
| 1983 |
if (in_codeblock_tag && line.contains("[/codeblock]")) { |
| 1984 |
line = "```"; |
| 1985 |
in_codeblock_tag = false; |
| 1986 |
} |
| 1987 |
|
| 1988 |
if (!in_codeblock_tag) { |
| 1989 |
line = line.strip_edges(); |
| 1990 |
line = line.replace("[br]", "\n\n"); |
| 1991 |
|
| 1992 |
line = line.replace("[code]", "`"); |
| 1993 |
line = line.replace("[/code]", "`"); |
| 1994 |
line = line.replace("[i]", "*"); |
| 1995 |
line = line.replace("[/i]", "*"); |
| 1996 |
line = line.replace("[b]", "**"); |
| 1997 |
line = line.replace("[/b]", "**"); |
| 1998 |
line = line.replace("[u]", "__"); |
| 1999 |
line = line.replace("[/u]", "__"); |
| 2000 |
line = line.replace("[s]", "~~"); |
| 2001 |
line = line.replace("[/s]", "~~"); |
| 2002 |
line = line.replace("[kbd]", "`"); |
| 2003 |
line = line.replace("[/kbd]", "`"); |
| 2004 |
line = line.replace("[center]", ""); |
| 2005 |
line = line.replace("[/center]", ""); |
| 2006 |
line = line.replace("[/font]", ""); |
| 2007 |
line = line.replace("[/color]", ""); |
| 2008 |
line = line.replace("[/img]", ""); |
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
int pos = 0; |
| 2013 |
while ((pos = line.find_char('[', pos)) != -1) { |
| 2014 |
|
| 2015 |
|
| 2016 |
const bool is_within_bounds = pos + 4 <= line.length(); |
| 2017 |
if (is_within_bounds && line.substr(pos, 4) == "[lb]") { |
| 2018 |
line = line.substr(0, pos) + "\\[" + line.substr(pos + 4); |
| 2019 |
|
| 2020 |
|
| 2021 |
pos += 2; |
| 2022 |
continue; |
| 2023 |
} else if (is_within_bounds && line.substr(pos, 4) == "[rb]") { |
| 2024 |
line = line.substr(0, pos) + "\\]" + line.substr(pos + 4); |
| 2025 |
pos += 2; |
| 2026 |
continue; |
| 2027 |
} |
| 2028 |
|
| 2029 |
|
| 2030 |
int end_pos = line.find_char(']', pos); |
| 2031 |
if (end_pos == -1) { |
| 2032 |
break; |
| 2033 |
} |
| 2034 |
|
| 2035 |
String content = line.substr(pos + 1, end_pos - pos - 1); |
| 2036 |
|
| 2037 |
|
| 2038 |
bool is_class_name = (!content.is_empty() && content != "url" && !content.contains_char(' ') && !content.contains_char('=') && !content.contains_char('/')); |
| 2039 |
if (is_class_name) { |
| 2040 |
line = line.substr(0, pos) + "`" + content + "`" + line.substr(end_pos + 1); |
| 2041 |
pos += content.length() + 2; |
| 2042 |
} else { |
| 2043 |
pos = end_pos + 1; |
| 2044 |
} |
| 2045 |
} |
| 2046 |
|
| 2047 |
constexpr int URL_OPEN_TAG_LENGTH = 5; |
| 2048 |
constexpr int URL_CLOSE_TAG_LENGTH = 6; |
| 2049 |
|
| 2050 |
|
| 2051 |
pos = 0; |
| 2052 |
while ((pos = line.find("[url=", pos)) != -1) { |
| 2053 |
int url_end = line.find_char(']', pos); |
| 2054 |
int close_start = line.find("[/url]", url_end); |
| 2055 |
if (url_end == -1 || close_start == -1) { |
| 2056 |
break; |
| 2057 |
} |
| 2058 |
|
| 2059 |
String url = line.substr(pos + URL_OPEN_TAG_LENGTH, url_end - pos - URL_OPEN_TAG_LENGTH); |
| 2060 |
String text = line.substr(url_end + 1, close_start - url_end - 1); |
| 2061 |
String replacement = "[" + text + "](" + url + ")"; |
| 2062 |
line = line.substr(0, pos) + replacement + line.substr(close_start + URL_CLOSE_TAG_LENGTH); |
| 2063 |
pos += replacement.length(); |
| 2064 |
} |
| 2065 |
|
| 2066 |
|
| 2067 |
pos = 0; |
| 2068 |
while ((pos = line.find("[url]", pos)) != -1) { |
| 2069 |
int close_pos = line.find("[/url]", pos); |
| 2070 |
if (close_pos == -1) { |
| 2071 |
break; |
| 2072 |
} |
| 2073 |
|
| 2074 |
String url = line.substr(pos + URL_OPEN_TAG_LENGTH, close_pos - pos - URL_OPEN_TAG_LENGTH); |
| 2075 |
String replacement = "[" + url + "](" + url + ")"; |
| 2076 |
line = line.substr(0, pos) + replacement + line.substr(close_pos + URL_CLOSE_TAG_LENGTH); |
| 2077 |
pos += replacement.length(); |
| 2078 |
} |
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
const Vector<String> link_start_patterns = { |
| 2083 |
"[class ", "[method ", "[member ", "[signal ", "[enum ", "[constant ", |
| 2084 |
"[annotation ", "[constructor ", "[operator ", "[theme_item ", "[param " |
| 2085 |
}; |
| 2086 |
for (const String &pattern : link_start_patterns) { |
| 2087 |
int pattern_pos = 0; |
| 2088 |
while ((pattern_pos = line.find(pattern, pattern_pos)) != -1) { |
| 2089 |
int end_pos = line.find_char(']', pattern_pos); |
| 2090 |
if (end_pos == -1) { |
| 2091 |
break; |
| 2092 |
} |
| 2093 |
|
| 2094 |
String content = line.substr(pattern_pos + pattern.length(), end_pos - pattern_pos - pattern.length()); |
| 2095 |
String replacement = "`" + content + "`"; |
| 2096 |
line = line.substr(0, pattern_pos) + replacement + line.substr(end_pos + 1); |
| 2097 |
pattern_pos += replacement.length(); |
| 2098 |
} |
| 2099 |
} |
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
const String attribute_tags[] = { |
| 2104 |
"color", "font", "img" |
| 2105 |
}; |
| 2106 |
for (const String &tag_name : attribute_tags) { |
| 2107 |
int tag_pos = 0; |
| 2108 |
while ((tag_pos = line.find("[" + tag_name + "=", tag_pos)) != -1) { |
| 2109 |
int end_pos = line.find_char(']', tag_pos); |
| 2110 |
if (end_pos == -1) { |
| 2111 |
break; |
| 2112 |
} |
| 2113 |
|
| 2114 |
line = line.substr(0, tag_pos) + line.substr(end_pos + 1); |
| 2115 |
} |
| 2116 |
} |
| 2117 |
} |
| 2118 |
|
| 2119 |
if (i < lines.size() - 1) { |
| 2120 |
line += "\n"; |
| 2121 |
} |
| 2122 |
markdown += line; |
| 2123 |
} |
| 2124 |
return markdown; |
| 2125 |
} |
| 2126 |
} |