lsp.hpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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 = nullptr;
  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. * The edits to be applied.
  224. */
  225. struct WorkspaceEdit {
  226. /**
  227. * Holds changes to existing resources.
  228. */
  229. Map<String, Vector<TextEdit>> changes;
  230. _FORCE_INLINE_ Dictionary to_json() const {
  231. Dictionary dict;
  232. Dictionary out_changes;
  233. for (Map<String, Vector<TextEdit>>::Element *E = changes.front(); E; E = E->next()) {
  234. Array edits;
  235. for (int i = 0; i < E->get().size(); ++i) {
  236. Dictionary text_edit;
  237. text_edit["range"] = E->get()[i].range.to_json();
  238. text_edit["newText"] = E->get()[i].newText;
  239. edits.push_back(text_edit);
  240. }
  241. out_changes[E->key()] = edits;
  242. }
  243. dict["changes"] = out_changes;
  244. return dict;
  245. }
  246. _FORCE_INLINE_ void add_change(const String &uri, const int &line, const int &start_character, const int &end_character, const String &new_text) {
  247. if (Map<String, Vector<TextEdit>>::Element *E = changes.find(uri)) {
  248. Vector<TextEdit> edit_list = E->value();
  249. for (int i = 0; i < edit_list.size(); ++i) {
  250. TextEdit edit = edit_list[i];
  251. if (edit.range.start.character == start_character) {
  252. return;
  253. }
  254. }
  255. }
  256. TextEdit new_edit;
  257. new_edit.newText = new_text;
  258. new_edit.range.start.line = line;
  259. new_edit.range.start.character = start_character;
  260. new_edit.range.end.line = line;
  261. new_edit.range.end.character = end_character;
  262. if (Map<String, Vector<TextEdit>>::Element *E = changes.find(uri)) {
  263. E->value().push_back(new_edit);
  264. } else {
  265. Vector<TextEdit> edit_list;
  266. edit_list.push_back(new_edit);
  267. changes.insert(uri, edit_list);
  268. }
  269. }
  270. };
  271. /**
  272. * Represents a reference to a command.
  273. * Provides a title which will be used to represent a command in the UI.
  274. * Commands are identified by a string identifier.
  275. * The recommended way to handle commands is to implement their execution on the server side if the client and server provides the corresponding capabilities.
  276. * Alternatively the tool extension code could handle the command. The protocol currently doesn’t specify a set of well-known commands.
  277. */
  278. struct Command {
  279. /**
  280. * Title of the command, like `save`.
  281. */
  282. String title;
  283. /**
  284. * The identifier of the actual command handler.
  285. */
  286. String command;
  287. /**
  288. * Arguments that the command handler should be
  289. * invoked with.
  290. */
  291. Array arguments;
  292. Dictionary to_json() const {
  293. Dictionary dict;
  294. dict["title"] = title;
  295. dict["command"] = command;
  296. if (arguments.size()) {
  297. dict["arguments"] = arguments;
  298. }
  299. return dict;
  300. }
  301. };
  302. // Use namespace instead of enumeration to follow the LSP specifications
  303. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  304. namespace TextDocumentSyncKind {
  305. /**
  306. * Documents should not be synced at all.
  307. */
  308. static const int None = 0;
  309. /**
  310. * Documents are synced by always sending the full content
  311. * of the document.
  312. */
  313. static const int Full = 1;
  314. /**
  315. * Documents are synced by sending the full content on open.
  316. * After that only incremental updates to the document are
  317. * send.
  318. */
  319. static const int Incremental = 2;
  320. }; // namespace TextDocumentSyncKind
  321. /**
  322. * Completion options.
  323. */
  324. struct CompletionOptions {
  325. /**
  326. * The server provides support to resolve additional
  327. * information for a completion item.
  328. */
  329. bool resolveProvider = true;
  330. /**
  331. * The characters that trigger completion automatically.
  332. */
  333. Vector<String> triggerCharacters;
  334. CompletionOptions() {
  335. triggerCharacters.push_back(".");
  336. triggerCharacters.push_back("$");
  337. triggerCharacters.push_back("'");
  338. triggerCharacters.push_back("\"");
  339. }
  340. Dictionary to_json() const {
  341. Dictionary dict;
  342. dict["resolveProvider"] = resolveProvider;
  343. dict["triggerCharacters"] = triggerCharacters;
  344. return dict;
  345. }
  346. };
  347. /**
  348. * Signature help options.
  349. */
  350. struct SignatureHelpOptions {
  351. /**
  352. * The characters that trigger signature help
  353. * automatically.
  354. */
  355. Vector<String> triggerCharacters;
  356. Dictionary to_json() {
  357. Dictionary dict;
  358. dict["triggerCharacters"] = triggerCharacters;
  359. return dict;
  360. }
  361. };
  362. /**
  363. * Code Lens options.
  364. */
  365. struct CodeLensOptions {
  366. /**
  367. * Code lens has a resolve provider as well.
  368. */
  369. bool resolveProvider = false;
  370. Dictionary to_json() {
  371. Dictionary dict;
  372. dict["resolveProvider"] = resolveProvider;
  373. return dict;
  374. }
  375. };
  376. /**
  377. * Rename options
  378. */
  379. struct RenameOptions {
  380. /**
  381. * Renames should be checked and tested before being executed.
  382. */
  383. bool prepareProvider = false;
  384. Dictionary to_json() {
  385. Dictionary dict;
  386. dict["prepareProvider"] = prepareProvider;
  387. return dict;
  388. }
  389. };
  390. /**
  391. * Document link options.
  392. */
  393. struct DocumentLinkOptions {
  394. /**
  395. * Document links have a resolve provider as well.
  396. */
  397. bool resolveProvider = false;
  398. Dictionary to_json() {
  399. Dictionary dict;
  400. dict["resolveProvider"] = resolveProvider;
  401. return dict;
  402. }
  403. };
  404. /**
  405. * Execute command options.
  406. */
  407. struct ExecuteCommandOptions {
  408. /**
  409. * The commands to be executed on the server
  410. */
  411. Vector<String> commands;
  412. Dictionary to_json() {
  413. Dictionary dict;
  414. dict["commands"] = commands;
  415. return dict;
  416. }
  417. };
  418. /**
  419. * Save options.
  420. */
  421. struct SaveOptions {
  422. /**
  423. * The client is supposed to include the content on save.
  424. */
  425. bool includeText = true;
  426. Dictionary to_json() {
  427. Dictionary dict;
  428. dict["includeText"] = includeText;
  429. return dict;
  430. }
  431. };
  432. /**
  433. * Color provider options.
  434. */
  435. struct ColorProviderOptions {
  436. Dictionary to_json() {
  437. Dictionary dict;
  438. return dict;
  439. }
  440. };
  441. /**
  442. * Folding range provider options.
  443. */
  444. struct FoldingRangeProviderOptions {
  445. Dictionary to_json() {
  446. Dictionary dict;
  447. return dict;
  448. }
  449. };
  450. struct TextDocumentSyncOptions {
  451. /**
  452. * Open and close notifications are sent to the server. If omitted open close notification should not
  453. * be sent.
  454. */
  455. bool openClose = true;
  456. /**
  457. * Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full
  458. * and TextDocumentSyncKind.Incremental. If omitted it defaults to TextDocumentSyncKind.None.
  459. */
  460. int change = TextDocumentSyncKind::Full;
  461. /**
  462. * If present will save notifications are sent to the server. If omitted the notification should not be
  463. * sent.
  464. */
  465. bool willSave = false;
  466. /**
  467. * If present will save wait until requests are sent to the server. If omitted the request should not be
  468. * sent.
  469. */
  470. bool willSaveWaitUntil = false;
  471. /**
  472. * If present save notifications are sent to the server. If omitted the notification should not be
  473. * sent.
  474. */
  475. SaveOptions save;
  476. Dictionary to_json() {
  477. Dictionary dict;
  478. dict["willSaveWaitUntil"] = willSaveWaitUntil;
  479. dict["willSave"] = willSave;
  480. dict["openClose"] = openClose;
  481. dict["change"] = change;
  482. dict["save"] = save.to_json();
  483. return dict;
  484. }
  485. };
  486. /**
  487. * Static registration options to be returned in the initialize request.
  488. */
  489. struct StaticRegistrationOptions {
  490. /**
  491. * The id used to register the request. The id can be used to deregister
  492. * the request again. See also Registration#id.
  493. */
  494. String id;
  495. };
  496. /**
  497. * Format document on type options.
  498. */
  499. struct DocumentOnTypeFormattingOptions {
  500. /**
  501. * A character on which formatting should be triggered, like `}`.
  502. */
  503. String firstTriggerCharacter;
  504. /**
  505. * More trigger characters.
  506. */
  507. Vector<String> moreTriggerCharacter;
  508. Dictionary to_json() {
  509. Dictionary dict;
  510. dict["firstTriggerCharacter"] = firstTriggerCharacter;
  511. dict["moreTriggerCharacter"] = moreTriggerCharacter;
  512. return dict;
  513. }
  514. };
  515. struct TextDocumentItem {
  516. /**
  517. * The text document's URI.
  518. */
  519. DocumentUri uri;
  520. /**
  521. * The text document's language identifier.
  522. */
  523. String languageId;
  524. /**
  525. * The version number of this document (it will increase after each
  526. * change, including undo/redo).
  527. */
  528. int version;
  529. /**
  530. * The content of the opened text document.
  531. */
  532. String text;
  533. void load(const Dictionary &p_dict) {
  534. uri = p_dict["uri"];
  535. languageId = p_dict["languageId"];
  536. version = p_dict["version"];
  537. text = p_dict["text"];
  538. }
  539. Dictionary to_json() const {
  540. Dictionary dict;
  541. dict["uri"] = uri;
  542. dict["languageId"] = languageId;
  543. dict["version"] = version;
  544. dict["text"] = text;
  545. return dict;
  546. }
  547. };
  548. /**
  549. * An event describing a change to a text document. If range and rangeLength are omitted
  550. * the new text is considered to be the full content of the document.
  551. */
  552. struct TextDocumentContentChangeEvent {
  553. /**
  554. * The range of the document that changed.
  555. */
  556. Range range;
  557. /**
  558. * The length of the range that got replaced.
  559. */
  560. int rangeLength;
  561. /**
  562. * The new text of the range/document.
  563. */
  564. String text;
  565. void load(const Dictionary &p_params) {
  566. text = p_params["text"];
  567. rangeLength = p_params["rangeLength"];
  568. range.load(p_params["range"]);
  569. }
  570. };
  571. // Use namespace instead of enumeration to follow the LSP specifications
  572. namespace DiagnosticSeverity {
  573. /**
  574. * Reports an error.
  575. */
  576. static const int Error = 1;
  577. /**
  578. * Reports a warning.
  579. */
  580. static const int Warning = 2;
  581. /**
  582. * Reports an information.
  583. */
  584. static const int Information = 3;
  585. /**
  586. * Reports a hint.
  587. */
  588. static const int Hint = 4;
  589. }; // namespace DiagnosticSeverity
  590. /**
  591. * Represents a related message and source code location for a diagnostic. This should be
  592. * used to point to code locations that cause or related to a diagnostics, e.g when duplicating
  593. * a symbol in a scope.
  594. */
  595. struct DiagnosticRelatedInformation {
  596. /**
  597. * The location of this related diagnostic information.
  598. */
  599. Location location;
  600. /**
  601. * The message of this related diagnostic information.
  602. */
  603. String message;
  604. Dictionary to_json() const {
  605. Dictionary dict;
  606. dict["location"] = location.to_json(),
  607. dict["message"] = message;
  608. return dict;
  609. }
  610. };
  611. /**
  612. * Represents a diagnostic, such as a compiler error or warning.
  613. * Diagnostic objects are only valid in the scope of a resource.
  614. */
  615. struct Diagnostic {
  616. /**
  617. * The range at which the message applies.
  618. */
  619. Range range;
  620. /**
  621. * The diagnostic's severity. Can be omitted. If omitted it is up to the
  622. * client to interpret diagnostics as error, warning, info or hint.
  623. */
  624. int severity;
  625. /**
  626. * The diagnostic's code, which might appear in the user interface.
  627. */
  628. int code;
  629. /**
  630. * A human-readable string describing the source of this
  631. * diagnostic, e.g. 'typescript' or 'super lint'.
  632. */
  633. String source;
  634. /**
  635. * The diagnostic's message.
  636. */
  637. String message;
  638. /**
  639. * An array of related diagnostic information, e.g. when symbol-names within
  640. * a scope collide all definitions can be marked via this property.
  641. */
  642. Vector<DiagnosticRelatedInformation> relatedInformation;
  643. Dictionary to_json() const {
  644. Dictionary dict;
  645. dict["range"] = range.to_json();
  646. dict["code"] = code;
  647. dict["severity"] = severity;
  648. dict["message"] = message;
  649. dict["source"] = source;
  650. if (!relatedInformation.empty()) {
  651. Array arr;
  652. arr.resize(relatedInformation.size());
  653. for (int i = 0; i < relatedInformation.size(); i++) {
  654. arr[i] = relatedInformation[i].to_json();
  655. }
  656. dict["relatedInformation"] = arr;
  657. }
  658. return dict;
  659. }
  660. };
  661. // Use namespace instead of enumeration to follow the LSP specifications
  662. /**
  663. * Describes the content type that a client supports in various
  664. * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
  665. *
  666. * Please note that `MarkupKinds` must not start with a `$`. This kinds
  667. * are reserved for internal usage.
  668. */
  669. namespace MarkupKind {
  670. static const String PlainText = "plaintext";
  671. static const String Markdown = "markdown";
  672. }; // namespace MarkupKind
  673. /**
  674. * A `MarkupContent` literal represents a string value which content is interpreted base on its
  675. * kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
  676. *
  677. * If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
  678. * See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
  679. *
  680. * Here is an example how such a string can be constructed using JavaScript / TypeScript:
  681. * ```typescript
  682. * let markdown: MarkdownContent = {
  683. * kind: MarkupKind.Markdown,
  684. * value: [
  685. * '# Header',
  686. * 'Some text',
  687. * '```typescript',
  688. * 'someCode();',
  689. * '```'
  690. * ].join('\n')
  691. * };
  692. * ```
  693. *
  694. * *Please Note* that clients might sanitize the return markdown. A client could decide to
  695. * remove HTML from the markdown to avoid script execution.
  696. */
  697. struct MarkupContent {
  698. /**
  699. * The type of the Markup
  700. */
  701. String kind;
  702. /**
  703. * The content itself
  704. */
  705. String value;
  706. MarkupContent() {
  707. kind = MarkupKind::Markdown;
  708. }
  709. MarkupContent(const String &p_value) {
  710. value = p_value;
  711. kind = MarkupKind::Markdown;
  712. }
  713. Dictionary to_json() const {
  714. Dictionary dict;
  715. dict["kind"] = kind;
  716. dict["value"] = value;
  717. return dict;
  718. }
  719. };
  720. // Use namespace instead of enumeration to follow the LSP specifications
  721. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  722. // And here C++ compilers are unhappy with our enumeration name like Color, File, Reference etc.
  723. /**
  724. * The kind of a completion entry.
  725. */
  726. namespace CompletionItemKind {
  727. static const int Text = 1;
  728. static const int Method = 2;
  729. static const int Function = 3;
  730. static const int Constructor = 4;
  731. static const int Field = 5;
  732. static const int Variable = 6;
  733. static const int Class = 7;
  734. static const int Interface = 8;
  735. static const int Module = 9;
  736. static const int Property = 10;
  737. static const int Unit = 11;
  738. static const int Value = 12;
  739. static const int Enum = 13;
  740. static const int Keyword = 14;
  741. static const int Snippet = 15;
  742. static const int Color = 16;
  743. static const int File = 17;
  744. static const int Reference = 18;
  745. static const int Folder = 19;
  746. static const int EnumMember = 20;
  747. static const int Constant = 21;
  748. static const int Struct = 22;
  749. static const int Event = 23;
  750. static const int Operator = 24;
  751. static const int TypeParameter = 25;
  752. }; // namespace CompletionItemKind
  753. // Use namespace instead of enumeration to follow the LSP specifications
  754. /**
  755. * Defines whether the insert text in a completion item should be interpreted as
  756. * plain text or a snippet.
  757. */
  758. namespace InsertTextFormat {
  759. /**
  760. * The primary text to be inserted is treated as a plain string.
  761. */
  762. static const int PlainText = 1;
  763. /**
  764. * The primary text to be inserted is treated as a snippet.
  765. *
  766. * A snippet can define tab stops and placeholders with `$1`, `$2`
  767. * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
  768. * the end of the snippet. Placeholders with equal identifiers are linked,
  769. * that is typing in one will update others too.
  770. */
  771. static const int Snippet = 2;
  772. }; // namespace InsertTextFormat
  773. struct CompletionItem {
  774. /**
  775. * The label of this completion item. By default
  776. * also the text that is inserted when selecting
  777. * this completion.
  778. */
  779. String label;
  780. /**
  781. * The kind of this completion item. Based of the kind
  782. * an icon is chosen by the editor. The standardized set
  783. * of available values is defined in `CompletionItemKind`.
  784. */
  785. int kind;
  786. /**
  787. * A human-readable string with additional information
  788. * about this item, like type or symbol information.
  789. */
  790. String detail;
  791. /**
  792. * A human-readable string that represents a doc-comment.
  793. */
  794. MarkupContent documentation;
  795. /**
  796. * Indicates if this item is deprecated.
  797. */
  798. bool deprecated = false;
  799. /**
  800. * Select this item when showing.
  801. *
  802. * *Note* that only one completion item can be selected and that the
  803. * tool / client decides which item that is. The rule is that the *first*
  804. * item of those that match best is selected.
  805. */
  806. bool preselect = false;
  807. /**
  808. * A string that should be used when comparing this item
  809. * with other items. When `falsy` the label is used.
  810. */
  811. String sortText;
  812. /**
  813. * A string that should be used when filtering a set of
  814. * completion items. When `falsy` the label is used.
  815. */
  816. String filterText;
  817. /**
  818. * A string that should be inserted into a document when selecting
  819. * this completion. When `falsy` the label is used.
  820. *
  821. * The `insertText` is subject to interpretation by the client side.
  822. * Some tools might not take the string literally. For example
  823. * VS Code when code complete is requested in this example `con<cursor position>`
  824. * and a completion item with an `insertText` of `console` is provided it
  825. * will only insert `sole`. Therefore it is recommended to use `textEdit` instead
  826. * since it avoids additional client side interpretation.
  827. *
  828. * @deprecated Use textEdit instead.
  829. */
  830. String insertText;
  831. /**
  832. * The format of the insert text. The format applies to both the `insertText` property
  833. * and the `newText` property of a provided `textEdit`.
  834. */
  835. int insertTextFormat;
  836. /**
  837. * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
  838. * `insertText` is ignored.
  839. *
  840. * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
  841. * has been requested.
  842. */
  843. TextEdit textEdit;
  844. /**
  845. * An optional array of additional text edits that are applied when
  846. * selecting this completion. Edits must not overlap (including the same insert position)
  847. * with the main edit nor with themselves.
  848. *
  849. * Additional text edits should be used to change text unrelated to the current cursor position
  850. * (for example adding an import statement at the top of the file if the completion item will
  851. * insert an unqualified type).
  852. */
  853. Vector<TextEdit> additionalTextEdits;
  854. /**
  855. * An optional set of characters that when pressed while this completion is active will accept it first and
  856. * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
  857. * characters will be ignored.
  858. */
  859. Vector<String> commitCharacters;
  860. /**
  861. * An optional command that is executed *after* inserting this completion. *Note* that
  862. * additional modifications to the current document should be described with the
  863. * additionalTextEdits-property.
  864. */
  865. Command command;
  866. /**
  867. * A data entry field that is preserved on a completion item between
  868. * a completion and a completion resolve request.
  869. */
  870. Variant data;
  871. _FORCE_INLINE_ Dictionary to_json(bool resolved = false) const {
  872. Dictionary dict;
  873. dict["label"] = label;
  874. dict["kind"] = kind;
  875. dict["data"] = data;
  876. if (resolved) {
  877. dict["insertText"] = insertText;
  878. dict["detail"] = detail;
  879. dict["documentation"] = documentation.to_json();
  880. dict["deprecated"] = deprecated;
  881. dict["preselect"] = preselect;
  882. dict["sortText"] = sortText;
  883. dict["filterText"] = filterText;
  884. if (commitCharacters.size()) {
  885. dict["commitCharacters"] = commitCharacters;
  886. }
  887. dict["command"] = command.to_json();
  888. }
  889. return dict;
  890. }
  891. void load(const Dictionary &p_dict) {
  892. if (p_dict.has("label")) {
  893. label = p_dict["label"];
  894. }
  895. if (p_dict.has("kind")) {
  896. kind = p_dict["kind"];
  897. }
  898. if (p_dict.has("detail")) {
  899. detail = p_dict["detail"];
  900. }
  901. if (p_dict.has("documentation")) {
  902. Variant doc = p_dict["documentation"];
  903. if (doc.get_type() == Variant::STRING) {
  904. documentation.value = doc;
  905. } else if (doc.get_type() == Variant::DICTIONARY) {
  906. Dictionary v = doc;
  907. documentation.value = v["value"];
  908. }
  909. }
  910. if (p_dict.has("deprecated")) {
  911. deprecated = p_dict["deprecated"];
  912. }
  913. if (p_dict.has("preselect")) {
  914. preselect = p_dict["preselect"];
  915. }
  916. if (p_dict.has("sortText")) {
  917. sortText = p_dict["sortText"];
  918. }
  919. if (p_dict.has("filterText")) {
  920. filterText = p_dict["filterText"];
  921. }
  922. if (p_dict.has("insertText")) {
  923. insertText = p_dict["insertText"];
  924. }
  925. if (p_dict.has("data")) {
  926. data = p_dict["data"];
  927. }
  928. }
  929. };
  930. /**
  931. * Represents a collection of [completion items](#CompletionItem) to be presented
  932. * in the editor.
  933. */
  934. struct CompletionList {
  935. /**
  936. * This list it not complete. Further typing should result in recomputing
  937. * this list.
  938. */
  939. bool isIncomplete;
  940. /**
  941. * The completion items.
  942. */
  943. Vector<CompletionItem> items;
  944. };
  945. // Use namespace instead of enumeration to follow the LSP specifications
  946. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  947. // And here C++ compilers are unhappy with our enumeration name like String, Array, Object etc
  948. /**
  949. * A symbol kind.
  950. */
  951. namespace SymbolKind {
  952. static const int File = 1;
  953. static const int Module = 2;
  954. static const int Namespace = 3;
  955. static const int Package = 4;
  956. static const int Class = 5;
  957. static const int Method = 6;
  958. static const int Property = 7;
  959. static const int Field = 8;
  960. static const int Constructor = 9;
  961. static const int Enum = 10;
  962. static const int Interface = 11;
  963. static const int Function = 12;
  964. static const int Variable = 13;
  965. static const int Constant = 14;
  966. static const int String = 15;
  967. static const int Number = 16;
  968. static const int Boolean = 17;
  969. static const int Array = 18;
  970. static const int Object = 19;
  971. static const int Key = 20;
  972. static const int Null = 21;
  973. static const int EnumMember = 22;
  974. static const int Struct = 23;
  975. static const int Event = 24;
  976. static const int Operator = 25;
  977. static const int TypeParameter = 26;
  978. }; // namespace SymbolKind
  979. /**
  980. * Represents information about programming constructs like variables, classes,
  981. * interfaces etc.
  982. */
  983. struct SymbolInformation {
  984. /**
  985. * The name of this symbol.
  986. */
  987. String name;
  988. /**
  989. * The kind of this symbol.
  990. */
  991. int kind = SymbolKind::File;
  992. /**
  993. * Indicates if this symbol is deprecated.
  994. */
  995. bool deprecated = false;
  996. /**
  997. * The location of this symbol. The location's range is used by a tool
  998. * to reveal the location in the editor. If the symbol is selected in the
  999. * tool the range's start information is used to position the cursor. So
  1000. * the range usually spans more then the actual symbol's name and does
  1001. * normally include things like visibility modifiers.
  1002. *
  1003. * The range doesn't have to denote a node range in the sense of a abstract
  1004. * syntax tree. It can therefore not be used to re-construct a hierarchy of
  1005. * the symbols.
  1006. */
  1007. Location location;
  1008. /**
  1009. * The name of the symbol containing this symbol. This information is for
  1010. * user interface purposes (e.g. to render a qualifier in the user interface
  1011. * if necessary). It can't be used to re-infer a hierarchy for the document
  1012. * symbols.
  1013. */
  1014. String containerName;
  1015. _FORCE_INLINE_ Dictionary to_json() const {
  1016. Dictionary dict;
  1017. dict["name"] = name;
  1018. dict["kind"] = kind;
  1019. dict["deprecated"] = deprecated;
  1020. dict["location"] = location.to_json();
  1021. dict["containerName"] = containerName;
  1022. return dict;
  1023. }
  1024. };
  1025. struct DocumentedSymbolInformation : public SymbolInformation {
  1026. /**
  1027. * A human-readable string with additional information
  1028. */
  1029. String detail;
  1030. /**
  1031. * A human-readable string that represents a doc-comment.
  1032. */
  1033. String documentation;
  1034. };
  1035. /**
  1036. * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
  1037. * hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
  1038. * e.g. the range of an identifier.
  1039. */
  1040. struct DocumentSymbol {
  1041. /**
  1042. * The name of this symbol. Will be displayed in the user interface and therefore must not be
  1043. * an empty string or a string only consisting of white spaces.
  1044. */
  1045. String name;
  1046. /**
  1047. * More detail for this symbol, e.g the signature of a function.
  1048. */
  1049. String detail;
  1050. /**
  1051. * Documentation for this symbol
  1052. */
  1053. String documentation;
  1054. /**
  1055. * Class name for the native symbols
  1056. */
  1057. String native_class;
  1058. /**
  1059. * The kind of this symbol.
  1060. */
  1061. int kind = SymbolKind::File;
  1062. /**
  1063. * Indicates if this symbol is deprecated.
  1064. */
  1065. bool deprecated = false;
  1066. /**
  1067. * The range enclosing this symbol not including leading/trailing whitespace but everything else
  1068. * like comments. This information is typically used to determine if the clients cursor is
  1069. * inside the symbol to reveal in the symbol in the UI.
  1070. */
  1071. Range range;
  1072. /**
  1073. * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
  1074. * Must be contained by the `range`.
  1075. */
  1076. Range selectionRange;
  1077. DocumentUri uri;
  1078. String script_path;
  1079. /**
  1080. * Children of this symbol, e.g. properties of a class.
  1081. */
  1082. Vector<DocumentSymbol> children;
  1083. Dictionary to_json(bool with_doc = false) const {
  1084. Dictionary dict;
  1085. dict["name"] = name;
  1086. dict["detail"] = detail;
  1087. dict["kind"] = kind;
  1088. dict["deprecated"] = deprecated;
  1089. dict["range"] = range.to_json();
  1090. dict["selectionRange"] = selectionRange.to_json();
  1091. if (with_doc) {
  1092. dict["documentation"] = documentation;
  1093. dict["native_class"] = native_class;
  1094. }
  1095. Array arr;
  1096. arr.resize(children.size());
  1097. for (int i = 0; i < children.size(); i++) {
  1098. arr[i] = children[i].to_json(with_doc);
  1099. }
  1100. dict["children"] = arr;
  1101. return dict;
  1102. }
  1103. void symbol_tree_as_list(const String &p_uri, Vector<DocumentedSymbolInformation> &r_list, const String &p_container = "", bool p_join_name = false) const {
  1104. DocumentedSymbolInformation si;
  1105. if (p_join_name && !p_container.empty()) {
  1106. si.name = p_container + ">" + name;
  1107. } else {
  1108. si.name = name;
  1109. }
  1110. si.kind = kind;
  1111. si.containerName = p_container;
  1112. si.deprecated = deprecated;
  1113. si.location.uri = p_uri;
  1114. si.location.range = range;
  1115. si.detail = detail;
  1116. si.documentation = documentation;
  1117. r_list.push_back(si);
  1118. for (int i = 0; i < children.size(); i++) {
  1119. children[i].symbol_tree_as_list(p_uri, r_list, si.name, p_join_name);
  1120. }
  1121. }
  1122. _FORCE_INLINE_ MarkupContent render() const {
  1123. MarkupContent markdown;
  1124. if (detail.length()) {
  1125. markdown.value = "\t" + detail + "\n\n";
  1126. }
  1127. if (documentation.length()) {
  1128. markdown.value += marked_documentation(documentation) + "\n\n";
  1129. }
  1130. if (script_path.length()) {
  1131. markdown.value += "Defined in [" + script_path + "](" + uri + ")";
  1132. }
  1133. return markdown;
  1134. }
  1135. _FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const {
  1136. lsp::CompletionItem item;
  1137. item.label = name;
  1138. if (resolved) {
  1139. item.documentation = render();
  1140. }
  1141. switch (kind) {
  1142. case lsp::SymbolKind::Enum:
  1143. item.kind = lsp::CompletionItemKind::Enum;
  1144. break;
  1145. case lsp::SymbolKind::Class:
  1146. item.kind = lsp::CompletionItemKind::Class;
  1147. break;
  1148. case lsp::SymbolKind::Property:
  1149. item.kind = lsp::CompletionItemKind::Property;
  1150. break;
  1151. case lsp::SymbolKind::Method:
  1152. case lsp::SymbolKind::Function:
  1153. item.kind = lsp::CompletionItemKind::Method;
  1154. break;
  1155. case lsp::SymbolKind::Event:
  1156. item.kind = lsp::CompletionItemKind::Event;
  1157. break;
  1158. case lsp::SymbolKind::Constant:
  1159. item.kind = lsp::CompletionItemKind::Constant;
  1160. break;
  1161. case lsp::SymbolKind::Variable:
  1162. item.kind = lsp::CompletionItemKind::Variable;
  1163. break;
  1164. case lsp::SymbolKind::File:
  1165. item.kind = lsp::CompletionItemKind::File;
  1166. break;
  1167. default:
  1168. item.kind = lsp::CompletionItemKind::Text;
  1169. break;
  1170. }
  1171. return item;
  1172. }
  1173. };
  1174. struct NativeSymbolInspectParams {
  1175. String native_class;
  1176. String symbol_name;
  1177. void load(const Dictionary &p_params) {
  1178. native_class = p_params["native_class"];
  1179. symbol_name = p_params["symbol_name"];
  1180. }
  1181. };
  1182. /**
  1183. * Enum of known range kinds
  1184. */
  1185. namespace FoldingRangeKind {
  1186. /**
  1187. * Folding range for a comment
  1188. */
  1189. static const String Comment = "comment";
  1190. /**
  1191. * Folding range for a imports or includes
  1192. */
  1193. static const String Imports = "imports";
  1194. /**
  1195. * Folding range for a region (e.g. `#region`)
  1196. */
  1197. static const String Region = "region";
  1198. } // namespace FoldingRangeKind
  1199. /**
  1200. * Represents a folding range.
  1201. */
  1202. struct FoldingRange {
  1203. /**
  1204. * The zero-based line number from where the folded range starts.
  1205. */
  1206. int startLine = 0;
  1207. /**
  1208. * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
  1209. */
  1210. int startCharacter = 0;
  1211. /**
  1212. * The zero-based line number where the folded range ends.
  1213. */
  1214. int endLine = 0;
  1215. /**
  1216. * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
  1217. */
  1218. int endCharacter = 0;
  1219. /**
  1220. * Describes the kind of the folding range such as `comment' or 'region'. The kind
  1221. * is used to categorize folding ranges and used by commands like 'Fold all comments'. See
  1222. * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
  1223. */
  1224. String kind = FoldingRangeKind::Region;
  1225. _FORCE_INLINE_ Dictionary to_json() const {
  1226. Dictionary dict;
  1227. dict["startLine"] = startLine;
  1228. dict["startCharacter"] = startCharacter;
  1229. dict["endLine"] = endLine;
  1230. dict["endCharacter"] = endCharacter;
  1231. return dict;
  1232. }
  1233. };
  1234. // Use namespace instead of enumeration to follow the LSP specifications
  1235. /**
  1236. * How a completion was triggered
  1237. */
  1238. namespace CompletionTriggerKind {
  1239. /**
  1240. * Completion was triggered by typing an identifier (24x7 code
  1241. * complete), manual invocation (e.g Ctrl+Space) or via API.
  1242. */
  1243. static const int Invoked = 1;
  1244. /**
  1245. * Completion was triggered by a trigger character specified by
  1246. * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
  1247. */
  1248. static const int TriggerCharacter = 2;
  1249. /**
  1250. * Completion was re-triggered as the current completion list is incomplete.
  1251. */
  1252. static const int TriggerForIncompleteCompletions = 3;
  1253. } // namespace CompletionTriggerKind
  1254. /**
  1255. * Contains additional information about the context in which a completion request is triggered.
  1256. */
  1257. struct CompletionContext {
  1258. /**
  1259. * How the completion was triggered.
  1260. */
  1261. int triggerKind = CompletionTriggerKind::TriggerCharacter;
  1262. /**
  1263. * The trigger character (a single character) that has trigger code complete.
  1264. * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
  1265. */
  1266. String triggerCharacter;
  1267. void load(const Dictionary &p_params) {
  1268. triggerKind = int(p_params["triggerKind"]);
  1269. triggerCharacter = p_params["triggerCharacter"];
  1270. }
  1271. };
  1272. struct CompletionParams : public TextDocumentPositionParams {
  1273. /**
  1274. * The completion context. This is only available if the client specifies
  1275. * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
  1276. */
  1277. CompletionContext context;
  1278. void load(const Dictionary &p_params) {
  1279. TextDocumentPositionParams::load(p_params);
  1280. context.load(p_params["context"]);
  1281. }
  1282. };
  1283. /**
  1284. * The result of a hover request.
  1285. */
  1286. struct Hover {
  1287. /**
  1288. * The hover's content
  1289. */
  1290. MarkupContent contents;
  1291. /**
  1292. * An optional range is a range inside a text document
  1293. * that is used to visualize a hover, e.g. by changing the background color.
  1294. */
  1295. Range range;
  1296. _FORCE_INLINE_ Dictionary to_json() const {
  1297. Dictionary dict;
  1298. dict["range"] = range.to_json();
  1299. dict["contents"] = contents.to_json();
  1300. return dict;
  1301. }
  1302. };
  1303. /**
  1304. * Represents a parameter of a callable-signature. A parameter can
  1305. * have a label and a doc-comment.
  1306. */
  1307. struct ParameterInformation {
  1308. /**
  1309. * The label of this parameter information.
  1310. *
  1311. * Either a string or an inclusive start and exclusive end offsets within its containing
  1312. * signature label. (see SignatureInformation.label). The offsets are based on a UTF-16
  1313. * string representation as `Position` and `Range` does.
  1314. *
  1315. * *Note*: a label of type string should be a substring of its containing signature label.
  1316. * Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`.
  1317. */
  1318. String label;
  1319. /**
  1320. * The human-readable doc-comment of this parameter. Will be shown
  1321. * in the UI but can be omitted.
  1322. */
  1323. MarkupContent documentation;
  1324. Dictionary to_json() const {
  1325. Dictionary dict;
  1326. dict["label"] = label;
  1327. dict["documentation"] = documentation.to_json();
  1328. return dict;
  1329. }
  1330. };
  1331. /**
  1332. * Represents the signature of something callable. A signature
  1333. * can have a label, like a function-name, a doc-comment, and
  1334. * a set of parameters.
  1335. */
  1336. struct SignatureInformation {
  1337. /**
  1338. * The label of this signature. Will be shown in
  1339. * the UI.
  1340. */
  1341. String label;
  1342. /**
  1343. * The human-readable doc-comment of this signature. Will be shown
  1344. * in the UI but can be omitted.
  1345. */
  1346. MarkupContent documentation;
  1347. /**
  1348. * The parameters of this signature.
  1349. */
  1350. Vector<ParameterInformation> parameters;
  1351. Dictionary to_json() const {
  1352. Dictionary dict;
  1353. dict["label"] = label;
  1354. dict["documentation"] = documentation.to_json();
  1355. Array args;
  1356. for (int i = 0; i < parameters.size(); i++) {
  1357. args.push_back(parameters[i].to_json());
  1358. }
  1359. dict["parameters"] = args;
  1360. return dict;
  1361. }
  1362. };
  1363. /**
  1364. * Signature help represents the signature of something
  1365. * callable. There can be multiple signature but only one
  1366. * active and only one active parameter.
  1367. */
  1368. struct SignatureHelp {
  1369. /**
  1370. * One or more signatures.
  1371. */
  1372. Vector<SignatureInformation> signatures;
  1373. /**
  1374. * The active signature. If omitted or the value lies outside the
  1375. * range of `signatures` the value defaults to zero or is ignored if
  1376. * `signatures.length === 0`. Whenever possible implementors should
  1377. * make an active decision about the active signature and shouldn't
  1378. * rely on a default value.
  1379. * In future version of the protocol this property might become
  1380. * mandatory to better express this.
  1381. */
  1382. int activeSignature = 0;
  1383. /**
  1384. * The active parameter of the active signature. If omitted or the value
  1385. * lies outside the range of `signatures[activeSignature].parameters`
  1386. * defaults to 0 if the active signature has parameters. If
  1387. * the active signature has no parameters it is ignored.
  1388. * In future version of the protocol this property might become
  1389. * mandatory to better express the active parameter if the
  1390. * active signature does have any.
  1391. */
  1392. int activeParameter = 0;
  1393. Dictionary to_json() const {
  1394. Dictionary dict;
  1395. Array sigs;
  1396. for (int i = 0; i < signatures.size(); i++) {
  1397. sigs.push_back(signatures[i].to_json());
  1398. }
  1399. dict["signatures"] = sigs;
  1400. dict["activeSignature"] = activeSignature;
  1401. dict["activeParameter"] = activeParameter;
  1402. return dict;
  1403. }
  1404. };
  1405. /**
  1406. * A pattern to describe in which file operation requests or notifications
  1407. * the server is interested in.
  1408. */
  1409. struct FileOperationPattern {
  1410. /**
  1411. * The glob pattern to match.
  1412. */
  1413. String glob = "**/*.gd";
  1414. /**
  1415. * Whether to match `file`s or `folder`s with this pattern.
  1416. *
  1417. * Matches both if undefined.
  1418. */
  1419. String matches = "file";
  1420. Dictionary to_json() const {
  1421. Dictionary dict;
  1422. dict["glob"] = glob;
  1423. dict["matches"] = matches;
  1424. return dict;
  1425. }
  1426. };
  1427. /**
  1428. * A filter to describe in which file operation requests or notifications
  1429. * the server is interested in.
  1430. */
  1431. struct FileOperationFilter {
  1432. /**
  1433. * The actual file operation pattern.
  1434. */
  1435. FileOperationPattern pattern;
  1436. Dictionary to_json() const {
  1437. Dictionary dict;
  1438. dict["pattern"] = pattern.to_json();
  1439. return dict;
  1440. }
  1441. };
  1442. /**
  1443. * The options to register for file operations.
  1444. */
  1445. struct FileOperationRegistrationOptions {
  1446. /**
  1447. * The actual filters.
  1448. */
  1449. Vector<FileOperationFilter> filters;
  1450. FileOperationRegistrationOptions() {
  1451. filters.push_back(FileOperationFilter());
  1452. }
  1453. Dictionary to_json() const {
  1454. Dictionary dict;
  1455. Array filts;
  1456. for (int i = 0; i < filters.size(); i++) {
  1457. filts.push_back(filters[i].to_json());
  1458. }
  1459. dict["filters"] = filts;
  1460. return dict;
  1461. }
  1462. };
  1463. /**
  1464. * The server is interested in file notifications/requests.
  1465. */
  1466. struct FileOperations {
  1467. /**
  1468. * The server is interested in receiving didDeleteFiles file notifications.
  1469. */
  1470. FileOperationRegistrationOptions didDelete;
  1471. Dictionary to_json() const {
  1472. Dictionary dict;
  1473. dict["didDelete"] = didDelete.to_json();
  1474. return dict;
  1475. }
  1476. };
  1477. /**
  1478. * Workspace specific server capabilities
  1479. */
  1480. struct Workspace {
  1481. /**
  1482. * The server is interested in file notifications/requests.
  1483. */
  1484. FileOperations fileOperations;
  1485. Dictionary to_json() const {
  1486. Dictionary dict;
  1487. dict["fileOperations"] = fileOperations.to_json();
  1488. return dict;
  1489. }
  1490. };
  1491. struct ServerCapabilities {
  1492. /**
  1493. * Defines how text documents are synced. Is either a detailed structure defining each notification or
  1494. * for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`.
  1495. */
  1496. TextDocumentSyncOptions textDocumentSync;
  1497. /**
  1498. * The server provides hover support.
  1499. */
  1500. bool hoverProvider = true;
  1501. /**
  1502. * The server provides completion support.
  1503. */
  1504. CompletionOptions completionProvider;
  1505. /**
  1506. * The server provides signature help support.
  1507. */
  1508. SignatureHelpOptions signatureHelpProvider;
  1509. /**
  1510. * The server provides goto definition support.
  1511. */
  1512. bool definitionProvider = true;
  1513. /**
  1514. * The server provides Goto Type Definition support.
  1515. *
  1516. * Since 3.6.0
  1517. */
  1518. bool typeDefinitionProvider = false;
  1519. /**
  1520. * The server provides Goto Implementation support.
  1521. *
  1522. * Since 3.6.0
  1523. */
  1524. bool implementationProvider = false;
  1525. /**
  1526. * The server provides find references support.
  1527. */
  1528. bool referencesProvider = false;
  1529. /**
  1530. * The server provides document highlight support.
  1531. */
  1532. bool documentHighlightProvider = false;
  1533. /**
  1534. * The server provides document symbol support.
  1535. */
  1536. bool documentSymbolProvider = true;
  1537. /**
  1538. * The server provides workspace symbol support.
  1539. */
  1540. bool workspaceSymbolProvider = true;
  1541. /**
  1542. * The server supports workspace folder.
  1543. */
  1544. Workspace workspace;
  1545. /**
  1546. * The server provides code actions. The `CodeActionOptions` return type is only
  1547. * valid if the client signals code action literal support via the property
  1548. * `textDocument.codeAction.codeActionLiteralSupport`.
  1549. */
  1550. bool codeActionProvider = false;
  1551. /**
  1552. * The server provides code lens.
  1553. */
  1554. CodeLensOptions codeLensProvider;
  1555. /**
  1556. * The server provides document formatting.
  1557. */
  1558. bool documentFormattingProvider = false;
  1559. /**
  1560. * The server provides document range formatting.
  1561. */
  1562. bool documentRangeFormattingProvider = false;
  1563. /**
  1564. * The server provides document formatting on typing.
  1565. */
  1566. DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider;
  1567. /**
  1568. * The server provides rename support. RenameOptions may only be
  1569. * specified if the client states that it supports
  1570. * `prepareSupport` in its initial `initialize` request.
  1571. */
  1572. RenameOptions renameProvider;
  1573. /**
  1574. * The server provides document link support.
  1575. */
  1576. DocumentLinkOptions documentLinkProvider;
  1577. /**
  1578. * The server provides color provider support.
  1579. *
  1580. * Since 3.6.0
  1581. */
  1582. ColorProviderOptions colorProvider;
  1583. /**
  1584. * The server provides folding provider support.
  1585. *
  1586. * Since 3.10.0
  1587. */
  1588. FoldingRangeProviderOptions foldingRangeProvider;
  1589. /**
  1590. * The server provides go to declaration support.
  1591. *
  1592. * Since 3.14.0
  1593. */
  1594. bool declarationProvider = true;
  1595. /**
  1596. * The server provides execute command support.
  1597. */
  1598. ExecuteCommandOptions executeCommandProvider;
  1599. _FORCE_INLINE_ Dictionary to_json() {
  1600. Dictionary dict;
  1601. dict["textDocumentSync"] = textDocumentSync.to_json();
  1602. dict["completionProvider"] = completionProvider.to_json();
  1603. signatureHelpProvider.triggerCharacters.push_back(",");
  1604. signatureHelpProvider.triggerCharacters.push_back("(");
  1605. dict["signatureHelpProvider"] = signatureHelpProvider.to_json();
  1606. //dict["codeLensProvider"] = codeLensProvider.to_json();
  1607. dict["documentOnTypeFormattingProvider"] = documentOnTypeFormattingProvider.to_json();
  1608. dict["renameProvider"] = renameProvider.to_json();
  1609. dict["documentLinkProvider"] = documentLinkProvider.to_json();
  1610. dict["colorProvider"] = false; // colorProvider.to_json();
  1611. dict["foldingRangeProvider"] = false; //foldingRangeProvider.to_json();
  1612. dict["executeCommandProvider"] = executeCommandProvider.to_json();
  1613. dict["hoverProvider"] = hoverProvider;
  1614. dict["definitionProvider"] = definitionProvider;
  1615. dict["typeDefinitionProvider"] = typeDefinitionProvider;
  1616. dict["implementationProvider"] = implementationProvider;
  1617. dict["referencesProvider"] = referencesProvider;
  1618. dict["documentHighlightProvider"] = documentHighlightProvider;
  1619. dict["documentSymbolProvider"] = documentSymbolProvider;
  1620. dict["workspaceSymbolProvider"] = workspaceSymbolProvider;
  1621. dict["workspace"] = workspace.to_json();
  1622. dict["codeActionProvider"] = codeActionProvider;
  1623. dict["documentFormattingProvider"] = documentFormattingProvider;
  1624. dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider;
  1625. dict["declarationProvider"] = declarationProvider;
  1626. return dict;
  1627. }
  1628. };
  1629. struct InitializeResult {
  1630. /**
  1631. * The capabilities the language server provides.
  1632. */
  1633. ServerCapabilities capabilities;
  1634. _FORCE_INLINE_ Dictionary to_json() {
  1635. Dictionary dict;
  1636. dict["capabilities"] = capabilities.to_json();
  1637. return dict;
  1638. }
  1639. };
  1640. struct GodotNativeClassInfo {
  1641. String name;
  1642. const DocData::ClassDoc *class_doc = nullptr;
  1643. const ClassDB::ClassInfo *class_info = nullptr;
  1644. Dictionary to_json() {
  1645. Dictionary dict;
  1646. dict["name"] = name;
  1647. dict["inherits"] = class_doc->inherits;
  1648. return dict;
  1649. }
  1650. };
  1651. /** Features not included in the standard lsp specifications */
  1652. struct GodotCapabilities {
  1653. /**
  1654. * Native class list
  1655. */
  1656. List<GodotNativeClassInfo> native_classes;
  1657. Dictionary to_json() {
  1658. Dictionary dict;
  1659. Array classes;
  1660. for (List<GodotNativeClassInfo>::Element *E = native_classes.front(); E; E = E->next()) {
  1661. classes.push_back(E->get().to_json());
  1662. }
  1663. dict["native_classes"] = classes;
  1664. return dict;
  1665. }
  1666. };
  1667. /** Format BBCode documentation from DocData to markdown */
  1668. static String marked_documentation(const String &p_bbcode) {
  1669. String markdown = p_bbcode.strip_edges();
  1670. Vector<String> lines = markdown.split("\n");
  1671. bool in_code_block = false;
  1672. int code_block_indent = -1;
  1673. markdown = "";
  1674. for (int i = 0; i < lines.size(); i++) {
  1675. String line = lines[i];
  1676. int block_start = line.find("[codeblock]");
  1677. if (block_start != -1) {
  1678. code_block_indent = block_start;
  1679. in_code_block = true;
  1680. line = "\n";
  1681. } else if (in_code_block) {
  1682. line = "\t" + line.substr(code_block_indent, line.length());
  1683. }
  1684. if (in_code_block && line.find("[/codeblock]") != -1) {
  1685. line = "\n";
  1686. in_code_block = false;
  1687. }
  1688. if (!in_code_block) {
  1689. line = line.strip_edges();
  1690. line = line.replace("[code]", "`");
  1691. line = line.replace("[/code]", "`");
  1692. line = line.replace("[i]", "*");
  1693. line = line.replace("[/i]", "*");
  1694. line = line.replace("[b]", "**");
  1695. line = line.replace("[/b]", "**");
  1696. line = line.replace("[u]", "__");
  1697. line = line.replace("[/u]", "__");
  1698. line = line.replace("[method ", "`");
  1699. line = line.replace("[member ", "`");
  1700. line = line.replace("[signal ", "`");
  1701. line = line.replace("[enum ", "`");
  1702. line = line.replace("[constant ", "`");
  1703. line = line.replace("[", "`");
  1704. line = line.replace("]", "`");
  1705. }
  1706. if (!in_code_block && i < lines.size() - 1) {
  1707. line += "\n\n";
  1708. } else if (i < lines.size() - 1) {
  1709. line += "\n";
  1710. }
  1711. markdown += line;
  1712. }
  1713. return markdown;
  1714. }
  1715. } // namespace lsp
  1716. #endif