lsp.hpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662
  1. /*************************************************************************/
  2. /* lsp.hpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GODOT_LSP_H
  31. #define GODOT_LSP_H
  32. #include "core/class_db.h"
  33. #include "core/list.h"
  34. #include "editor/doc/doc_data.h"
  35. namespace lsp {
  36. typedef String DocumentUri;
  37. /** Format BBCode documentation from DocData to markdown */
  38. static String marked_documentation(const String &p_bbcode);
  39. /**
  40. * Text documents are identified using a URI. On the protocol level, URIs are passed as strings.
  41. */
  42. struct TextDocumentIdentifier {
  43. /**
  44. * The text document's URI.
  45. */
  46. DocumentUri uri;
  47. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  48. uri = p_params["uri"];
  49. }
  50. _FORCE_INLINE_ Dictionary to_json() const {
  51. Dictionary dict;
  52. dict["uri"] = uri;
  53. return dict;
  54. }
  55. };
  56. /**
  57. * Position in a text document expressed as zero-based line and zero-based character offset.
  58. * A position is between two characters like an ‘insert’ cursor in a editor.
  59. * Special values like for example -1 to denote the end of a line are not supported.
  60. */
  61. struct Position {
  62. /**
  63. * Line position in a document (zero-based).
  64. */
  65. int line = 0;
  66. /**
  67. * Character offset on a line in a document (zero-based). Assuming that the line is
  68. * represented as a string, the `character` value represents the gap between the
  69. * `character` and `character + 1`.
  70. *
  71. * If the character value is greater than the line length it defaults back to the
  72. * line length.
  73. */
  74. int character = 0;
  75. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  76. line = p_params["line"];
  77. character = p_params["character"];
  78. }
  79. _FORCE_INLINE_ Dictionary to_json() const {
  80. Dictionary dict;
  81. dict["line"] = line;
  82. dict["character"] = character;
  83. return dict;
  84. }
  85. };
  86. /**
  87. * A range in a text document expressed as (zero-based) start and end positions.
  88. * A range is comparable to a selection in an editor. Therefore the end position is exclusive.
  89. * If you want to specify a range that contains a line including the line ending character(s) then use an end position denoting the start of the next line.
  90. */
  91. struct Range {
  92. /**
  93. * The range's start position.
  94. */
  95. Position start;
  96. /**
  97. * The range's end position.
  98. */
  99. Position end;
  100. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  101. start.load(p_params["start"]);
  102. end.load(p_params["end"]);
  103. }
  104. _FORCE_INLINE_ Dictionary to_json() const {
  105. Dictionary dict;
  106. dict["start"] = start.to_json();
  107. dict["end"] = end.to_json();
  108. return dict;
  109. }
  110. };
  111. /**
  112. * Represents a location inside a resource, such as a line inside a text file.
  113. */
  114. struct Location {
  115. DocumentUri uri;
  116. Range range;
  117. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  118. uri = p_params["uri"];
  119. range.load(p_params["range"]);
  120. }
  121. _FORCE_INLINE_ Dictionary to_json() const {
  122. Dictionary dict;
  123. dict["uri"] = uri;
  124. dict["range"] = range.to_json();
  125. return dict;
  126. }
  127. };
  128. /**
  129. * Represents a link between a source and a target location.
  130. */
  131. struct LocationLink {
  132. /**
  133. * Span of the origin of this link.
  134. *
  135. * Used as the underlined span for mouse interaction. Defaults to the word range at
  136. * the mouse position.
  137. */
  138. Range *originSelectionRange = NULL;
  139. /**
  140. * The target resource identifier of this link.
  141. */
  142. String targetUri;
  143. /**
  144. * The full target range of this link. If the target for example is a symbol then target range is the
  145. * range enclosing this symbol not including leading/trailing whitespace but everything else
  146. * like comments. This information is typically used to highlight the range in the editor.
  147. */
  148. Range targetRange;
  149. /**
  150. * The range that should be selected and revealed when this link is being followed, e.g the name of a function.
  151. * Must be contained by the the `targetRange`. See also `DocumentSymbol#range`
  152. */
  153. Range targetSelectionRange;
  154. };
  155. /**
  156. * A parameter literal used in requests to pass a text document and a position inside that document.
  157. */
  158. struct TextDocumentPositionParams {
  159. /**
  160. * The text document.
  161. */
  162. TextDocumentIdentifier textDocument;
  163. /**
  164. * The position inside the text document.
  165. */
  166. Position position;
  167. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  168. textDocument.load(p_params["textDocument"]);
  169. position.load(p_params["position"]);
  170. }
  171. _FORCE_INLINE_ Dictionary to_json() const {
  172. Dictionary dict;
  173. dict["textDocument"] = textDocument.to_json();
  174. dict["position"] = position.to_json();
  175. return dict;
  176. }
  177. };
  178. struct DocumentLinkParams {
  179. /**
  180. * The document to provide document links for.
  181. */
  182. TextDocumentIdentifier textDocument;
  183. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  184. textDocument.load(p_params["textDocument"]);
  185. }
  186. };
  187. /**
  188. * A document link is a range in a text document that links to an internal or external resource, like another
  189. * text document or a web site.
  190. */
  191. struct DocumentLink {
  192. /**
  193. * The range this link applies to.
  194. */
  195. Range range;
  196. /**
  197. * The uri this link points to. If missing a resolve request is sent later.
  198. */
  199. DocumentUri target;
  200. Dictionary to_json() const {
  201. Dictionary dict;
  202. dict["range"] = range.to_json();
  203. dict["target"] = target;
  204. return dict;
  205. }
  206. };
  207. /**
  208. * A textual edit applicable to a text document.
  209. */
  210. struct TextEdit {
  211. /**
  212. * The range of the text document to be manipulated. To insert
  213. * text into a document create a range where start === end.
  214. */
  215. Range range;
  216. /**
  217. * The string to be inserted. For delete operations use an
  218. * empty string.
  219. */
  220. String newText;
  221. };
  222. /**
  223. * Represents a reference to a command.
  224. * Provides a title which will be used to represent a command in the UI.
  225. * Commands are identified by a string identifier.
  226. * The recommended way to handle commands is to implement their execution on the server side if the client and server provides the corresponding capabilities.
  227. * Alternatively the tool extension code could handle the command. The protocol currently doesn’t specify a set of well-known commands.
  228. */
  229. struct Command {
  230. /**
  231. * Title of the command, like `save`.
  232. */
  233. String title;
  234. /**
  235. * The identifier of the actual command handler.
  236. */
  237. String command;
  238. /**
  239. * Arguments that the command handler should be
  240. * invoked with.
  241. */
  242. Array arguments;
  243. Dictionary to_json() const {
  244. Dictionary dict;
  245. dict["title"] = title;
  246. dict["command"] = command;
  247. if (arguments.size()) dict["arguments"] = arguments;
  248. return dict;
  249. }
  250. };
  251. // Use namespace instead of enumeration to follow the LSP specifications
  252. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  253. namespace TextDocumentSyncKind {
  254. /**
  255. * Documents should not be synced at all.
  256. */
  257. static const int None = 0;
  258. /**
  259. * Documents are synced by always sending the full content
  260. * of the document.
  261. */
  262. static const int Full = 1;
  263. /**
  264. * Documents are synced by sending the full content on open.
  265. * After that only incremental updates to the document are
  266. * send.
  267. */
  268. static const int Incremental = 2;
  269. }; // namespace TextDocumentSyncKind
  270. /**
  271. * Completion options.
  272. */
  273. struct CompletionOptions {
  274. /**
  275. * The server provides support to resolve additional
  276. * information for a completion item.
  277. */
  278. bool resolveProvider = true;
  279. /**
  280. * The characters that trigger completion automatically.
  281. */
  282. Vector<String> triggerCharacters;
  283. CompletionOptions() {
  284. triggerCharacters.push_back(".");
  285. triggerCharacters.push_back("$");
  286. triggerCharacters.push_back("'");
  287. triggerCharacters.push_back("\"");
  288. triggerCharacters.push_back("(");
  289. triggerCharacters.push_back(",");
  290. }
  291. Dictionary to_json() const {
  292. Dictionary dict;
  293. dict["resolveProvider"] = resolveProvider;
  294. dict["triggerCharacters"] = triggerCharacters;
  295. return dict;
  296. }
  297. };
  298. /**
  299. * Signature help options.
  300. */
  301. struct SignatureHelpOptions {
  302. /**
  303. * The characters that trigger signature help
  304. * automatically.
  305. */
  306. Vector<String> triggerCharacters;
  307. Dictionary to_json() {
  308. Dictionary dict;
  309. dict["triggerCharacters"] = triggerCharacters;
  310. return dict;
  311. }
  312. };
  313. /**
  314. * Code Lens options.
  315. */
  316. struct CodeLensOptions {
  317. /**
  318. * Code lens has a resolve provider as well.
  319. */
  320. bool resolveProvider = false;
  321. Dictionary to_json() {
  322. Dictionary dict;
  323. dict["resolveProvider"] = resolveProvider;
  324. return dict;
  325. }
  326. };
  327. /**
  328. * Rename options
  329. */
  330. struct RenameOptions {
  331. /**
  332. * Renames should be checked and tested before being executed.
  333. */
  334. bool prepareProvider = false;
  335. Dictionary to_json() {
  336. Dictionary dict;
  337. dict["prepareProvider"] = prepareProvider;
  338. return dict;
  339. }
  340. };
  341. /**
  342. * Document link options.
  343. */
  344. struct DocumentLinkOptions {
  345. /**
  346. * Document links have a resolve provider as well.
  347. */
  348. bool resolveProvider = false;
  349. Dictionary to_json() {
  350. Dictionary dict;
  351. dict["resolveProvider"] = resolveProvider;
  352. return dict;
  353. }
  354. };
  355. /**
  356. * Execute command options.
  357. */
  358. struct ExecuteCommandOptions {
  359. /**
  360. * The commands to be executed on the server
  361. */
  362. Vector<String> commands;
  363. Dictionary to_json() {
  364. Dictionary dict;
  365. dict["commands"] = commands;
  366. return dict;
  367. }
  368. };
  369. /**
  370. * Save options.
  371. */
  372. struct SaveOptions {
  373. /**
  374. * The client is supposed to include the content on save.
  375. */
  376. bool includeText = true;
  377. Dictionary to_json() {
  378. Dictionary dict;
  379. dict["includeText"] = includeText;
  380. return dict;
  381. }
  382. };
  383. /**
  384. * Color provider options.
  385. */
  386. struct ColorProviderOptions {
  387. Dictionary to_json() {
  388. Dictionary dict;
  389. return dict;
  390. }
  391. };
  392. /**
  393. * Folding range provider options.
  394. */
  395. struct FoldingRangeProviderOptions {
  396. Dictionary to_json() {
  397. Dictionary dict;
  398. return dict;
  399. }
  400. };
  401. struct TextDocumentSyncOptions {
  402. /**
  403. * Open and close notifications are sent to the server. If omitted open close notification should not
  404. * be sent.
  405. */
  406. bool openClose = true;
  407. /**
  408. * Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full
  409. * and TextDocumentSyncKind.Incremental. If omitted it defaults to TextDocumentSyncKind.None.
  410. */
  411. int change = TextDocumentSyncKind::Full;
  412. /**
  413. * If present will save notifications are sent to the server. If omitted the notification should not be
  414. * sent.
  415. */
  416. bool willSave = false;
  417. /**
  418. * If present will save wait until requests are sent to the server. If omitted the request should not be
  419. * sent.
  420. */
  421. bool willSaveWaitUntil = false;
  422. /**
  423. * If present save notifications are sent to the server. If omitted the notification should not be
  424. * sent.
  425. */
  426. SaveOptions save;
  427. Dictionary to_json() {
  428. Dictionary dict;
  429. dict["willSaveWaitUntil"] = willSaveWaitUntil;
  430. dict["willSave"] = willSave;
  431. dict["openClose"] = openClose;
  432. dict["change"] = change;
  433. dict["change"] = save.to_json();
  434. return dict;
  435. }
  436. };
  437. /**
  438. * Static registration options to be returned in the initialize request.
  439. */
  440. struct StaticRegistrationOptions {
  441. /**
  442. * The id used to register the request. The id can be used to deregister
  443. * the request again. See also Registration#id.
  444. */
  445. String id;
  446. };
  447. /**
  448. * Format document on type options.
  449. */
  450. struct DocumentOnTypeFormattingOptions {
  451. /**
  452. * A character on which formatting should be triggered, like `}`.
  453. */
  454. String firstTriggerCharacter;
  455. /**
  456. * More trigger characters.
  457. */
  458. Vector<String> moreTriggerCharacter;
  459. Dictionary to_json() {
  460. Dictionary dict;
  461. dict["firstTriggerCharacter"] = firstTriggerCharacter;
  462. dict["moreTriggerCharacter"] = moreTriggerCharacter;
  463. return dict;
  464. }
  465. };
  466. struct TextDocumentItem {
  467. /**
  468. * The text document's URI.
  469. */
  470. DocumentUri uri;
  471. /**
  472. * The text document's language identifier.
  473. */
  474. String languageId;
  475. /**
  476. * The version number of this document (it will increase after each
  477. * change, including undo/redo).
  478. */
  479. int version;
  480. /**
  481. * The content of the opened text document.
  482. */
  483. String text;
  484. void load(const Dictionary &p_dict) {
  485. uri = p_dict["uri"];
  486. languageId = p_dict["languageId"];
  487. version = p_dict["version"];
  488. text = p_dict["text"];
  489. }
  490. Dictionary to_json() const {
  491. Dictionary dict;
  492. dict["uri"] = uri;
  493. dict["languageId"] = languageId;
  494. dict["version"] = version;
  495. dict["text"] = text;
  496. return dict;
  497. }
  498. };
  499. /**
  500. * An event describing a change to a text document. If range and rangeLength are omitted
  501. * the new text is considered to be the full content of the document.
  502. */
  503. struct TextDocumentContentChangeEvent {
  504. /**
  505. * The range of the document that changed.
  506. */
  507. Range range;
  508. /**
  509. * The length of the range that got replaced.
  510. */
  511. int rangeLength;
  512. /**
  513. * The new text of the range/document.
  514. */
  515. String text;
  516. void load(const Dictionary &p_params) {
  517. text = p_params["text"];
  518. rangeLength = p_params["rangeLength"];
  519. range.load(p_params["range"]);
  520. }
  521. };
  522. // Use namespace instead of enumeration to follow the LSP specifications
  523. namespace DiagnosticSeverity {
  524. /**
  525. * Reports an error.
  526. */
  527. static const int Error = 1;
  528. /**
  529. * Reports a warning.
  530. */
  531. static const int Warning = 2;
  532. /**
  533. * Reports an information.
  534. */
  535. static const int Information = 3;
  536. /**
  537. * Reports a hint.
  538. */
  539. static const int Hint = 4;
  540. }; // namespace DiagnosticSeverity
  541. /**
  542. * Represents a related message and source code location for a diagnostic. This should be
  543. * used to point to code locations that cause or related to a diagnostics, e.g when duplicating
  544. * a symbol in a scope.
  545. */
  546. struct DiagnosticRelatedInformation {
  547. /**
  548. * The location of this related diagnostic information.
  549. */
  550. Location location;
  551. /**
  552. * The message of this related diagnostic information.
  553. */
  554. String message;
  555. Dictionary to_json() const {
  556. Dictionary dict;
  557. dict["location"] = location.to_json(),
  558. dict["message"] = message;
  559. return dict;
  560. }
  561. };
  562. /**
  563. * Represents a diagnostic, such as a compiler error or warning.
  564. * Diagnostic objects are only valid in the scope of a resource.
  565. */
  566. struct Diagnostic {
  567. /**
  568. * The range at which the message applies.
  569. */
  570. Range range;
  571. /**
  572. * The diagnostic's severity. Can be omitted. If omitted it is up to the
  573. * client to interpret diagnostics as error, warning, info or hint.
  574. */
  575. int severity;
  576. /**
  577. * The diagnostic's code, which might appear in the user interface.
  578. */
  579. int code;
  580. /**
  581. * A human-readable string describing the source of this
  582. * diagnostic, e.g. 'typescript' or 'super lint'.
  583. */
  584. String source;
  585. /**
  586. * The diagnostic's message.
  587. */
  588. String message;
  589. /**
  590. * An array of related diagnostic information, e.g. when symbol-names within
  591. * a scope collide all definitions can be marked via this property.
  592. */
  593. Vector<DiagnosticRelatedInformation> relatedInformation;
  594. Dictionary to_json() const {
  595. Dictionary dict;
  596. dict["range"] = range.to_json();
  597. dict["code"] = code;
  598. dict["severity"] = severity;
  599. dict["message"] = message;
  600. dict["source"] = source;
  601. if (!relatedInformation.empty()) {
  602. Array arr;
  603. arr.resize(relatedInformation.size());
  604. for (int i = 0; i < relatedInformation.size(); i++) {
  605. arr[i] = relatedInformation[i].to_json();
  606. }
  607. dict["relatedInformation"] = arr;
  608. }
  609. return dict;
  610. }
  611. };
  612. // Use namespace instead of enumeration to follow the LSP specifications
  613. /**
  614. * Describes the content type that a client supports in various
  615. * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
  616. *
  617. * Please note that `MarkupKinds` must not start with a `$`. This kinds
  618. * are reserved for internal usage.
  619. */
  620. namespace MarkupKind {
  621. static const String PlainText = "plaintext";
  622. static const String Markdown = "markdown";
  623. }; // namespace MarkupKind
  624. /**
  625. * A `MarkupContent` literal represents a string value which content is interpreted base on its
  626. * kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
  627. *
  628. * If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
  629. * See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
  630. *
  631. * Here is an example how such a string can be constructed using JavaScript / TypeScript:
  632. * ```typescript
  633. * let markdown: MarkdownContent = {
  634. * kind: MarkupKind.Markdown,
  635. * value: [
  636. * '# Header',
  637. * 'Some text',
  638. * '```typescript',
  639. * 'someCode();',
  640. * '```'
  641. * ].join('\n')
  642. * };
  643. * ```
  644. *
  645. * *Please Note* that clients might sanitize the return markdown. A client could decide to
  646. * remove HTML from the markdown to avoid script execution.
  647. */
  648. struct MarkupContent {
  649. /**
  650. * The type of the Markup
  651. */
  652. String kind;
  653. /**
  654. * The content itself
  655. */
  656. String value;
  657. MarkupContent() {
  658. kind = MarkupKind::Markdown;
  659. }
  660. MarkupContent(const String &p_value) {
  661. value = p_value;
  662. kind = MarkupKind::Markdown;
  663. }
  664. Dictionary to_json() const {
  665. Dictionary dict;
  666. dict["kind"] = kind;
  667. dict["value"] = value;
  668. return dict;
  669. }
  670. };
  671. // Use namespace instead of enumeration to follow the LSP specifications
  672. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  673. // And here C++ compilers are unhappy with our enumeration name like Color, File, Reference etc.
  674. /**
  675. * The kind of a completion entry.
  676. */
  677. namespace CompletionItemKind {
  678. static const int Text = 1;
  679. static const int Method = 2;
  680. static const int Function = 3;
  681. static const int Constructor = 4;
  682. static const int Field = 5;
  683. static const int Variable = 6;
  684. static const int Class = 7;
  685. static const int Interface = 8;
  686. static const int Module = 9;
  687. static const int Property = 10;
  688. static const int Unit = 11;
  689. static const int Value = 12;
  690. static const int Enum = 13;
  691. static const int Keyword = 14;
  692. static const int Snippet = 15;
  693. static const int Color = 16;
  694. static const int File = 17;
  695. static const int Reference = 18;
  696. static const int Folder = 19;
  697. static const int EnumMember = 20;
  698. static const int Constant = 21;
  699. static const int Struct = 22;
  700. static const int Event = 23;
  701. static const int Operator = 24;
  702. static const int TypeParameter = 25;
  703. }; // namespace CompletionItemKind
  704. // Use namespace instead of enumeration to follow the LSP specifications
  705. /**
  706. * Defines whether the insert text in a completion item should be interpreted as
  707. * plain text or a snippet.
  708. */
  709. namespace InsertTextFormat {
  710. /**
  711. * The primary text to be inserted is treated as a plain string.
  712. */
  713. static const int PlainText = 1;
  714. /**
  715. * The primary text to be inserted is treated as a snippet.
  716. *
  717. * A snippet can define tab stops and placeholders with `$1`, `$2`
  718. * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
  719. * the end of the snippet. Placeholders with equal identifiers are linked,
  720. * that is typing in one will update others too.
  721. */
  722. static const int Snippet = 2;
  723. }; // namespace InsertTextFormat
  724. struct CompletionItem {
  725. /**
  726. * The label of this completion item. By default
  727. * also the text that is inserted when selecting
  728. * this completion.
  729. */
  730. String label;
  731. /**
  732. * The kind of this completion item. Based of the kind
  733. * an icon is chosen by the editor. The standardized set
  734. * of available values is defined in `CompletionItemKind`.
  735. */
  736. int kind;
  737. /**
  738. * A human-readable string with additional information
  739. * about this item, like type or symbol information.
  740. */
  741. String detail;
  742. /**
  743. * A human-readable string that represents a doc-comment.
  744. */
  745. MarkupContent documentation;
  746. /**
  747. * Indicates if this item is deprecated.
  748. */
  749. bool deprecated = false;
  750. /**
  751. * Select this item when showing.
  752. *
  753. * *Note* that only one completion item can be selected and that the
  754. * tool / client decides which item that is. The rule is that the *first*
  755. * item of those that match best is selected.
  756. */
  757. bool preselect = false;
  758. /**
  759. * A string that should be used when comparing this item
  760. * with other items. When `falsy` the label is used.
  761. */
  762. String sortText;
  763. /**
  764. * A string that should be used when filtering a set of
  765. * completion items. When `falsy` the label is used.
  766. */
  767. String filterText;
  768. /**
  769. * A string that should be inserted into a document when selecting
  770. * this completion. When `falsy` the label is used.
  771. *
  772. * The `insertText` is subject to interpretation by the client side.
  773. * Some tools might not take the string literally. For example
  774. * VS Code when code complete is requested in this example `con<cursor position>`
  775. * and a completion item with an `insertText` of `console` is provided it
  776. * will only insert `sole`. Therefore it is recommended to use `textEdit` instead
  777. * since it avoids additional client side interpretation.
  778. *
  779. * @deprecated Use textEdit instead.
  780. */
  781. String insertText;
  782. /**
  783. * The format of the insert text. The format applies to both the `insertText` property
  784. * and the `newText` property of a provided `textEdit`.
  785. */
  786. int insertTextFormat;
  787. /**
  788. * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
  789. * `insertText` is ignored.
  790. *
  791. * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
  792. * has been requested.
  793. */
  794. TextEdit textEdit;
  795. /**
  796. * An optional array of additional text edits that are applied when
  797. * selecting this completion. Edits must not overlap (including the same insert position)
  798. * with the main edit nor with themselves.
  799. *
  800. * Additional text edits should be used to change text unrelated to the current cursor position
  801. * (for example adding an import statement at the top of the file if the completion item will
  802. * insert an unqualified type).
  803. */
  804. Vector<TextEdit> additionalTextEdits;
  805. /**
  806. * An optional set of characters that when pressed while this completion is active will accept it first and
  807. * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
  808. * characters will be ignored.
  809. */
  810. Vector<String> commitCharacters;
  811. /**
  812. * An optional command that is executed *after* inserting this completion. *Note* that
  813. * additional modifications to the current document should be described with the
  814. * additionalTextEdits-property.
  815. */
  816. Command command;
  817. /**
  818. * A data entry field that is preserved on a completion item between
  819. * a completion and a completion resolve request.
  820. */
  821. Variant data;
  822. _FORCE_INLINE_ Dictionary to_json(bool resolved = false) const {
  823. Dictionary dict;
  824. dict["label"] = label;
  825. dict["kind"] = kind;
  826. dict["data"] = data;
  827. if (resolved) {
  828. dict["insertText"] = insertText;
  829. dict["detail"] = detail;
  830. dict["documentation"] = documentation.to_json();
  831. dict["deprecated"] = deprecated;
  832. dict["preselect"] = preselect;
  833. dict["sortText"] = sortText;
  834. dict["filterText"] = filterText;
  835. if (commitCharacters.size()) dict["commitCharacters"] = commitCharacters;
  836. dict["command"] = command.to_json();
  837. }
  838. return dict;
  839. }
  840. void load(const Dictionary &p_dict) {
  841. if (p_dict.has("label")) label = p_dict["label"];
  842. if (p_dict.has("kind")) kind = p_dict["kind"];
  843. if (p_dict.has("detail")) detail = p_dict["detail"];
  844. if (p_dict.has("documentation")) {
  845. Variant doc = p_dict["documentation"];
  846. if (doc.get_type() == Variant::STRING) {
  847. documentation.value = doc;
  848. } else if (doc.get_type() == Variant::DICTIONARY) {
  849. Dictionary v = doc;
  850. documentation.value = v["value"];
  851. }
  852. }
  853. if (p_dict.has("deprecated")) deprecated = p_dict["deprecated"];
  854. if (p_dict.has("preselect")) preselect = p_dict["preselect"];
  855. if (p_dict.has("sortText")) sortText = p_dict["sortText"];
  856. if (p_dict.has("filterText")) filterText = p_dict["filterText"];
  857. if (p_dict.has("insertText")) insertText = p_dict["insertText"];
  858. if (p_dict.has("data")) data = p_dict["data"];
  859. }
  860. };
  861. /**
  862. * Represents a collection of [completion items](#CompletionItem) to be presented
  863. * in the editor.
  864. */
  865. struct CompletionList {
  866. /**
  867. * This list it not complete. Further typing should result in recomputing
  868. * this list.
  869. */
  870. bool isIncomplete;
  871. /**
  872. * The completion items.
  873. */
  874. Vector<CompletionItem> items;
  875. };
  876. // Use namespace instead of enumeration to follow the LSP specifications
  877. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  878. // And here C++ compilers are unhappy with our enumeration name like String, Array, Object etc
  879. /**
  880. * A symbol kind.
  881. */
  882. namespace SymbolKind {
  883. static const int File = 0;
  884. static const int Module = 1;
  885. static const int Namespace = 2;
  886. static const int Package = 3;
  887. static const int Class = 4;
  888. static const int Method = 5;
  889. static const int Property = 6;
  890. static const int Field = 7;
  891. static const int Constructor = 8;
  892. static const int Enum = 9;
  893. static const int Interface = 10;
  894. static const int Function = 11;
  895. static const int Variable = 12;
  896. static const int Constant = 13;
  897. static const int String = 14;
  898. static const int Number = 15;
  899. static const int Boolean = 16;
  900. static const int Array = 17;
  901. static const int Object = 18;
  902. static const int Key = 19;
  903. static const int Null = 20;
  904. static const int EnumMember = 21;
  905. static const int Struct = 22;
  906. static const int Event = 23;
  907. static const int Operator = 24;
  908. static const int TypeParameter = 25;
  909. }; // namespace SymbolKind
  910. /**
  911. * Represents information about programming constructs like variables, classes,
  912. * interfaces etc.
  913. */
  914. struct SymbolInformation {
  915. /**
  916. * The name of this symbol.
  917. */
  918. String name;
  919. /**
  920. * The kind of this symbol.
  921. */
  922. int kind = SymbolKind::File;
  923. /**
  924. * Indicates if this symbol is deprecated.
  925. */
  926. bool deprecated = false;
  927. /**
  928. * The location of this symbol. The location's range is used by a tool
  929. * to reveal the location in the editor. If the symbol is selected in the
  930. * tool the range's start information is used to position the cursor. So
  931. * the range usually spans more then the actual symbol's name and does
  932. * normally include things like visibility modifiers.
  933. *
  934. * The range doesn't have to denote a node range in the sense of a abstract
  935. * syntax tree. It can therefore not be used to re-construct a hierarchy of
  936. * the symbols.
  937. */
  938. Location location;
  939. /**
  940. * The name of the symbol containing this symbol. This information is for
  941. * user interface purposes (e.g. to render a qualifier in the user interface
  942. * if necessary). It can't be used to re-infer a hierarchy for the document
  943. * symbols.
  944. */
  945. String containerName;
  946. _FORCE_INLINE_ Dictionary to_json() const {
  947. Dictionary dict;
  948. dict["name"] = name;
  949. dict["kind"] = kind;
  950. dict["deprecated"] = deprecated;
  951. dict["location"] = location.to_json();
  952. dict["containerName"] = containerName;
  953. return dict;
  954. }
  955. };
  956. struct DocumentedSymbolInformation : public SymbolInformation {
  957. /**
  958. * A human-readable string with additional information
  959. */
  960. String detail;
  961. /**
  962. * A human-readable string that represents a doc-comment.
  963. */
  964. String documentation;
  965. };
  966. /**
  967. * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
  968. * hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
  969. * e.g. the range of an identifier.
  970. */
  971. struct DocumentSymbol {
  972. /**
  973. * The name of this symbol. Will be displayed in the user interface and therefore must not be
  974. * an empty string or a string only consisting of white spaces.
  975. */
  976. String name;
  977. /**
  978. * More detail for this symbol, e.g the signature of a function.
  979. */
  980. String detail;
  981. /**
  982. * Documentation for this symbol
  983. */
  984. String documentation;
  985. /**
  986. * Class name for the native symbols
  987. */
  988. String native_class;
  989. /**
  990. * The kind of this symbol.
  991. */
  992. int kind = SymbolKind::File;
  993. /**
  994. * Indicates if this symbol is deprecated.
  995. */
  996. bool deprecated = false;
  997. /**
  998. * The range enclosing this symbol not including leading/trailing whitespace but everything else
  999. * like comments. This information is typically used to determine if the clients cursor is
  1000. * inside the symbol to reveal in the symbol in the UI.
  1001. */
  1002. Range range;
  1003. /**
  1004. * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
  1005. * Must be contained by the `range`.
  1006. */
  1007. Range selectionRange;
  1008. DocumentUri uri;
  1009. String script_path;
  1010. /**
  1011. * Children of this symbol, e.g. properties of a class.
  1012. */
  1013. Vector<DocumentSymbol> children;
  1014. Dictionary to_json(bool with_doc = false) const {
  1015. Dictionary dict;
  1016. dict["name"] = name;
  1017. dict["detail"] = detail;
  1018. dict["kind"] = kind;
  1019. dict["deprecated"] = deprecated;
  1020. dict["range"] = range.to_json();
  1021. dict["selectionRange"] = selectionRange.to_json();
  1022. if (with_doc) {
  1023. dict["documentation"] = documentation;
  1024. dict["native_class"] = native_class;
  1025. }
  1026. Array arr;
  1027. arr.resize(children.size());
  1028. for (int i = 0; i < children.size(); i++) {
  1029. arr[i] = children[i].to_json(with_doc);
  1030. }
  1031. dict["children"] = arr;
  1032. return dict;
  1033. }
  1034. void symbol_tree_as_list(const String &p_uri, Vector<DocumentedSymbolInformation> &r_list, const String &p_container = "", bool p_join_name = false) const {
  1035. DocumentedSymbolInformation si;
  1036. if (p_join_name && !p_container.empty()) {
  1037. si.name = p_container + ">" + name;
  1038. } else {
  1039. si.name = name;
  1040. }
  1041. si.kind = kind;
  1042. si.containerName = p_container;
  1043. si.deprecated = deprecated;
  1044. si.location.uri = p_uri;
  1045. si.location.range = range;
  1046. si.detail = detail;
  1047. si.documentation = documentation;
  1048. r_list.push_back(si);
  1049. for (int i = 0; i < children.size(); i++) {
  1050. children[i].symbol_tree_as_list(p_uri, r_list, si.name, p_join_name);
  1051. }
  1052. }
  1053. _FORCE_INLINE_ MarkupContent render() const {
  1054. MarkupContent markdown;
  1055. if (detail.length()) {
  1056. markdown.value = "\t" + detail + "\n\n";
  1057. }
  1058. if (documentation.length()) {
  1059. markdown.value += marked_documentation(documentation) + "\n\n";
  1060. }
  1061. if (script_path.length()) {
  1062. markdown.value += "Defined in [" + script_path + "](" + uri + ")";
  1063. }
  1064. return markdown;
  1065. }
  1066. _FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const {
  1067. lsp::CompletionItem item;
  1068. item.label = name;
  1069. if (resolved) {
  1070. item.documentation = render();
  1071. }
  1072. switch (kind) {
  1073. case lsp::SymbolKind::Enum:
  1074. item.kind = lsp::CompletionItemKind::Enum;
  1075. break;
  1076. case lsp::SymbolKind::Class:
  1077. item.kind = lsp::CompletionItemKind::Class;
  1078. break;
  1079. case lsp::SymbolKind::Property:
  1080. item.kind = lsp::CompletionItemKind::Property;
  1081. break;
  1082. case lsp::SymbolKind::Method:
  1083. case lsp::SymbolKind::Function:
  1084. item.kind = lsp::CompletionItemKind::Method;
  1085. break;
  1086. case lsp::SymbolKind::Event:
  1087. item.kind = lsp::CompletionItemKind::Event;
  1088. break;
  1089. case lsp::SymbolKind::Constant:
  1090. item.kind = lsp::CompletionItemKind::Constant;
  1091. break;
  1092. case lsp::SymbolKind::Variable:
  1093. item.kind = lsp::CompletionItemKind::Variable;
  1094. break;
  1095. case lsp::SymbolKind::File:
  1096. item.kind = lsp::CompletionItemKind::File;
  1097. break;
  1098. default:
  1099. item.kind = lsp::CompletionItemKind::Text;
  1100. break;
  1101. }
  1102. return item;
  1103. }
  1104. };
  1105. struct NativeSymbolInspectParams {
  1106. String native_class;
  1107. String symbol_name;
  1108. void load(const Dictionary &p_params) {
  1109. native_class = p_params["native_class"];
  1110. symbol_name = p_params["symbol_name"];
  1111. }
  1112. };
  1113. /**
  1114. * Enum of known range kinds
  1115. */
  1116. namespace FoldingRangeKind {
  1117. /**
  1118. * Folding range for a comment
  1119. */
  1120. static const String Comment = "comment";
  1121. /**
  1122. * Folding range for a imports or includes
  1123. */
  1124. static const String Imports = "imports";
  1125. /**
  1126. * Folding range for a region (e.g. `#region`)
  1127. */
  1128. static const String Region = "region";
  1129. } // namespace FoldingRangeKind
  1130. /**
  1131. * Represents a folding range.
  1132. */
  1133. struct FoldingRange {
  1134. /**
  1135. * The zero-based line number from where the folded range starts.
  1136. */
  1137. int startLine = 0;
  1138. /**
  1139. * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
  1140. */
  1141. int startCharacter = 0;
  1142. /**
  1143. * The zero-based line number where the folded range ends.
  1144. */
  1145. int endLine = 0;
  1146. /**
  1147. * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
  1148. */
  1149. int endCharacter = 0;
  1150. /**
  1151. * Describes the kind of the folding range such as `comment' or 'region'. The kind
  1152. * is used to categorize folding ranges and used by commands like 'Fold all comments'. See
  1153. * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
  1154. */
  1155. String kind = FoldingRangeKind::Region;
  1156. _FORCE_INLINE_ Dictionary to_json() const {
  1157. Dictionary dict;
  1158. dict["startLine"] = startLine;
  1159. dict["startCharacter"] = startCharacter;
  1160. dict["endLine"] = endLine;
  1161. dict["endCharacter"] = endCharacter;
  1162. return dict;
  1163. }
  1164. };
  1165. // Use namespace instead of enumeration to follow the LSP specifications
  1166. /**
  1167. * How a completion was triggered
  1168. */
  1169. namespace CompletionTriggerKind {
  1170. /**
  1171. * Completion was triggered by typing an identifier (24x7 code
  1172. * complete), manual invocation (e.g Ctrl+Space) or via API.
  1173. */
  1174. static const int Invoked = 1;
  1175. /**
  1176. * Completion was triggered by a trigger character specified by
  1177. * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
  1178. */
  1179. static const int TriggerCharacter = 2;
  1180. /**
  1181. * Completion was re-triggered as the current completion list is incomplete.
  1182. */
  1183. static const int TriggerForIncompleteCompletions = 3;
  1184. } // namespace CompletionTriggerKind
  1185. /**
  1186. * Contains additional information about the context in which a completion request is triggered.
  1187. */
  1188. struct CompletionContext {
  1189. /**
  1190. * How the completion was triggered.
  1191. */
  1192. int triggerKind = CompletionTriggerKind::TriggerCharacter;
  1193. /**
  1194. * The trigger character (a single character) that has trigger code complete.
  1195. * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
  1196. */
  1197. String triggerCharacter;
  1198. void load(const Dictionary &p_params) {
  1199. triggerKind = int(p_params["triggerKind"]);
  1200. triggerCharacter = p_params["triggerCharacter"];
  1201. }
  1202. };
  1203. struct CompletionParams : public TextDocumentPositionParams {
  1204. /**
  1205. * The completion context. This is only available if the client specifies
  1206. * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
  1207. */
  1208. CompletionContext context;
  1209. void load(const Dictionary &p_params) {
  1210. TextDocumentPositionParams::load(p_params);
  1211. context.load(p_params["context"]);
  1212. }
  1213. };
  1214. /**
  1215. * The result of a hover request.
  1216. */
  1217. struct Hover {
  1218. /**
  1219. * The hover's content
  1220. */
  1221. MarkupContent contents;
  1222. /**
  1223. * An optional range is a range inside a text document
  1224. * that is used to visualize a hover, e.g. by changing the background color.
  1225. */
  1226. Range range;
  1227. _FORCE_INLINE_ Dictionary to_json() const {
  1228. Dictionary dict;
  1229. dict["range"] = range.to_json();
  1230. dict["contents"] = contents.to_json();
  1231. return dict;
  1232. }
  1233. };
  1234. struct ServerCapabilities {
  1235. /**
  1236. * Defines how text documents are synced. Is either a detailed structure defining each notification or
  1237. * for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`.
  1238. */
  1239. TextDocumentSyncOptions textDocumentSync;
  1240. /**
  1241. * The server provides hover support.
  1242. */
  1243. bool hoverProvider = true;
  1244. /**
  1245. * The server provides completion support.
  1246. */
  1247. CompletionOptions completionProvider;
  1248. /**
  1249. * The server provides signature help support.
  1250. */
  1251. SignatureHelpOptions signatureHelpProvider;
  1252. /**
  1253. * The server provides goto definition support.
  1254. */
  1255. bool definitionProvider = true;
  1256. /**
  1257. * The server provides Goto Type Definition support.
  1258. *
  1259. * Since 3.6.0
  1260. */
  1261. bool typeDefinitionProvider = false;
  1262. /**
  1263. * The server provides Goto Implementation support.
  1264. *
  1265. * Since 3.6.0
  1266. */
  1267. bool implementationProvider = false;
  1268. /**
  1269. * The server provides find references support.
  1270. */
  1271. bool referencesProvider = false;
  1272. /**
  1273. * The server provides document highlight support.
  1274. */
  1275. bool documentHighlightProvider = false;
  1276. /**
  1277. * The server provides document symbol support.
  1278. */
  1279. bool documentSymbolProvider = true;
  1280. /**
  1281. * The server provides workspace symbol support.
  1282. */
  1283. bool workspaceSymbolProvider = true;
  1284. /**
  1285. * The server provides code actions. The `CodeActionOptions` return type is only
  1286. * valid if the client signals code action literal support via the property
  1287. * `textDocument.codeAction.codeActionLiteralSupport`.
  1288. */
  1289. bool codeActionProvider = false;
  1290. /**
  1291. * The server provides code lens.
  1292. */
  1293. CodeLensOptions codeLensProvider;
  1294. /**
  1295. * The server provides document formatting.
  1296. */
  1297. bool documentFormattingProvider = false;
  1298. /**
  1299. * The server provides document range formatting.
  1300. */
  1301. bool documentRangeFormattingProvider = false;
  1302. /**
  1303. * The server provides document formatting on typing.
  1304. */
  1305. DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider;
  1306. /**
  1307. * The server provides rename support. RenameOptions may only be
  1308. * specified if the client states that it supports
  1309. * `prepareSupport` in its initial `initialize` request.
  1310. */
  1311. RenameOptions renameProvider;
  1312. /**
  1313. * The server provides document link support.
  1314. */
  1315. DocumentLinkOptions documentLinkProvider;
  1316. /**
  1317. * The server provides color provider support.
  1318. *
  1319. * Since 3.6.0
  1320. */
  1321. ColorProviderOptions colorProvider;
  1322. /**
  1323. * The server provides folding provider support.
  1324. *
  1325. * Since 3.10.0
  1326. */
  1327. FoldingRangeProviderOptions foldingRangeProvider;
  1328. /**
  1329. * The server provides go to declaration support.
  1330. *
  1331. * Since 3.14.0
  1332. */
  1333. bool declarationProvider = true;
  1334. /**
  1335. * The server provides execute command support.
  1336. */
  1337. ExecuteCommandOptions executeCommandProvider;
  1338. _FORCE_INLINE_ Dictionary to_json() {
  1339. Dictionary dict;
  1340. dict["textDocumentSync"] = (int)textDocumentSync.change;
  1341. dict["completionProvider"] = completionProvider.to_json();
  1342. dict["signatureHelpProvider"] = signatureHelpProvider.to_json();
  1343. dict["codeLensProvider"] = false; // codeLensProvider.to_json();
  1344. dict["documentOnTypeFormattingProvider"] = documentOnTypeFormattingProvider.to_json();
  1345. dict["renameProvider"] = renameProvider.to_json();
  1346. dict["documentLinkProvider"] = documentLinkProvider.to_json();
  1347. dict["colorProvider"] = false; // colorProvider.to_json();
  1348. dict["foldingRangeProvider"] = false; //foldingRangeProvider.to_json();
  1349. dict["executeCommandProvider"] = executeCommandProvider.to_json();
  1350. dict["hoverProvider"] = hoverProvider;
  1351. dict["definitionProvider"] = definitionProvider;
  1352. dict["typeDefinitionProvider"] = typeDefinitionProvider;
  1353. dict["implementationProvider"] = implementationProvider;
  1354. dict["referencesProvider"] = referencesProvider;
  1355. dict["documentHighlightProvider"] = documentHighlightProvider;
  1356. dict["documentSymbolProvider"] = documentSymbolProvider;
  1357. dict["workspaceSymbolProvider"] = workspaceSymbolProvider;
  1358. dict["codeActionProvider"] = codeActionProvider;
  1359. dict["documentFormattingProvider"] = documentFormattingProvider;
  1360. dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider;
  1361. dict["declarationProvider"] = declarationProvider;
  1362. return dict;
  1363. }
  1364. };
  1365. struct InitializeResult {
  1366. /**
  1367. * The capabilities the language server provides.
  1368. */
  1369. ServerCapabilities capabilities;
  1370. _FORCE_INLINE_ Dictionary to_json() {
  1371. Dictionary dict;
  1372. dict["capabilities"] = capabilities.to_json();
  1373. return dict;
  1374. }
  1375. };
  1376. struct GodotNativeClassInfo {
  1377. String name;
  1378. const DocData::ClassDoc *class_doc = NULL;
  1379. const ClassDB::ClassInfo *class_info = NULL;
  1380. Dictionary to_json() {
  1381. Dictionary dict;
  1382. dict["name"] = name;
  1383. dict["inherits"] = class_doc->inherits;
  1384. return dict;
  1385. }
  1386. };
  1387. /** Features not included in the standart lsp specifications */
  1388. struct GodotCapabilities {
  1389. /**
  1390. * Native class list
  1391. */
  1392. List<GodotNativeClassInfo> native_classes;
  1393. Dictionary to_json() {
  1394. Dictionary dict;
  1395. Array classes;
  1396. for (List<GodotNativeClassInfo>::Element *E = native_classes.front(); E; E = E->next()) {
  1397. classes.push_back(E->get().to_json());
  1398. }
  1399. dict["native_classes"] = classes;
  1400. return dict;
  1401. }
  1402. };
  1403. /** Format BBCode documentation from DocData to markdown */
  1404. static String marked_documentation(const String &p_bbcode) {
  1405. String markdown = p_bbcode.strip_edges();
  1406. Vector<String> lines = markdown.split("\n");
  1407. bool in_code_block = false;
  1408. int code_block_indent = -1;
  1409. markdown = "";
  1410. for (int i = 0; i < lines.size(); i++) {
  1411. String line = lines[i];
  1412. int block_start = line.find("[codeblock]");
  1413. if (block_start != -1) {
  1414. code_block_indent = block_start;
  1415. in_code_block = true;
  1416. line = "\n";
  1417. } else if (in_code_block) {
  1418. line = "\t" + line.substr(code_block_indent, line.length());
  1419. }
  1420. if (in_code_block && line.find("[/codeblock]") != -1) {
  1421. line = "\n";
  1422. in_code_block = false;
  1423. }
  1424. if (!in_code_block) {
  1425. line = line.strip_edges();
  1426. line = line.replace("[code]", "`");
  1427. line = line.replace("[/code]", "`");
  1428. line = line.replace("[i]", "*");
  1429. line = line.replace("[/i]", "*");
  1430. line = line.replace("[b]", "**");
  1431. line = line.replace("[/b]", "**");
  1432. line = line.replace("[u]", "__");
  1433. line = line.replace("[/u]", "__");
  1434. line = line.replace("[method ", "`");
  1435. line = line.replace("[member ", "`");
  1436. line = line.replace("[signal ", "`");
  1437. line = line.replace("[enum ", "`");
  1438. line = line.replace("[constant ", "`");
  1439. line = line.replace("[", "`");
  1440. line = line.replace("]", "`");
  1441. }
  1442. if (!in_code_block && i < lines.size() - 1) {
  1443. line += "\n\n";
  1444. } else if (i < lines.size() - 1) {
  1445. line += "\n";
  1446. }
  1447. markdown += line;
  1448. }
  1449. return markdown;
  1450. }
  1451. } // namespace lsp
  1452. #endif