lsp.hpp 41 KB

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