godot_lsp.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  1. /**************************************************************************/
  2. /* godot_lsp.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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/doc_data.h"
  33. #include "core/object/class_db.h"
  34. #include "core/templates/list.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. HashMap<String, Vector<TextEdit>> changes;
  230. _FORCE_INLINE_ void add_edit(const String &uri, const TextEdit &edit) {
  231. if (changes.has(uri)) {
  232. changes[uri].push_back(edit);
  233. } else {
  234. Vector<TextEdit> edits;
  235. edits.push_back(edit);
  236. changes[uri] = edits;
  237. }
  238. }
  239. _FORCE_INLINE_ Dictionary to_json() const {
  240. Dictionary dict;
  241. Dictionary out_changes;
  242. for (const KeyValue<String, Vector<TextEdit>> &E : changes) {
  243. Array edits;
  244. for (int i = 0; i < E.value.size(); ++i) {
  245. Dictionary text_edit;
  246. text_edit["range"] = E.value[i].range.to_json();
  247. text_edit["newText"] = E.value[i].newText;
  248. edits.push_back(text_edit);
  249. }
  250. out_changes[E.key] = edits;
  251. }
  252. dict["changes"] = out_changes;
  253. return dict;
  254. }
  255. _FORCE_INLINE_ void add_change(const String &uri, const int &line, const int &start_character, const int &end_character, const String &new_text) {
  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 (HashMap<String, Vector<TextEdit>>::Iterator 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 = true;
  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 = 0;
  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 = 0;
  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 = 0;
  625. /**
  626. * The diagnostic's code, which might appear in the user interface.
  627. */
  628. int code = 0;
  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.is_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, RefCounted 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 RefCounted = 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 = 0;
  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 = 0;
  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. dict["insertText"] = insertText;
  877. if (resolved) {
  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. if (!command.command.is_empty()) {
  888. dict["command"] = command.to_json();
  889. }
  890. }
  891. return dict;
  892. }
  893. void load(const Dictionary &p_dict) {
  894. if (p_dict.has("label")) {
  895. label = p_dict["label"];
  896. }
  897. if (p_dict.has("kind")) {
  898. kind = p_dict["kind"];
  899. }
  900. if (p_dict.has("detail")) {
  901. detail = p_dict["detail"];
  902. }
  903. if (p_dict.has("documentation")) {
  904. Variant doc = p_dict["documentation"];
  905. if (doc.get_type() == Variant::STRING) {
  906. documentation.value = doc;
  907. } else if (doc.get_type() == Variant::DICTIONARY) {
  908. Dictionary v = doc;
  909. documentation.value = v["value"];
  910. }
  911. }
  912. if (p_dict.has("deprecated")) {
  913. deprecated = p_dict["deprecated"];
  914. }
  915. if (p_dict.has("preselect")) {
  916. preselect = p_dict["preselect"];
  917. }
  918. if (p_dict.has("sortText")) {
  919. sortText = p_dict["sortText"];
  920. }
  921. if (p_dict.has("filterText")) {
  922. filterText = p_dict["filterText"];
  923. }
  924. if (p_dict.has("insertText")) {
  925. insertText = p_dict["insertText"];
  926. }
  927. if (p_dict.has("data")) {
  928. data = p_dict["data"];
  929. }
  930. }
  931. };
  932. /**
  933. * Represents a collection of [completion items](#CompletionItem) to be presented
  934. * in the editor.
  935. */
  936. struct CompletionList {
  937. /**
  938. * This list it not complete. Further typing should result in recomputing
  939. * this list.
  940. */
  941. bool isIncomplete = false;
  942. /**
  943. * The completion items.
  944. */
  945. Vector<CompletionItem> items;
  946. };
  947. // Use namespace instead of enumeration to follow the LSP specifications
  948. // lsp::EnumName::EnumValue is OK but lsp::EnumValue is not
  949. // And here C++ compilers are unhappy with our enumeration name like String, Array, Object etc
  950. /**
  951. * A symbol kind.
  952. */
  953. namespace SymbolKind {
  954. static const int File = 1;
  955. static const int Module = 2;
  956. static const int Namespace = 3;
  957. static const int Package = 4;
  958. static const int Class = 5;
  959. static const int Method = 6;
  960. static const int Property = 7;
  961. static const int Field = 8;
  962. static const int Constructor = 9;
  963. static const int Enum = 10;
  964. static const int Interface = 11;
  965. static const int Function = 12;
  966. static const int Variable = 13;
  967. static const int Constant = 14;
  968. static const int String = 15;
  969. static const int Number = 16;
  970. static const int Boolean = 17;
  971. static const int Array = 18;
  972. static const int Object = 19;
  973. static const int Key = 20;
  974. static const int Null = 21;
  975. static const int EnumMember = 22;
  976. static const int Struct = 23;
  977. static const int Event = 24;
  978. static const int Operator = 25;
  979. static const int TypeParameter = 26;
  980. }; // namespace SymbolKind
  981. /**
  982. * Represents information about programming constructs like variables, classes,
  983. * interfaces etc.
  984. */
  985. struct SymbolInformation {
  986. /**
  987. * The name of this symbol.
  988. */
  989. String name;
  990. /**
  991. * The kind of this symbol.
  992. */
  993. int kind = SymbolKind::File;
  994. /**
  995. * Indicates if this symbol is deprecated.
  996. */
  997. bool deprecated = false;
  998. /**
  999. * The location of this symbol. The location's range is used by a tool
  1000. * to reveal the location in the editor. If the symbol is selected in the
  1001. * tool the range's start information is used to position the cursor. So
  1002. * the range usually spans more then the actual symbol's name and does
  1003. * normally include things like visibility modifiers.
  1004. *
  1005. * The range doesn't have to denote a node range in the sense of a abstract
  1006. * syntax tree. It can therefore not be used to re-construct a hierarchy of
  1007. * the symbols.
  1008. */
  1009. Location location;
  1010. /**
  1011. * The name of the symbol containing this symbol. This information is for
  1012. * user interface purposes (e.g. to render a qualifier in the user interface
  1013. * if necessary). It can't be used to re-infer a hierarchy for the document
  1014. * symbols.
  1015. */
  1016. String containerName;
  1017. _FORCE_INLINE_ Dictionary to_json() const {
  1018. Dictionary dict;
  1019. dict["name"] = name;
  1020. dict["kind"] = kind;
  1021. dict["deprecated"] = deprecated;
  1022. dict["location"] = location.to_json();
  1023. dict["containerName"] = containerName;
  1024. return dict;
  1025. }
  1026. };
  1027. struct DocumentedSymbolInformation : public SymbolInformation {
  1028. /**
  1029. * A human-readable string with additional information
  1030. */
  1031. String detail;
  1032. /**
  1033. * A human-readable string that represents a doc-comment.
  1034. */
  1035. String documentation;
  1036. };
  1037. /**
  1038. * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
  1039. * hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
  1040. * e.g. the range of an identifier.
  1041. */
  1042. struct DocumentSymbol {
  1043. /**
  1044. * The name of this symbol. Will be displayed in the user interface and therefore must not be
  1045. * an empty string or a string only consisting of white spaces.
  1046. */
  1047. String name;
  1048. /**
  1049. * More detail for this symbol, e.g the signature of a function.
  1050. */
  1051. String detail;
  1052. /**
  1053. * Documentation for this symbol
  1054. */
  1055. String documentation;
  1056. /**
  1057. * Class name for the native symbols
  1058. */
  1059. String native_class;
  1060. /**
  1061. * The kind of this symbol.
  1062. */
  1063. int kind = SymbolKind::File;
  1064. /**
  1065. * Indicates if this symbol is deprecated.
  1066. */
  1067. bool deprecated = false;
  1068. /**
  1069. * The range enclosing this symbol not including leading/trailing whitespace but everything else
  1070. * like comments. This information is typically used to determine if the clients cursor is
  1071. * inside the symbol to reveal in the symbol in the UI.
  1072. */
  1073. Range range;
  1074. /**
  1075. * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
  1076. * Must be contained by the `range`.
  1077. */
  1078. Range selectionRange;
  1079. DocumentUri uri;
  1080. String script_path;
  1081. /**
  1082. * Children of this symbol, e.g. properties of a class.
  1083. */
  1084. Vector<DocumentSymbol> children;
  1085. Dictionary to_json(bool with_doc = false) const {
  1086. Dictionary dict;
  1087. dict["name"] = name;
  1088. dict["detail"] = detail;
  1089. dict["kind"] = kind;
  1090. dict["deprecated"] = deprecated;
  1091. dict["range"] = range.to_json();
  1092. dict["selectionRange"] = selectionRange.to_json();
  1093. if (with_doc) {
  1094. dict["documentation"] = documentation;
  1095. dict["native_class"] = native_class;
  1096. }
  1097. Array arr;
  1098. arr.resize(children.size());
  1099. for (int i = 0; i < children.size(); i++) {
  1100. arr[i] = children[i].to_json(with_doc);
  1101. }
  1102. dict["children"] = arr;
  1103. return dict;
  1104. }
  1105. void symbol_tree_as_list(const String &p_uri, Vector<DocumentedSymbolInformation> &r_list, const String &p_container = "", bool p_join_name = false) const {
  1106. DocumentedSymbolInformation si;
  1107. if (p_join_name && !p_container.is_empty()) {
  1108. si.name = p_container + ">" + name;
  1109. } else {
  1110. si.name = name;
  1111. }
  1112. si.kind = kind;
  1113. si.containerName = p_container;
  1114. si.deprecated = deprecated;
  1115. si.location.uri = p_uri;
  1116. si.location.range = range;
  1117. si.detail = detail;
  1118. si.documentation = documentation;
  1119. r_list.push_back(si);
  1120. for (int i = 0; i < children.size(); i++) {
  1121. children[i].symbol_tree_as_list(p_uri, r_list, si.name, p_join_name);
  1122. }
  1123. }
  1124. _FORCE_INLINE_ MarkupContent render() const {
  1125. MarkupContent markdown;
  1126. if (detail.length()) {
  1127. markdown.value = "\t" + detail + "\n\n";
  1128. }
  1129. if (documentation.length()) {
  1130. markdown.value += marked_documentation(documentation) + "\n\n";
  1131. }
  1132. if (script_path.length()) {
  1133. markdown.value += "Defined in [" + script_path + "](" + uri + ")";
  1134. }
  1135. return markdown;
  1136. }
  1137. _FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const {
  1138. lsp::CompletionItem item;
  1139. item.label = name;
  1140. if (resolved) {
  1141. item.documentation = render();
  1142. }
  1143. switch (kind) {
  1144. case lsp::SymbolKind::Enum:
  1145. item.kind = lsp::CompletionItemKind::Enum;
  1146. break;
  1147. case lsp::SymbolKind::Class:
  1148. item.kind = lsp::CompletionItemKind::Class;
  1149. break;
  1150. case lsp::SymbolKind::Property:
  1151. item.kind = lsp::CompletionItemKind::Property;
  1152. break;
  1153. case lsp::SymbolKind::Method:
  1154. case lsp::SymbolKind::Function:
  1155. item.kind = lsp::CompletionItemKind::Method;
  1156. break;
  1157. case lsp::SymbolKind::Event:
  1158. item.kind = lsp::CompletionItemKind::Event;
  1159. break;
  1160. case lsp::SymbolKind::Constant:
  1161. item.kind = lsp::CompletionItemKind::Constant;
  1162. break;
  1163. case lsp::SymbolKind::Variable:
  1164. item.kind = lsp::CompletionItemKind::Variable;
  1165. break;
  1166. case lsp::SymbolKind::File:
  1167. item.kind = lsp::CompletionItemKind::File;
  1168. break;
  1169. default:
  1170. item.kind = lsp::CompletionItemKind::Text;
  1171. break;
  1172. }
  1173. return item;
  1174. }
  1175. };
  1176. struct ApplyWorkspaceEditParams {
  1177. WorkspaceEdit edit;
  1178. Dictionary to_json() {
  1179. Dictionary dict;
  1180. dict["edit"] = edit.to_json();
  1181. return dict;
  1182. }
  1183. };
  1184. struct NativeSymbolInspectParams {
  1185. String native_class;
  1186. String symbol_name;
  1187. void load(const Dictionary &p_params) {
  1188. native_class = p_params["native_class"];
  1189. symbol_name = p_params["symbol_name"];
  1190. }
  1191. };
  1192. /**
  1193. * Enum of known range kinds
  1194. */
  1195. namespace FoldingRangeKind {
  1196. /**
  1197. * Folding range for a comment
  1198. */
  1199. static const String Comment = "comment";
  1200. /**
  1201. * Folding range for a imports or includes
  1202. */
  1203. static const String Imports = "imports";
  1204. /**
  1205. * Folding range for a region (e.g. `#region`)
  1206. */
  1207. static const String Region = "region";
  1208. } // namespace FoldingRangeKind
  1209. /**
  1210. * Represents a folding range.
  1211. */
  1212. struct FoldingRange {
  1213. /**
  1214. * The zero-based line number from where the folded range starts.
  1215. */
  1216. int startLine = 0;
  1217. /**
  1218. * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
  1219. */
  1220. int startCharacter = 0;
  1221. /**
  1222. * The zero-based line number where the folded range ends.
  1223. */
  1224. int endLine = 0;
  1225. /**
  1226. * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
  1227. */
  1228. int endCharacter = 0;
  1229. /**
  1230. * Describes the kind of the folding range such as `comment' or 'region'. The kind
  1231. * is used to categorize folding ranges and used by commands like 'Fold all comments'. See
  1232. * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
  1233. */
  1234. String kind = FoldingRangeKind::Region;
  1235. _FORCE_INLINE_ Dictionary to_json() const {
  1236. Dictionary dict;
  1237. dict["startLine"] = startLine;
  1238. dict["startCharacter"] = startCharacter;
  1239. dict["endLine"] = endLine;
  1240. dict["endCharacter"] = endCharacter;
  1241. return dict;
  1242. }
  1243. };
  1244. // Use namespace instead of enumeration to follow the LSP specifications
  1245. /**
  1246. * How a completion was triggered
  1247. */
  1248. namespace CompletionTriggerKind {
  1249. /**
  1250. * Completion was triggered by typing an identifier (24x7 code
  1251. * complete), manual invocation (e.g Ctrl+Space) or via API.
  1252. */
  1253. static const int Invoked = 1;
  1254. /**
  1255. * Completion was triggered by a trigger character specified by
  1256. * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
  1257. */
  1258. static const int TriggerCharacter = 2;
  1259. /**
  1260. * Completion was re-triggered as the current completion list is incomplete.
  1261. */
  1262. static const int TriggerForIncompleteCompletions = 3;
  1263. } // namespace CompletionTriggerKind
  1264. /**
  1265. * Contains additional information about the context in which a completion request is triggered.
  1266. */
  1267. struct CompletionContext {
  1268. /**
  1269. * How the completion was triggered.
  1270. */
  1271. int triggerKind = CompletionTriggerKind::TriggerCharacter;
  1272. /**
  1273. * The trigger character (a single character) that has trigger code complete.
  1274. * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
  1275. */
  1276. String triggerCharacter;
  1277. void load(const Dictionary &p_params) {
  1278. triggerKind = int(p_params["triggerKind"]);
  1279. triggerCharacter = p_params["triggerCharacter"];
  1280. }
  1281. };
  1282. struct CompletionParams : public TextDocumentPositionParams {
  1283. /**
  1284. * The completion context. This is only available if the client specifies
  1285. * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
  1286. */
  1287. CompletionContext context;
  1288. void load(const Dictionary &p_params) {
  1289. TextDocumentPositionParams::load(p_params);
  1290. context.load(p_params["context"]);
  1291. }
  1292. };
  1293. /**
  1294. * The result of a hover request.
  1295. */
  1296. struct Hover {
  1297. /**
  1298. * The hover's content
  1299. */
  1300. MarkupContent contents;
  1301. /**
  1302. * An optional range is a range inside a text document
  1303. * that is used to visualize a hover, e.g. by changing the background color.
  1304. */
  1305. Range range;
  1306. _FORCE_INLINE_ Dictionary to_json() const {
  1307. Dictionary dict;
  1308. dict["range"] = range.to_json();
  1309. dict["contents"] = contents.to_json();
  1310. return dict;
  1311. }
  1312. };
  1313. /**
  1314. * Represents a parameter of a callable-signature. A parameter can
  1315. * have a label and a doc-comment.
  1316. */
  1317. struct ParameterInformation {
  1318. /**
  1319. * The label of this parameter information.
  1320. *
  1321. * Either a string or an inclusive start and exclusive end offsets within its containing
  1322. * signature label. (see SignatureInformation.label). The offsets are based on a UTF-16
  1323. * string representation as `Position` and `Range` does.
  1324. *
  1325. * *Note*: a label of type string should be a substring of its containing signature label.
  1326. * Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`.
  1327. */
  1328. String label;
  1329. /**
  1330. * The human-readable doc-comment of this parameter. Will be shown
  1331. * in the UI but can be omitted.
  1332. */
  1333. MarkupContent documentation;
  1334. Dictionary to_json() const {
  1335. Dictionary dict;
  1336. dict["label"] = label;
  1337. dict["documentation"] = documentation.to_json();
  1338. return dict;
  1339. }
  1340. };
  1341. /**
  1342. * Represents the signature of something callable. A signature
  1343. * can have a label, like a function-name, a doc-comment, and
  1344. * a set of parameters.
  1345. */
  1346. struct SignatureInformation {
  1347. /**
  1348. * The label of this signature. Will be shown in
  1349. * the UI.
  1350. */
  1351. String label;
  1352. /**
  1353. * The human-readable doc-comment of this signature. Will be shown
  1354. * in the UI but can be omitted.
  1355. */
  1356. MarkupContent documentation;
  1357. /**
  1358. * The parameters of this signature.
  1359. */
  1360. Vector<ParameterInformation> parameters;
  1361. Dictionary to_json() const {
  1362. Dictionary dict;
  1363. dict["label"] = label;
  1364. dict["documentation"] = documentation.to_json();
  1365. Array args;
  1366. for (int i = 0; i < parameters.size(); i++) {
  1367. args.push_back(parameters[i].to_json());
  1368. }
  1369. dict["parameters"] = args;
  1370. return dict;
  1371. }
  1372. };
  1373. /**
  1374. * Signature help represents the signature of something
  1375. * callable. There can be multiple signature but only one
  1376. * active and only one active parameter.
  1377. */
  1378. struct SignatureHelp {
  1379. /**
  1380. * One or more signatures.
  1381. */
  1382. Vector<SignatureInformation> signatures;
  1383. /**
  1384. * The active signature. If omitted or the value lies outside the
  1385. * range of `signatures` the value defaults to zero or is ignored if
  1386. * `signatures.length === 0`. Whenever possible implementers should
  1387. * make an active decision about the active signature and shouldn't
  1388. * rely on a default value.
  1389. * In future version of the protocol this property might become
  1390. * mandatory to better express this.
  1391. */
  1392. int activeSignature = 0;
  1393. /**
  1394. * The active parameter of the active signature. If omitted or the value
  1395. * lies outside the range of `signatures[activeSignature].parameters`
  1396. * defaults to 0 if the active signature has parameters. If
  1397. * the active signature has no parameters it is ignored.
  1398. * In future version of the protocol this property might become
  1399. * mandatory to better express the active parameter if the
  1400. * active signature does have any.
  1401. */
  1402. int activeParameter = 0;
  1403. Dictionary to_json() const {
  1404. Dictionary dict;
  1405. Array sigs;
  1406. for (int i = 0; i < signatures.size(); i++) {
  1407. sigs.push_back(signatures[i].to_json());
  1408. }
  1409. dict["signatures"] = sigs;
  1410. dict["activeSignature"] = activeSignature;
  1411. dict["activeParameter"] = activeParameter;
  1412. return dict;
  1413. }
  1414. };
  1415. /**
  1416. * A pattern to describe in which file operation requests or notifications
  1417. * the server is interested in.
  1418. */
  1419. struct FileOperationPattern {
  1420. /**
  1421. * The glob pattern to match.
  1422. */
  1423. String glob = "**/*.gd";
  1424. /**
  1425. * Whether to match `file`s or `folder`s with this pattern.
  1426. *
  1427. * Matches both if undefined.
  1428. */
  1429. String matches = "file";
  1430. Dictionary to_json() const {
  1431. Dictionary dict;
  1432. dict["glob"] = glob;
  1433. dict["matches"] = matches;
  1434. return dict;
  1435. }
  1436. };
  1437. /**
  1438. * A filter to describe in which file operation requests or notifications
  1439. * the server is interested in.
  1440. */
  1441. struct FileOperationFilter {
  1442. /**
  1443. * The actual file operation pattern.
  1444. */
  1445. FileOperationPattern pattern;
  1446. Dictionary to_json() const {
  1447. Dictionary dict;
  1448. dict["pattern"] = pattern.to_json();
  1449. return dict;
  1450. }
  1451. };
  1452. /**
  1453. * The options to register for file operations.
  1454. */
  1455. struct FileOperationRegistrationOptions {
  1456. /**
  1457. * The actual filters.
  1458. */
  1459. Vector<FileOperationFilter> filters;
  1460. FileOperationRegistrationOptions() {
  1461. filters.push_back(FileOperationFilter());
  1462. }
  1463. Dictionary to_json() const {
  1464. Dictionary dict;
  1465. Array filts;
  1466. for (int i = 0; i < filters.size(); i++) {
  1467. filts.push_back(filters[i].to_json());
  1468. }
  1469. dict["filters"] = filts;
  1470. return dict;
  1471. }
  1472. };
  1473. /**
  1474. * The server is interested in file notifications/requests.
  1475. */
  1476. struct FileOperations {
  1477. /**
  1478. * The server is interested in receiving didDeleteFiles file notifications.
  1479. */
  1480. FileOperationRegistrationOptions didDelete;
  1481. Dictionary to_json() const {
  1482. Dictionary dict;
  1483. dict["didDelete"] = didDelete.to_json();
  1484. return dict;
  1485. }
  1486. };
  1487. /**
  1488. * Workspace specific server capabilities
  1489. */
  1490. struct Workspace {
  1491. /**
  1492. * The server is interested in file notifications/requests.
  1493. */
  1494. FileOperations fileOperations;
  1495. Dictionary to_json() const {
  1496. Dictionary dict;
  1497. dict["fileOperations"] = fileOperations.to_json();
  1498. return dict;
  1499. }
  1500. };
  1501. struct ServerCapabilities {
  1502. /**
  1503. * Defines how text documents are synced. Is either a detailed structure defining each notification or
  1504. * for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`.
  1505. */
  1506. TextDocumentSyncOptions textDocumentSync;
  1507. /**
  1508. * The server provides hover support.
  1509. */
  1510. bool hoverProvider = true;
  1511. /**
  1512. * The server provides completion support.
  1513. */
  1514. CompletionOptions completionProvider;
  1515. /**
  1516. * The server provides signature help support.
  1517. */
  1518. SignatureHelpOptions signatureHelpProvider;
  1519. /**
  1520. * The server provides goto definition support.
  1521. */
  1522. bool definitionProvider = true;
  1523. /**
  1524. * The server provides Goto Type Definition support.
  1525. *
  1526. * Since 3.6.0
  1527. */
  1528. bool typeDefinitionProvider = false;
  1529. /**
  1530. * The server provides Goto Implementation support.
  1531. *
  1532. * Since 3.6.0
  1533. */
  1534. bool implementationProvider = false;
  1535. /**
  1536. * The server provides find references support.
  1537. */
  1538. bool referencesProvider = false;
  1539. /**
  1540. * The server provides document highlight support.
  1541. */
  1542. bool documentHighlightProvider = false;
  1543. /**
  1544. * The server provides document symbol support.
  1545. */
  1546. bool documentSymbolProvider = true;
  1547. /**
  1548. * The server provides workspace symbol support.
  1549. */
  1550. bool workspaceSymbolProvider = true;
  1551. /**
  1552. * The server supports workspace folder.
  1553. */
  1554. Workspace workspace;
  1555. /**
  1556. * The server provides code actions. The `CodeActionOptions` return type is only
  1557. * valid if the client signals code action literal support via the property
  1558. * `textDocument.codeAction.codeActionLiteralSupport`.
  1559. */
  1560. bool codeActionProvider = false;
  1561. /**
  1562. * The server provides code lens.
  1563. */
  1564. CodeLensOptions codeLensProvider;
  1565. /**
  1566. * The server provides document formatting.
  1567. */
  1568. bool documentFormattingProvider = false;
  1569. /**
  1570. * The server provides document range formatting.
  1571. */
  1572. bool documentRangeFormattingProvider = false;
  1573. /**
  1574. * The server provides document formatting on typing.
  1575. */
  1576. DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider;
  1577. /**
  1578. * The server provides rename support. RenameOptions may only be
  1579. * specified if the client states that it supports
  1580. * `prepareSupport` in its initial `initialize` request.
  1581. */
  1582. RenameOptions renameProvider;
  1583. /**
  1584. * The server provides document link support.
  1585. */
  1586. DocumentLinkOptions documentLinkProvider;
  1587. /**
  1588. * The server provides color provider support.
  1589. *
  1590. * Since 3.6.0
  1591. */
  1592. ColorProviderOptions colorProvider;
  1593. /**
  1594. * The server provides folding provider support.
  1595. *
  1596. * Since 3.10.0
  1597. */
  1598. FoldingRangeProviderOptions foldingRangeProvider;
  1599. /**
  1600. * The server provides go to declaration support.
  1601. *
  1602. * Since 3.14.0
  1603. */
  1604. bool declarationProvider = true;
  1605. /**
  1606. * The server provides execute command support.
  1607. */
  1608. ExecuteCommandOptions executeCommandProvider;
  1609. _FORCE_INLINE_ Dictionary to_json() {
  1610. Dictionary dict;
  1611. dict["textDocumentSync"] = textDocumentSync.to_json();
  1612. dict["completionProvider"] = completionProvider.to_json();
  1613. signatureHelpProvider.triggerCharacters.push_back(",");
  1614. signatureHelpProvider.triggerCharacters.push_back("(");
  1615. dict["signatureHelpProvider"] = signatureHelpProvider.to_json();
  1616. //dict["codeLensProvider"] = codeLensProvider.to_json();
  1617. dict["documentOnTypeFormattingProvider"] = documentOnTypeFormattingProvider.to_json();
  1618. dict["renameProvider"] = renameProvider.to_json();
  1619. dict["documentLinkProvider"] = documentLinkProvider.to_json();
  1620. dict["colorProvider"] = false; // colorProvider.to_json();
  1621. dict["foldingRangeProvider"] = false; //foldingRangeProvider.to_json();
  1622. dict["executeCommandProvider"] = executeCommandProvider.to_json();
  1623. dict["hoverProvider"] = hoverProvider;
  1624. dict["definitionProvider"] = definitionProvider;
  1625. dict["typeDefinitionProvider"] = typeDefinitionProvider;
  1626. dict["implementationProvider"] = implementationProvider;
  1627. dict["referencesProvider"] = referencesProvider;
  1628. dict["documentHighlightProvider"] = documentHighlightProvider;
  1629. dict["documentSymbolProvider"] = documentSymbolProvider;
  1630. dict["workspaceSymbolProvider"] = workspaceSymbolProvider;
  1631. dict["workspace"] = workspace.to_json();
  1632. dict["codeActionProvider"] = codeActionProvider;
  1633. dict["documentFormattingProvider"] = documentFormattingProvider;
  1634. dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider;
  1635. dict["declarationProvider"] = declarationProvider;
  1636. return dict;
  1637. }
  1638. };
  1639. struct InitializeResult {
  1640. /**
  1641. * The capabilities the language server provides.
  1642. */
  1643. ServerCapabilities capabilities;
  1644. _FORCE_INLINE_ Dictionary to_json() {
  1645. Dictionary dict;
  1646. dict["capabilities"] = capabilities.to_json();
  1647. return dict;
  1648. }
  1649. };
  1650. struct GodotNativeClassInfo {
  1651. String name;
  1652. const DocData::ClassDoc *class_doc = nullptr;
  1653. const ClassDB::ClassInfo *class_info = nullptr;
  1654. Dictionary to_json() {
  1655. Dictionary dict;
  1656. dict["name"] = name;
  1657. dict["inherits"] = class_doc->inherits;
  1658. return dict;
  1659. }
  1660. };
  1661. /** Features not included in the standard lsp specifications */
  1662. struct GodotCapabilities {
  1663. /**
  1664. * Native class list
  1665. */
  1666. List<GodotNativeClassInfo> native_classes;
  1667. Dictionary to_json() {
  1668. Dictionary dict;
  1669. Array classes;
  1670. for (List<GodotNativeClassInfo>::Element *E = native_classes.front(); E; E = E->next()) {
  1671. classes.push_back(E->get().to_json());
  1672. }
  1673. dict["native_classes"] = classes;
  1674. return dict;
  1675. }
  1676. };
  1677. /** Format BBCode documentation from DocData to markdown */
  1678. static String marked_documentation(const String &p_bbcode) {
  1679. String markdown = p_bbcode.strip_edges();
  1680. Vector<String> lines = markdown.split("\n");
  1681. bool in_code_block = false;
  1682. int code_block_indent = -1;
  1683. markdown = "";
  1684. for (int i = 0; i < lines.size(); i++) {
  1685. String line = lines[i];
  1686. int block_start = line.find("[codeblock]");
  1687. if (block_start != -1) {
  1688. code_block_indent = block_start;
  1689. in_code_block = true;
  1690. line = "\n";
  1691. } else if (in_code_block) {
  1692. line = "\t" + line.substr(code_block_indent, line.length());
  1693. }
  1694. if (in_code_block && line.contains("[/codeblock]")) {
  1695. line = "\n";
  1696. in_code_block = false;
  1697. }
  1698. if (!in_code_block) {
  1699. line = line.strip_edges();
  1700. line = line.replace("[code]", "`");
  1701. line = line.replace("[/code]", "`");
  1702. line = line.replace("[i]", "*");
  1703. line = line.replace("[/i]", "*");
  1704. line = line.replace("[b]", "**");
  1705. line = line.replace("[/b]", "**");
  1706. line = line.replace("[u]", "__");
  1707. line = line.replace("[/u]", "__");
  1708. line = line.replace("[method ", "`");
  1709. line = line.replace("[member ", "`");
  1710. line = line.replace("[signal ", "`");
  1711. line = line.replace("[enum ", "`");
  1712. line = line.replace("[constant ", "`");
  1713. line = line.replace("[", "`");
  1714. line = line.replace("]", "`");
  1715. }
  1716. if (!in_code_block && i < lines.size() - 1) {
  1717. line += "\n\n";
  1718. } else if (i < lines.size() - 1) {
  1719. line += "\n";
  1720. }
  1721. markdown += line;
  1722. }
  1723. return markdown;
  1724. }
  1725. } // namespace lsp
  1726. #endif // GODOT_LSP_H