lsp.hpp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. /*************************************************************************/
  2. /* lsp.hpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. }
  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. bool save = false;
  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["save"] = save;
  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. /**
  1233. * Represents a parameter of a callable-signature. A parameter can
  1234. * have a label and a doc-comment.
  1235. */
  1236. struct ParameterInformation {
  1237. /**
  1238. * The label of this parameter information.
  1239. *
  1240. * Either a string or an inclusive start and exclusive end offsets within its containing
  1241. * signature label. (see SignatureInformation.label). The offsets are based on a UTF-16
  1242. * string representation as `Position` and `Range` does.
  1243. *
  1244. * *Note*: a label of type string should be a substring of its containing signature label.
  1245. * Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`.
  1246. */
  1247. String label;
  1248. /**
  1249. * The human-readable doc-comment of this parameter. Will be shown
  1250. * in the UI but can be omitted.
  1251. */
  1252. MarkupContent documentation;
  1253. Dictionary to_json() const {
  1254. Dictionary dict;
  1255. dict["label"] = label;
  1256. dict["documentation"] = documentation.to_json();
  1257. return dict;
  1258. }
  1259. };
  1260. /**
  1261. * Represents the signature of something callable. A signature
  1262. * can have a label, like a function-name, a doc-comment, and
  1263. * a set of parameters.
  1264. */
  1265. struct SignatureInformation {
  1266. /**
  1267. * The label of this signature. Will be shown in
  1268. * the UI.
  1269. */
  1270. String label;
  1271. /**
  1272. * The human-readable doc-comment of this signature. Will be shown
  1273. * in the UI but can be omitted.
  1274. */
  1275. MarkupContent documentation;
  1276. /**
  1277. * The parameters of this signature.
  1278. */
  1279. Vector<ParameterInformation> parameters;
  1280. Dictionary to_json() const {
  1281. Dictionary dict;
  1282. dict["label"] = label;
  1283. dict["documentation"] = documentation.to_json();
  1284. Array args;
  1285. for (int i = 0; i < parameters.size(); i++) {
  1286. args.push_back(parameters[i].to_json());
  1287. }
  1288. dict["parameters"] = args;
  1289. return dict;
  1290. }
  1291. };
  1292. /**
  1293. * Signature help represents the signature of something
  1294. * callable. There can be multiple signature but only one
  1295. * active and only one active parameter.
  1296. */
  1297. struct SignatureHelp {
  1298. /**
  1299. * One or more signatures.
  1300. */
  1301. Vector<SignatureInformation> signatures;
  1302. /**
  1303. * The active signature. If omitted or the value lies outside the
  1304. * range of `signatures` the value defaults to zero or is ignored if
  1305. * `signatures.length === 0`. Whenever possible implementors should
  1306. * make an active decision about the active signature and shouldn't
  1307. * rely on a default value.
  1308. * In future version of the protocol this property might become
  1309. * mandatory to better express this.
  1310. */
  1311. int activeSignature = 0;
  1312. /**
  1313. * The active parameter of the active signature. If omitted or the value
  1314. * lies outside the range of `signatures[activeSignature].parameters`
  1315. * defaults to 0 if the active signature has parameters. If
  1316. * the active signature has no parameters it is ignored.
  1317. * In future version of the protocol this property might become
  1318. * mandatory to better express the active parameter if the
  1319. * active signature does have any.
  1320. */
  1321. int activeParameter = 0;
  1322. Dictionary to_json() const {
  1323. Dictionary dict;
  1324. Array sigs;
  1325. for (int i = 0; i < signatures.size(); i++) {
  1326. sigs.push_back(signatures[i].to_json());
  1327. }
  1328. dict["signatures"] = sigs;
  1329. dict["activeSignature"] = activeSignature;
  1330. dict["activeParameter"] = activeParameter;
  1331. return dict;
  1332. }
  1333. };
  1334. /**
  1335. * A pattern to describe in which file operation requests or notifications
  1336. * the server is interested in.
  1337. */
  1338. struct FileOperationPattern {
  1339. /**
  1340. * The glob pattern to match.
  1341. */
  1342. String glob = "**/*.gd";
  1343. /**
  1344. * Whether to match `file`s or `folder`s with this pattern.
  1345. *
  1346. * Matches both if undefined.
  1347. */
  1348. String matches = "file";
  1349. Dictionary to_json() const {
  1350. Dictionary dict;
  1351. dict["glob"] = glob;
  1352. dict["matches"] = matches;
  1353. return dict;
  1354. }
  1355. };
  1356. /**
  1357. * A filter to describe in which file operation requests or notifications
  1358. * the server is interested in.
  1359. */
  1360. struct FileOperationFilter {
  1361. /**
  1362. * The actual file operation pattern.
  1363. */
  1364. FileOperationPattern pattern;
  1365. Dictionary to_json() const {
  1366. Dictionary dict;
  1367. dict["pattern"] = pattern.to_json();
  1368. return dict;
  1369. }
  1370. };
  1371. /**
  1372. * The options to register for file operations.
  1373. */
  1374. struct FileOperationRegistrationOptions {
  1375. /**
  1376. * The actual filters.
  1377. */
  1378. Vector<FileOperationFilter> filters;
  1379. FileOperationRegistrationOptions() {
  1380. filters.push_back(FileOperationFilter());
  1381. }
  1382. Dictionary to_json() const {
  1383. Dictionary dict;
  1384. Array filts;
  1385. for (int i = 0; i < filters.size(); i++) {
  1386. filts.push_back(filters[i].to_json());
  1387. }
  1388. dict["filters"] = filts;
  1389. return dict;
  1390. }
  1391. };
  1392. /**
  1393. * The server is interested in file notifications/requests.
  1394. */
  1395. struct FileOperations {
  1396. /**
  1397. * The server is interested in receiving didDeleteFiles file notifications.
  1398. */
  1399. FileOperationRegistrationOptions didDelete;
  1400. Dictionary to_json() const {
  1401. Dictionary dict;
  1402. dict["didDelete"] = didDelete.to_json();
  1403. return dict;
  1404. }
  1405. };
  1406. /**
  1407. * Workspace specific server capabilities
  1408. */
  1409. struct Workspace {
  1410. /**
  1411. * The server is interested in file notifications/requests.
  1412. */
  1413. FileOperations fileOperations;
  1414. Dictionary to_json() const {
  1415. Dictionary dict;
  1416. dict["fileOperations"] = fileOperations.to_json();
  1417. return dict;
  1418. }
  1419. };
  1420. struct ServerCapabilities {
  1421. /**
  1422. * Defines how text documents are synced. Is either a detailed structure defining each notification or
  1423. * for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`.
  1424. */
  1425. TextDocumentSyncOptions textDocumentSync;
  1426. /**
  1427. * The server provides hover support.
  1428. */
  1429. bool hoverProvider = true;
  1430. /**
  1431. * The server provides completion support.
  1432. */
  1433. CompletionOptions completionProvider;
  1434. /**
  1435. * The server provides signature help support.
  1436. */
  1437. SignatureHelpOptions signatureHelpProvider;
  1438. /**
  1439. * The server provides goto definition support.
  1440. */
  1441. bool definitionProvider = true;
  1442. /**
  1443. * The server provides Goto Type Definition support.
  1444. *
  1445. * Since 3.6.0
  1446. */
  1447. bool typeDefinitionProvider = false;
  1448. /**
  1449. * The server provides Goto Implementation support.
  1450. *
  1451. * Since 3.6.0
  1452. */
  1453. bool implementationProvider = false;
  1454. /**
  1455. * The server provides find references support.
  1456. */
  1457. bool referencesProvider = false;
  1458. /**
  1459. * The server provides document highlight support.
  1460. */
  1461. bool documentHighlightProvider = false;
  1462. /**
  1463. * The server provides document symbol support.
  1464. */
  1465. bool documentSymbolProvider = true;
  1466. /**
  1467. * The server provides workspace symbol support.
  1468. */
  1469. bool workspaceSymbolProvider = true;
  1470. /**
  1471. * The server supports workspace folder.
  1472. */
  1473. Workspace workspace;
  1474. /**
  1475. * The server provides code actions. The `CodeActionOptions` return type is only
  1476. * valid if the client signals code action literal support via the property
  1477. * `textDocument.codeAction.codeActionLiteralSupport`.
  1478. */
  1479. bool codeActionProvider = false;
  1480. /**
  1481. * The server provides code lens.
  1482. */
  1483. CodeLensOptions codeLensProvider;
  1484. /**
  1485. * The server provides document formatting.
  1486. */
  1487. bool documentFormattingProvider = false;
  1488. /**
  1489. * The server provides document range formatting.
  1490. */
  1491. bool documentRangeFormattingProvider = false;
  1492. /**
  1493. * The server provides document formatting on typing.
  1494. */
  1495. DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider;
  1496. /**
  1497. * The server provides rename support. RenameOptions may only be
  1498. * specified if the client states that it supports
  1499. * `prepareSupport` in its initial `initialize` request.
  1500. */
  1501. RenameOptions renameProvider;
  1502. /**
  1503. * The server provides document link support.
  1504. */
  1505. DocumentLinkOptions documentLinkProvider;
  1506. /**
  1507. * The server provides color provider support.
  1508. *
  1509. * Since 3.6.0
  1510. */
  1511. ColorProviderOptions colorProvider;
  1512. /**
  1513. * The server provides folding provider support.
  1514. *
  1515. * Since 3.10.0
  1516. */
  1517. FoldingRangeProviderOptions foldingRangeProvider;
  1518. /**
  1519. * The server provides go to declaration support.
  1520. *
  1521. * Since 3.14.0
  1522. */
  1523. bool declarationProvider = true;
  1524. /**
  1525. * The server provides execute command support.
  1526. */
  1527. ExecuteCommandOptions executeCommandProvider;
  1528. _FORCE_INLINE_ Dictionary to_json() {
  1529. Dictionary dict;
  1530. dict["textDocumentSync"] = textDocumentSync.to_json();
  1531. dict["completionProvider"] = completionProvider.to_json();
  1532. signatureHelpProvider.triggerCharacters.push_back(",");
  1533. signatureHelpProvider.triggerCharacters.push_back("(");
  1534. dict["signatureHelpProvider"] = signatureHelpProvider.to_json();
  1535. //dict["codeLensProvider"] = codeLensProvider.to_json();
  1536. dict["documentOnTypeFormattingProvider"] = documentOnTypeFormattingProvider.to_json();
  1537. dict["renameProvider"] = renameProvider.to_json();
  1538. dict["documentLinkProvider"] = documentLinkProvider.to_json();
  1539. dict["colorProvider"] = false; // colorProvider.to_json();
  1540. dict["foldingRangeProvider"] = false; //foldingRangeProvider.to_json();
  1541. dict["executeCommandProvider"] = executeCommandProvider.to_json();
  1542. dict["hoverProvider"] = hoverProvider;
  1543. dict["definitionProvider"] = definitionProvider;
  1544. dict["typeDefinitionProvider"] = typeDefinitionProvider;
  1545. dict["implementationProvider"] = implementationProvider;
  1546. dict["referencesProvider"] = referencesProvider;
  1547. dict["documentHighlightProvider"] = documentHighlightProvider;
  1548. dict["documentSymbolProvider"] = documentSymbolProvider;
  1549. dict["workspaceSymbolProvider"] = workspaceSymbolProvider;
  1550. dict["workspace"] = workspace.to_json();
  1551. dict["codeActionProvider"] = codeActionProvider;
  1552. dict["documentFormattingProvider"] = documentFormattingProvider;
  1553. dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider;
  1554. dict["declarationProvider"] = declarationProvider;
  1555. return dict;
  1556. }
  1557. };
  1558. struct InitializeResult {
  1559. /**
  1560. * The capabilities the language server provides.
  1561. */
  1562. ServerCapabilities capabilities;
  1563. _FORCE_INLINE_ Dictionary to_json() {
  1564. Dictionary dict;
  1565. dict["capabilities"] = capabilities.to_json();
  1566. return dict;
  1567. }
  1568. };
  1569. struct GodotNativeClassInfo {
  1570. String name;
  1571. const DocData::ClassDoc *class_doc = NULL;
  1572. const ClassDB::ClassInfo *class_info = NULL;
  1573. Dictionary to_json() {
  1574. Dictionary dict;
  1575. dict["name"] = name;
  1576. dict["inherits"] = class_doc->inherits;
  1577. return dict;
  1578. }
  1579. };
  1580. /** Features not included in the standard lsp specifications */
  1581. struct GodotCapabilities {
  1582. /**
  1583. * Native class list
  1584. */
  1585. List<GodotNativeClassInfo> native_classes;
  1586. Dictionary to_json() {
  1587. Dictionary dict;
  1588. Array classes;
  1589. for (List<GodotNativeClassInfo>::Element *E = native_classes.front(); E; E = E->next()) {
  1590. classes.push_back(E->get().to_json());
  1591. }
  1592. dict["native_classes"] = classes;
  1593. return dict;
  1594. }
  1595. };
  1596. /** Format BBCode documentation from DocData to markdown */
  1597. static String marked_documentation(const String &p_bbcode) {
  1598. String markdown = p_bbcode.strip_edges();
  1599. Vector<String> lines = markdown.split("\n");
  1600. bool in_code_block = false;
  1601. int code_block_indent = -1;
  1602. markdown = "";
  1603. for (int i = 0; i < lines.size(); i++) {
  1604. String line = lines[i];
  1605. int block_start = line.find("[codeblock]");
  1606. if (block_start != -1) {
  1607. code_block_indent = block_start;
  1608. in_code_block = true;
  1609. line = "\n";
  1610. } else if (in_code_block) {
  1611. line = "\t" + line.substr(code_block_indent, line.length());
  1612. }
  1613. if (in_code_block && line.find("[/codeblock]") != -1) {
  1614. line = "\n";
  1615. in_code_block = false;
  1616. }
  1617. if (!in_code_block) {
  1618. line = line.strip_edges();
  1619. line = line.replace("[code]", "`");
  1620. line = line.replace("[/code]", "`");
  1621. line = line.replace("[i]", "*");
  1622. line = line.replace("[/i]", "*");
  1623. line = line.replace("[b]", "**");
  1624. line = line.replace("[/b]", "**");
  1625. line = line.replace("[u]", "__");
  1626. line = line.replace("[/u]", "__");
  1627. line = line.replace("[method ", "`");
  1628. line = line.replace("[member ", "`");
  1629. line = line.replace("[signal ", "`");
  1630. line = line.replace("[enum ", "`");
  1631. line = line.replace("[constant ", "`");
  1632. line = line.replace("[", "`");
  1633. line = line.replace("]", "`");
  1634. }
  1635. if (!in_code_block && i < lines.size() - 1) {
  1636. line += "\n\n";
  1637. } else if (i < lines.size() - 1) {
  1638. line += "\n";
  1639. }
  1640. markdown += line;
  1641. }
  1642. return markdown;
  1643. }
  1644. } // namespace lsp
  1645. #endif