godot_lsp.h 49 KB

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