lsp.hpp 47 KB

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