lsp.hpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. /*************************************************************************/
  2. /* lsp.hpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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/variant.h"
  33. namespace lsp {
  34. typedef String DocumentUri;
  35. /**
  36. * Text documents are identified using a URI. On the protocol level, URIs are passed as strings.
  37. */
  38. struct TextDocumentIdentifier {
  39. /**
  40. * The text document's URI.
  41. */
  42. DocumentUri uri;
  43. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  44. uri = p_params["uri"];
  45. }
  46. _FORCE_INLINE_ Dictionary to_json() const {
  47. Dictionary dict;
  48. dict["uri"] = uri;
  49. return dict;
  50. }
  51. };
  52. /**
  53. * Position in a text document expressed as zero-based line and zero-based character offset.
  54. * A position is between two characters like an ‘insert’ cursor in a editor.
  55. * Special values like for example -1 to denote the end of a line are not supported.
  56. */
  57. struct Position {
  58. /**
  59. * Line position in a document (zero-based).
  60. */
  61. int line = 0;
  62. /**
  63. * Character offset on a line in a document (zero-based). Assuming that the line is
  64. * represented as a string, the `character` value represents the gap between the
  65. * `character` and `character + 1`.
  66. *
  67. * If the character value is greater than the line length it defaults back to the
  68. * line length.
  69. */
  70. int character = 0;
  71. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  72. line = p_params["line"];
  73. character = p_params["character"];
  74. }
  75. _FORCE_INLINE_ Dictionary to_json() const {
  76. Dictionary dict;
  77. dict["line"] = line;
  78. dict["character"] = character;
  79. return dict;
  80. }
  81. };
  82. /**
  83. * A range in a text document expressed as (zero-based) start and end positions.
  84. * A range is comparable to a selection in an editor. Therefore the end position is exclusive.
  85. * 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.
  86. */
  87. struct Range {
  88. /**
  89. * The range's start position.
  90. */
  91. Position start;
  92. /**
  93. * The range's end position.
  94. */
  95. Position end;
  96. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  97. start.load(p_params["start"]);
  98. end.load(p_params["end"]);
  99. }
  100. _FORCE_INLINE_ Dictionary to_json() const {
  101. Dictionary dict;
  102. dict["start"] = start.to_json();
  103. dict["end"] = end.to_json();
  104. return dict;
  105. }
  106. };
  107. /**
  108. * Represents a location inside a resource, such as a line inside a text file.
  109. */
  110. struct Location {
  111. DocumentUri uri;
  112. Range range;
  113. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  114. uri = p_params["uri"];
  115. range.load(p_params["range"]);
  116. }
  117. _FORCE_INLINE_ Dictionary to_json() const {
  118. Dictionary dict;
  119. dict["uri"] = uri;
  120. dict["range"] = range.to_json();
  121. return dict;
  122. }
  123. };
  124. /**
  125. * Represents a link between a source and a target location.
  126. */
  127. struct LocationLink {
  128. /**
  129. * Span of the origin of this link.
  130. *
  131. * Used as the underlined span for mouse interaction. Defaults to the word range at
  132. * the mouse position.
  133. */
  134. Range *originSelectionRange = NULL;
  135. /**
  136. * The target resource identifier of this link.
  137. */
  138. String targetUri;
  139. /**
  140. * The full target range of this link. If the target for example is a symbol then target range is the
  141. * range enclosing this symbol not including leading/trailing whitespace but everything else
  142. * like comments. This information is typically used to highlight the range in the editor.
  143. */
  144. Range targetRange;
  145. /**
  146. * The range that should be selected and revealed when this link is being followed, e.g the name of a function.
  147. * Must be contained by the the `targetRange`. See also `DocumentSymbol#range`
  148. */
  149. Range targetSelectionRange;
  150. };
  151. /**
  152. * A parameter literal used in requests to pass a text document and a position inside that document.
  153. */
  154. struct TextDocumentPositionParams {
  155. /**
  156. * The text document.
  157. */
  158. TextDocumentIdentifier textDocument;
  159. /**
  160. * The position inside the text document.
  161. */
  162. Position position;
  163. _FORCE_INLINE_ void load(const Dictionary &p_params) {
  164. textDocument.load(p_params["textDocument"]);
  165. position.load(p_params["position"]);
  166. }
  167. _FORCE_INLINE_ Dictionary to_json() const {
  168. Dictionary dict;
  169. dict["textDocument"] = textDocument.to_json();
  170. dict["position"] = position.to_json();
  171. return dict;
  172. }
  173. };
  174. /**
  175. * A textual edit applicable to a text document.
  176. */
  177. struct TextEdit {
  178. /**
  179. * The range of the text document to be manipulated. To insert
  180. * text into a document create a range where start === end.
  181. */
  182. Range range;
  183. /**
  184. * The string to be inserted. For delete operations use an
  185. * empty string.
  186. */
  187. String newText;
  188. };
  189. /**
  190. * Represents a reference to a command.
  191. * Provides a title which will be used to represent a command in the UI.
  192. * Commands are identified by a string identifier.
  193. * The recommended way to handle commands is to implement their execution on the server side if the client and server provides the corresponding capabilities.
  194. * Alternatively the tool extension code could handle the command. The protocol currently doesn’t specify a set of well-known commands.
  195. */
  196. struct Command {
  197. /**
  198. * Title of the command, like `save`.
  199. */
  200. String title;
  201. /**
  202. * The identifier of the actual command handler.
  203. */
  204. String command;
  205. /**
  206. * Arguments that the command handler should be
  207. * invoked with.
  208. */
  209. Array arguments;
  210. Dictionary to_json() const {
  211. Dictionary dict;
  212. dict["title"] = title;
  213. dict["command"] = command;
  214. if (arguments.size()) dict["arguments"] = arguments;
  215. return dict;
  216. }
  217. };
  218. namespace TextDocumentSyncKind {
  219. /**
  220. * Documents should not be synced at all.
  221. */
  222. static const int None = 0;
  223. /**
  224. * Documents are synced by always sending the full content
  225. * of the document.
  226. */
  227. static const int Full = 1;
  228. /**
  229. * Documents are synced by sending the full content on open.
  230. * After that only incremental updates to the document are
  231. * send.
  232. */
  233. static const int Incremental = 2;
  234. }; // namespace TextDocumentSyncKind
  235. /**
  236. * Completion options.
  237. */
  238. struct CompletionOptions {
  239. /**
  240. * The server provides support to resolve additional
  241. * information for a completion item.
  242. */
  243. bool resolveProvider = true;
  244. /**
  245. * The characters that trigger completion automatically.
  246. */
  247. Vector<String> triggerCharacters;
  248. CompletionOptions() {
  249. triggerCharacters.push_back(".");
  250. triggerCharacters.push_back("$");
  251. triggerCharacters.push_back("'");
  252. triggerCharacters.push_back("\"");
  253. triggerCharacters.push_back("(");
  254. triggerCharacters.push_back(",");
  255. }
  256. Dictionary to_json() const {
  257. Dictionary dict;
  258. dict["resolveProvider"] = resolveProvider;
  259. dict["triggerCharacters"] = triggerCharacters;
  260. return dict;
  261. }
  262. };
  263. /**
  264. * Signature help options.
  265. */
  266. struct SignatureHelpOptions {
  267. /**
  268. * The characters that trigger signature help
  269. * automatically.
  270. */
  271. Vector<String> triggerCharacters;
  272. Dictionary to_json() {
  273. Dictionary dict;
  274. dict["triggerCharacters"] = triggerCharacters;
  275. return dict;
  276. }
  277. };
  278. /**
  279. * Code Lens options.
  280. */
  281. struct CodeLensOptions {
  282. /**
  283. * Code lens has a resolve provider as well.
  284. */
  285. bool resolveProvider = false;
  286. Dictionary to_json() {
  287. Dictionary dict;
  288. dict["resolveProvider"] = resolveProvider;
  289. return dict;
  290. }
  291. };
  292. /**
  293. * Rename options
  294. */
  295. struct RenameOptions {
  296. /**
  297. * Renames should be checked and tested before being executed.
  298. */
  299. bool prepareProvider = false;
  300. Dictionary to_json() {
  301. Dictionary dict;
  302. dict["prepareProvider"] = prepareProvider;
  303. return dict;
  304. }
  305. };
  306. /**
  307. * Document link options.
  308. */
  309. struct DocumentLinkOptions {
  310. /**
  311. * Document links have a resolve provider as well.
  312. */
  313. bool resolveProvider = false;
  314. Dictionary to_json() {
  315. Dictionary dict;
  316. dict["resolveProvider"] = resolveProvider;
  317. return dict;
  318. }
  319. };
  320. /**
  321. * Execute command options.
  322. */
  323. struct ExecuteCommandOptions {
  324. /**
  325. * The commands to be executed on the server
  326. */
  327. Vector<String> commands;
  328. Dictionary to_json() {
  329. Dictionary dict;
  330. dict["commands"] = commands;
  331. return dict;
  332. }
  333. };
  334. /**
  335. * Save options.
  336. */
  337. struct SaveOptions {
  338. /**
  339. * The client is supposed to include the content on save.
  340. */
  341. bool includeText = true;
  342. Dictionary to_json() {
  343. Dictionary dict;
  344. dict["includeText"] = includeText;
  345. return dict;
  346. }
  347. };
  348. /**
  349. * Color provider options.
  350. */
  351. struct ColorProviderOptions {
  352. Dictionary to_json() {
  353. Dictionary dict;
  354. return dict;
  355. }
  356. };
  357. /**
  358. * Folding range provider options.
  359. */
  360. struct FoldingRangeProviderOptions {
  361. Dictionary to_json() {
  362. Dictionary dict;
  363. return dict;
  364. }
  365. };
  366. struct TextDocumentSyncOptions {
  367. /**
  368. * Open and close notifications are sent to the server. If omitted open close notification should not
  369. * be sent.
  370. */
  371. bool openClose = true;
  372. /**
  373. * Change notifications are sent to the server. See TextDocumentSyncKind.None, TextDocumentSyncKind.Full
  374. * and TextDocumentSyncKind.Incremental. If omitted it defaults to TextDocumentSyncKind.None.
  375. */
  376. int change = TextDocumentSyncKind::Full;
  377. /**
  378. * If present will save notifications are sent to the server. If omitted the notification should not be
  379. * sent.
  380. */
  381. bool willSave = false;
  382. /**
  383. * If present will save wait until requests are sent to the server. If omitted the request should not be
  384. * sent.
  385. */
  386. bool willSaveWaitUntil = false;
  387. /**
  388. * If present save notifications are sent to the server. If omitted the notification should not be
  389. * sent.
  390. */
  391. SaveOptions save;
  392. Dictionary to_json() {
  393. Dictionary dict;
  394. dict["willSaveWaitUntil"] = willSaveWaitUntil;
  395. dict["willSave"] = willSave;
  396. dict["openClose"] = openClose;
  397. dict["change"] = change;
  398. dict["change"] = save.to_json();
  399. return dict;
  400. }
  401. };
  402. /**
  403. * Static registration options to be returned in the initialize request.
  404. */
  405. struct StaticRegistrationOptions {
  406. /**
  407. * The id used to register the request. The id can be used to deregister
  408. * the request again. See also Registration#id.
  409. */
  410. String id;
  411. };
  412. /**
  413. * Format document on type options.
  414. */
  415. struct DocumentOnTypeFormattingOptions {
  416. /**
  417. * A character on which formatting should be triggered, like `}`.
  418. */
  419. String firstTriggerCharacter;
  420. /**
  421. * More trigger characters.
  422. */
  423. Vector<String> moreTriggerCharacter;
  424. Dictionary to_json() {
  425. Dictionary dict;
  426. dict["firstTriggerCharacter"] = firstTriggerCharacter;
  427. dict["moreTriggerCharacter"] = moreTriggerCharacter;
  428. return dict;
  429. }
  430. };
  431. struct TextDocumentItem {
  432. /**
  433. * The text document's URI.
  434. */
  435. DocumentUri uri;
  436. /**
  437. * The text document's language identifier.
  438. */
  439. String languageId;
  440. /**
  441. * The version number of this document (it will increase after each
  442. * change, including undo/redo).
  443. */
  444. int version;
  445. /**
  446. * The content of the opened text document.
  447. */
  448. String text;
  449. void load(const Dictionary &p_dict) {
  450. uri = p_dict["uri"];
  451. languageId = p_dict["languageId"];
  452. version = p_dict["version"];
  453. text = p_dict["text"];
  454. }
  455. Dictionary to_json() const {
  456. Dictionary dict;
  457. dict["uri"] = uri;
  458. dict["languageId"] = languageId;
  459. dict["version"] = version;
  460. dict["text"] = text;
  461. return dict;
  462. }
  463. };
  464. /**
  465. * An event describing a change to a text document. If range and rangeLength are omitted
  466. * the new text is considered to be the full content of the document.
  467. */
  468. struct TextDocumentContentChangeEvent {
  469. /**
  470. * The range of the document that changed.
  471. */
  472. Range range;
  473. /**
  474. * The length of the range that got replaced.
  475. */
  476. int rangeLength;
  477. /**
  478. * The new text of the range/document.
  479. */
  480. String text;
  481. void load(const Dictionary &p_params) {
  482. text = p_params["text"];
  483. rangeLength = p_params["rangeLength"];
  484. range.load(p_params["range"]);
  485. }
  486. };
  487. namespace DiagnosticSeverity {
  488. /**
  489. * Reports an error.
  490. */
  491. static const int Error = 1;
  492. /**
  493. * Reports a warning.
  494. */
  495. static const int Warning = 2;
  496. /**
  497. * Reports an information.
  498. */
  499. static const int Information = 3;
  500. /**
  501. * Reports a hint.
  502. */
  503. static const int Hint = 4;
  504. }; // namespace DiagnosticSeverity
  505. /**
  506. * Represents a related message and source code location for a diagnostic. This should be
  507. * used to point to code locations that cause or related to a diagnostics, e.g when duplicating
  508. * a symbol in a scope.
  509. */
  510. struct DiagnosticRelatedInformation {
  511. /**
  512. * The location of this related diagnostic information.
  513. */
  514. Location location;
  515. /**
  516. * The message of this related diagnostic information.
  517. */
  518. String message;
  519. Dictionary to_json() const {
  520. Dictionary dict;
  521. dict["location"] = location.to_json(),
  522. dict["message"] = message;
  523. return dict;
  524. }
  525. };
  526. /**
  527. * Represents a diagnostic, such as a compiler error or warning.
  528. * Diagnostic objects are only valid in the scope of a resource.
  529. */
  530. struct Diagnostic {
  531. /**
  532. * The range at which the message applies.
  533. */
  534. Range range;
  535. /**
  536. * The diagnostic's severity. Can be omitted. If omitted it is up to the
  537. * client to interpret diagnostics as error, warning, info or hint.
  538. */
  539. int severity;
  540. /**
  541. * The diagnostic's code, which might appear in the user interface.
  542. */
  543. int code;
  544. /**
  545. * A human-readable string describing the source of this
  546. * diagnostic, e.g. 'typescript' or 'super lint'.
  547. */
  548. String source;
  549. /**
  550. * The diagnostic's message.
  551. */
  552. String message;
  553. /**
  554. * An array of related diagnostic information, e.g. when symbol-names within
  555. * a scope collide all definitions can be marked via this property.
  556. */
  557. Vector<DiagnosticRelatedInformation> relatedInformation;
  558. Dictionary to_json() const {
  559. Dictionary dict;
  560. dict["range"] = range.to_json();
  561. dict["code"] = code;
  562. dict["severity"] = severity;
  563. dict["message"] = message;
  564. dict["source"] = source;
  565. if (!relatedInformation.empty()) {
  566. Array arr;
  567. arr.resize(relatedInformation.size());
  568. for (int i = 0; i < relatedInformation.size(); i++) {
  569. arr[i] = relatedInformation[i].to_json();
  570. }
  571. dict["relatedInformation"] = arr;
  572. }
  573. return dict;
  574. }
  575. };
  576. /**
  577. * Describes the content type that a client supports in various
  578. * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
  579. *
  580. * Please note that `MarkupKinds` must not start with a `$`. This kinds
  581. * are reserved for internal usage.
  582. */
  583. namespace MarkupKind {
  584. static const String PlainText = "plaintext";
  585. static const String Markdown = "markdown";
  586. }; // namespace MarkupKind
  587. /**
  588. * A `MarkupContent` literal represents a string value which content is interpreted base on its
  589. * kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
  590. *
  591. * If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
  592. * See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
  593. *
  594. * Here is an example how such a string can be constructed using JavaScript / TypeScript:
  595. * ```typescript
  596. * let markdown: MarkdownContent = {
  597. * kind: MarkupKind.Markdown,
  598. * value: [
  599. * '# Header',
  600. * 'Some text',
  601. * '```typescript',
  602. * 'someCode();',
  603. * '```'
  604. * ].join('\n')
  605. * };
  606. * ```
  607. *
  608. * *Please Note* that clients might sanitize the return markdown. A client could decide to
  609. * remove HTML from the markdown to avoid script execution.
  610. */
  611. struct MarkupContent {
  612. /**
  613. * The type of the Markup
  614. */
  615. String kind;
  616. /**
  617. * The content itself
  618. */
  619. String value;
  620. MarkupContent() {
  621. kind = MarkupKind::Markdown;
  622. }
  623. MarkupContent(const String &p_value) {
  624. value = p_value;
  625. kind = MarkupKind::Markdown;
  626. }
  627. Dictionary to_json() const {
  628. Dictionary dict;
  629. dict["kind"] = kind;
  630. dict["value"] = value;
  631. return dict;
  632. }
  633. };
  634. /**
  635. * The kind of a completion entry.
  636. */
  637. namespace CompletionItemKind {
  638. static const int Text = 1;
  639. static const int Method = 2;
  640. static const int Function = 3;
  641. static const int Constructor = 4;
  642. static const int Field = 5;
  643. static const int Variable = 6;
  644. static const int Class = 7;
  645. static const int Interface = 8;
  646. static const int Module = 9;
  647. static const int Property = 10;
  648. static const int Unit = 11;
  649. static const int Value = 12;
  650. static const int Enum = 13;
  651. static const int Keyword = 14;
  652. static const int Snippet = 15;
  653. static const int Color = 16;
  654. static const int File = 17;
  655. static const int Reference = 18;
  656. static const int Folder = 19;
  657. static const int EnumMember = 20;
  658. static const int Constant = 21;
  659. static const int Struct = 22;
  660. static const int Event = 23;
  661. static const int Operator = 24;
  662. static const int TypeParameter = 25;
  663. }; // namespace CompletionItemKind
  664. /**
  665. * Defines whether the insert text in a completion item should be interpreted as
  666. * plain text or a snippet.
  667. */
  668. namespace InsertTextFormat {
  669. /**
  670. * The primary text to be inserted is treated as a plain string.
  671. */
  672. static const int PlainText = 1;
  673. /**
  674. * The primary text to be inserted is treated as a snippet.
  675. *
  676. * A snippet can define tab stops and placeholders with `$1`, `$2`
  677. * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
  678. * the end of the snippet. Placeholders with equal identifiers are linked,
  679. * that is typing in one will update others too.
  680. */
  681. static const int Snippet = 2;
  682. }; // namespace InsertTextFormat
  683. struct CompletionItem {
  684. /**
  685. * The label of this completion item. By default
  686. * also the text that is inserted when selecting
  687. * this completion.
  688. */
  689. String label;
  690. /**
  691. * The kind of this completion item. Based of the kind
  692. * an icon is chosen by the editor. The standardized set
  693. * of available values is defined in `CompletionItemKind`.
  694. */
  695. int kind;
  696. /**
  697. * A human-readable string with additional information
  698. * about this item, like type or symbol information.
  699. */
  700. String detail;
  701. /**
  702. * A human-readable string that represents a doc-comment.
  703. */
  704. MarkupContent documentation;
  705. /**
  706. * Indicates if this item is deprecated.
  707. */
  708. bool deprecated = false;
  709. /**
  710. * Select this item when showing.
  711. *
  712. * *Note* that only one completion item can be selected and that the
  713. * tool / client decides which item that is. The rule is that the *first*
  714. * item of those that match best is selected.
  715. */
  716. bool preselect = false;
  717. /**
  718. * A string that should be used when comparing this item
  719. * with other items. When `falsy` the label is used.
  720. */
  721. String sortText;
  722. /**
  723. * A string that should be used when filtering a set of
  724. * completion items. When `falsy` the label is used.
  725. */
  726. String filterText;
  727. /**
  728. * A string that should be inserted into a document when selecting
  729. * this completion. When `falsy` the label is used.
  730. *
  731. * The `insertText` is subject to interpretation by the client side.
  732. * Some tools might not take the string literally. For example
  733. * VS Code when code complete is requested in this example `con<cursor position>`
  734. * and a completion item with an `insertText` of `console` is provided it
  735. * will only insert `sole`. Therefore it is recommended to use `textEdit` instead
  736. * since it avoids additional client side interpretation.
  737. *
  738. * @deprecated Use textEdit instead.
  739. */
  740. String insertText;
  741. /**
  742. * The format of the insert text. The format applies to both the `insertText` property
  743. * and the `newText` property of a provided `textEdit`.
  744. */
  745. int insertTextFormat;
  746. /**
  747. * An edit which is applied to a document when selecting this completion. When an edit is provided the value of
  748. * `insertText` is ignored.
  749. *
  750. * *Note:* The range of the edit must be a single line range and it must contain the position at which completion
  751. * has been requested.
  752. */
  753. TextEdit textEdit;
  754. /**
  755. * An optional array of additional text edits that are applied when
  756. * selecting this completion. Edits must not overlap (including the same insert position)
  757. * with the main edit nor with themselves.
  758. *
  759. * Additional text edits should be used to change text unrelated to the current cursor position
  760. * (for example adding an import statement at the top of the file if the completion item will
  761. * insert an unqualified type).
  762. */
  763. Vector<TextEdit> additionalTextEdits;
  764. /**
  765. * An optional set of characters that when pressed while this completion is active will accept it first and
  766. * then type that character. *Note* that all commit characters should have `length=1` and that superfluous
  767. * characters will be ignored.
  768. */
  769. Vector<String> commitCharacters;
  770. /**
  771. * An optional command that is executed *after* inserting this completion. *Note* that
  772. * additional modifications to the current document should be described with the
  773. * additionalTextEdits-property.
  774. */
  775. Command command;
  776. /**
  777. * A data entry field that is preserved on a completion item between
  778. * a completion and a completion resolve request.
  779. */
  780. Variant data;
  781. _FORCE_INLINE_ Dictionary to_json(bool resolved = false) const {
  782. Dictionary dict;
  783. dict["label"] = label;
  784. dict["kind"] = kind;
  785. dict["data"] = data;
  786. if (resolved) {
  787. dict["insertText"] = insertText;
  788. dict["detail"] = detail;
  789. dict["documentation"] = documentation.to_json();
  790. dict["deprecated"] = deprecated;
  791. dict["preselect"] = preselect;
  792. dict["sortText"] = sortText;
  793. dict["filterText"] = filterText;
  794. if (commitCharacters.size()) dict["commitCharacters"] = commitCharacters;
  795. dict["command"] = command.to_json();
  796. }
  797. return dict;
  798. }
  799. void load(const Dictionary &p_dict) {
  800. if (p_dict.has("label")) label = p_dict["label"];
  801. if (p_dict.has("kind")) kind = p_dict["kind"];
  802. if (p_dict.has("detail")) detail = p_dict["detail"];
  803. if (p_dict.has("documentation")) {
  804. Variant doc = p_dict["documentation"];
  805. if (doc.get_type() == Variant::STRING) {
  806. documentation.value = doc;
  807. } else if (doc.get_type() == Variant::DICTIONARY) {
  808. Dictionary v = doc;
  809. documentation.value = v["value"];
  810. }
  811. }
  812. if (p_dict.has("deprecated")) deprecated = p_dict["deprecated"];
  813. if (p_dict.has("preselect")) preselect = p_dict["preselect"];
  814. if (p_dict.has("sortText")) sortText = p_dict["sortText"];
  815. if (p_dict.has("filterText")) filterText = p_dict["filterText"];
  816. if (p_dict.has("insertText")) insertText = p_dict["insertText"];
  817. if (p_dict.has("data")) data = p_dict["data"];
  818. }
  819. };
  820. /**
  821. * Represents a collection of [completion items](#CompletionItem) to be presented
  822. * in the editor.
  823. */
  824. struct CompletionList {
  825. /**
  826. * This list it not complete. Further typing should result in recomputing
  827. * this list.
  828. */
  829. bool isIncomplete;
  830. /**
  831. * The completion items.
  832. */
  833. Vector<CompletionItem> items;
  834. };
  835. /**
  836. * A symbol kind.
  837. */
  838. namespace SymbolKind {
  839. static const int File = 1;
  840. static const int Module = 2;
  841. static const int Namespace = 3;
  842. static const int Package = 4;
  843. static const int Class = 5;
  844. static const int Method = 6;
  845. static const int Property = 7;
  846. static const int Field = 8;
  847. static const int Constructor = 9;
  848. static const int Enum = 10;
  849. static const int Interface = 11;
  850. static const int Function = 12;
  851. static const int Variable = 13;
  852. static const int Constant = 14;
  853. static const int String = 15;
  854. static const int Number = 16;
  855. static const int Boolean = 17;
  856. static const int Array = 18;
  857. static const int Object = 19;
  858. static const int Key = 20;
  859. static const int Null = 21;
  860. static const int EnumMember = 22;
  861. static const int Struct = 23;
  862. static const int Event = 24;
  863. static const int Operator = 25;
  864. static const int TypeParameter = 26;
  865. }; // namespace SymbolKind
  866. /**
  867. * Represents information about programming constructs like variables, classes,
  868. * interfaces etc.
  869. */
  870. struct SymbolInformation {
  871. /**
  872. * The name of this symbol.
  873. */
  874. String name;
  875. /**
  876. * The kind of this symbol.
  877. */
  878. int kind = SymbolKind::File;
  879. /**
  880. * Indicates if this symbol is deprecated.
  881. */
  882. bool deprecated = false;
  883. /**
  884. * The location of this symbol. The location's range is used by a tool
  885. * to reveal the location in the editor. If the symbol is selected in the
  886. * tool the range's start information is used to position the cursor. So
  887. * the range usually spans more then the actual symbol's name and does
  888. * normally include things like visibility modifiers.
  889. *
  890. * The range doesn't have to denote a node range in the sense of a abstract
  891. * syntax tree. It can therefore not be used to re-construct a hierarchy of
  892. * the symbols.
  893. */
  894. Location location;
  895. /**
  896. * The name of the symbol containing this symbol. This information is for
  897. * user interface purposes (e.g. to render a qualifier in the user interface
  898. * if necessary). It can't be used to re-infer a hierarchy for the document
  899. * symbols.
  900. */
  901. String containerName;
  902. _FORCE_INLINE_ Dictionary to_json() const {
  903. Dictionary dict;
  904. dict["name"] = name;
  905. dict["kind"] = kind;
  906. dict["deprecated"] = deprecated;
  907. dict["location"] = location.to_json();
  908. dict["containerName"] = containerName;
  909. return dict;
  910. }
  911. };
  912. struct DocumentedSymbolInformation : public SymbolInformation {
  913. /**
  914. * A human-readable string with additional information
  915. */
  916. String detail;
  917. /**
  918. * A human-readable string that represents a doc-comment.
  919. */
  920. String documentation;
  921. };
  922. /**
  923. * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document symbols can be
  924. * hierarchical and they have two ranges: one that encloses its definition and one that points to its most interesting range,
  925. * e.g. the range of an identifier.
  926. */
  927. struct DocumentSymbol {
  928. /**
  929. * The name of this symbol. Will be displayed in the user interface and therefore must not be
  930. * an empty string or a string only consisting of white spaces.
  931. */
  932. String name;
  933. /**
  934. * More detail for this symbol, e.g the signature of a function.
  935. */
  936. String detail;
  937. /**
  938. * Documentation for this symbol
  939. */
  940. String documentation;
  941. /**
  942. * Class name for the native symbols
  943. */
  944. String native_class;
  945. /**
  946. * The kind of this symbol.
  947. */
  948. int kind = SymbolKind::File;
  949. /**
  950. * Indicates if this symbol is deprecated.
  951. */
  952. bool deprecated = false;
  953. /**
  954. * The range enclosing this symbol not including leading/trailing whitespace but everything else
  955. * like comments. This information is typically used to determine if the clients cursor is
  956. * inside the symbol to reveal in the symbol in the UI.
  957. */
  958. Range range;
  959. /**
  960. * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function.
  961. * Must be contained by the `range`.
  962. */
  963. Range selectionRange;
  964. DocumentUri uri;
  965. String script_path;
  966. /**
  967. * Children of this symbol, e.g. properties of a class.
  968. */
  969. Vector<DocumentSymbol> children;
  970. _FORCE_INLINE_ Dictionary to_json() const {
  971. Dictionary dict;
  972. dict["name"] = name;
  973. dict["detail"] = detail;
  974. dict["kind"] = kind;
  975. dict["deprecated"] = deprecated;
  976. dict["range"] = range.to_json();
  977. dict["selectionRange"] = selectionRange.to_json();
  978. Array arr;
  979. arr.resize(children.size());
  980. for (int i = 0; i < children.size(); i++) {
  981. arr[i] = children[i].to_json();
  982. }
  983. dict["children"] = arr;
  984. return dict;
  985. }
  986. void symbol_tree_as_list(const String &p_uri, Vector<DocumentedSymbolInformation> &r_list, const String &p_container = "", bool p_join_name = false) const {
  987. DocumentedSymbolInformation si;
  988. if (p_join_name && !p_container.empty()) {
  989. si.name = p_container + ">" + name;
  990. } else {
  991. si.name = name;
  992. }
  993. si.kind = kind;
  994. si.containerName = p_container;
  995. si.deprecated = deprecated;
  996. si.location.uri = p_uri;
  997. si.location.range = range;
  998. si.detail = detail;
  999. si.documentation = documentation;
  1000. r_list.push_back(si);
  1001. for (int i = 0; i < children.size(); i++) {
  1002. children[i].symbol_tree_as_list(p_uri, r_list, si.name, p_join_name);
  1003. }
  1004. }
  1005. _FORCE_INLINE_ MarkupContent render() const {
  1006. MarkupContent markdown;
  1007. if (detail.length()) {
  1008. markdown.value = "\t" + detail + "\n\n";
  1009. }
  1010. if (documentation.length()) {
  1011. markdown.value += documentation + "\n\n";
  1012. }
  1013. if (script_path.length()) {
  1014. markdown.value += "Defined in [" + script_path + "](" + uri + ")";
  1015. }
  1016. return markdown;
  1017. }
  1018. _FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const {
  1019. lsp::CompletionItem item;
  1020. item.label = name;
  1021. if (resolved) {
  1022. item.documentation = render();
  1023. }
  1024. switch (kind) {
  1025. case lsp::SymbolKind::Enum:
  1026. item.kind = lsp::CompletionItemKind::Enum;
  1027. break;
  1028. case lsp::SymbolKind::Class:
  1029. item.kind = lsp::CompletionItemKind::Class;
  1030. break;
  1031. case lsp::SymbolKind::Property:
  1032. item.kind = lsp::CompletionItemKind::Property;
  1033. break;
  1034. case lsp::SymbolKind::Method:
  1035. case lsp::SymbolKind::Function:
  1036. item.kind = lsp::CompletionItemKind::Method;
  1037. break;
  1038. case lsp::SymbolKind::Event:
  1039. item.kind = lsp::CompletionItemKind::Event;
  1040. break;
  1041. case lsp::SymbolKind::Constant:
  1042. item.kind = lsp::CompletionItemKind::Constant;
  1043. break;
  1044. case lsp::SymbolKind::Variable:
  1045. item.kind = lsp::CompletionItemKind::Variable;
  1046. break;
  1047. case lsp::SymbolKind::File:
  1048. item.kind = lsp::CompletionItemKind::File;
  1049. break;
  1050. default:
  1051. item.kind = lsp::CompletionItemKind::Text;
  1052. break;
  1053. }
  1054. return item;
  1055. }
  1056. };
  1057. /**
  1058. * Enum of known range kinds
  1059. */
  1060. namespace FoldingRangeKind {
  1061. /**
  1062. * Folding range for a comment
  1063. */
  1064. static const String Comment = "comment";
  1065. /**
  1066. * Folding range for a imports or includes
  1067. */
  1068. static const String Imports = "imports";
  1069. /**
  1070. * Folding range for a region (e.g. `#region`)
  1071. */
  1072. static const String Region = "region";
  1073. } // namespace FoldingRangeKind
  1074. /**
  1075. * Represents a folding range.
  1076. */
  1077. struct FoldingRange {
  1078. /**
  1079. * The zero-based line number from where the folded range starts.
  1080. */
  1081. int startLine = 0;
  1082. /**
  1083. * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
  1084. */
  1085. int startCharacter = 0;
  1086. /**
  1087. * The zero-based line number where the folded range ends.
  1088. */
  1089. int endLine = 0;
  1090. /**
  1091. * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
  1092. */
  1093. int endCharacter = 0;
  1094. /**
  1095. * Describes the kind of the folding range such as `comment' or 'region'. The kind
  1096. * is used to categorize folding ranges and used by commands like 'Fold all comments'. See
  1097. * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds.
  1098. */
  1099. String kind = FoldingRangeKind::Region;
  1100. _FORCE_INLINE_ Dictionary to_json() const {
  1101. Dictionary dict;
  1102. dict["startLine"] = startLine;
  1103. dict["startCharacter"] = startCharacter;
  1104. dict["endLine"] = endLine;
  1105. dict["endCharacter"] = endCharacter;
  1106. return dict;
  1107. }
  1108. };
  1109. /**
  1110. * How a completion was triggered
  1111. */
  1112. namespace CompletionTriggerKind {
  1113. /**
  1114. * Completion was triggered by typing an identifier (24x7 code
  1115. * complete), manual invocation (e.g Ctrl+Space) or via API.
  1116. */
  1117. static const int Invoked = 1;
  1118. /**
  1119. * Completion was triggered by a trigger character specified by
  1120. * the `triggerCharacters` properties of the `CompletionRegistrationOptions`.
  1121. */
  1122. static const int TriggerCharacter = 2;
  1123. /**
  1124. * Completion was re-triggered as the current completion list is incomplete.
  1125. */
  1126. static const int TriggerForIncompleteCompletions = 3;
  1127. } // namespace CompletionTriggerKind
  1128. /**
  1129. * Contains additional information about the context in which a completion request is triggered.
  1130. */
  1131. struct CompletionContext {
  1132. /**
  1133. * How the completion was triggered.
  1134. */
  1135. int triggerKind = CompletionTriggerKind::TriggerCharacter;
  1136. /**
  1137. * The trigger character (a single character) that has trigger code complete.
  1138. * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter`
  1139. */
  1140. String triggerCharacter;
  1141. void load(const Dictionary &p_params) {
  1142. triggerKind = int(p_params["triggerKind"]);
  1143. triggerCharacter = p_params["triggerCharacter"];
  1144. }
  1145. };
  1146. struct CompletionParams : public TextDocumentPositionParams {
  1147. /**
  1148. * The completion context. This is only available if the client specifies
  1149. * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true`
  1150. */
  1151. CompletionContext context;
  1152. void load(const Dictionary &p_params) {
  1153. TextDocumentPositionParams::load(p_params);
  1154. context.load(p_params["context"]);
  1155. }
  1156. };
  1157. /**
  1158. * The result of a hover request.
  1159. */
  1160. struct Hover {
  1161. /**
  1162. * The hover's content
  1163. */
  1164. MarkupContent contents;
  1165. /**
  1166. * An optional range is a range inside a text document
  1167. * that is used to visualize a hover, e.g. by changing the background color.
  1168. */
  1169. Range range;
  1170. _FORCE_INLINE_ Dictionary to_json() const {
  1171. Dictionary dict;
  1172. dict["range"] = range.to_json();
  1173. dict["contents"] = contents.to_json();
  1174. return dict;
  1175. }
  1176. };
  1177. struct ServerCapabilities {
  1178. /**
  1179. * Defines how text documents are synced. Is either a detailed structure defining each notification or
  1180. * for backwards compatibility the TextDocumentSyncKind number. If omitted it defaults to `TextDocumentSyncKind.None`.
  1181. */
  1182. TextDocumentSyncOptions textDocumentSync;
  1183. /**
  1184. * The server provides hover support.
  1185. */
  1186. bool hoverProvider = true;
  1187. /**
  1188. * The server provides completion support.
  1189. */
  1190. CompletionOptions completionProvider;
  1191. /**
  1192. * The server provides signature help support.
  1193. */
  1194. SignatureHelpOptions signatureHelpProvider;
  1195. /**
  1196. * The server provides goto definition support.
  1197. */
  1198. bool definitionProvider = true;
  1199. /**
  1200. * The server provides Goto Type Definition support.
  1201. *
  1202. * Since 3.6.0
  1203. */
  1204. bool typeDefinitionProvider = false;
  1205. /**
  1206. * The server provides Goto Implementation support.
  1207. *
  1208. * Since 3.6.0
  1209. */
  1210. bool implementationProvider = false;
  1211. /**
  1212. * The server provides find references support.
  1213. */
  1214. bool referencesProvider = false;
  1215. /**
  1216. * The server provides document highlight support.
  1217. */
  1218. bool documentHighlightProvider = false;
  1219. /**
  1220. * The server provides document symbol support.
  1221. */
  1222. bool documentSymbolProvider = true;
  1223. /**
  1224. * The server provides workspace symbol support.
  1225. */
  1226. bool workspaceSymbolProvider = true;
  1227. /**
  1228. * The server provides code actions. The `CodeActionOptions` return type is only
  1229. * valid if the client signals code action literal support via the property
  1230. * `textDocument.codeAction.codeActionLiteralSupport`.
  1231. */
  1232. bool codeActionProvider = false;
  1233. /**
  1234. * The server provides code lens.
  1235. */
  1236. CodeLensOptions codeLensProvider;
  1237. /**
  1238. * The server provides document formatting.
  1239. */
  1240. bool documentFormattingProvider = false;
  1241. /**
  1242. * The server provides document range formatting.
  1243. */
  1244. bool documentRangeFormattingProvider = false;
  1245. /**
  1246. * The server provides document formatting on typing.
  1247. */
  1248. DocumentOnTypeFormattingOptions documentOnTypeFormattingProvider;
  1249. /**
  1250. * The server provides rename support. RenameOptions may only be
  1251. * specified if the client states that it supports
  1252. * `prepareSupport` in its initial `initialize` request.
  1253. */
  1254. RenameOptions renameProvider;
  1255. /**
  1256. * The server provides document link support.
  1257. */
  1258. DocumentLinkOptions documentLinkProvider;
  1259. /**
  1260. * The server provides color provider support.
  1261. *
  1262. * Since 3.6.0
  1263. */
  1264. ColorProviderOptions colorProvider;
  1265. /**
  1266. * The server provides folding provider support.
  1267. *
  1268. * Since 3.10.0
  1269. */
  1270. FoldingRangeProviderOptions foldingRangeProvider;
  1271. /**
  1272. * The server provides go to declaration support.
  1273. *
  1274. * Since 3.14.0
  1275. */
  1276. bool declarationProvider = true;
  1277. /**
  1278. * The server provides execute command support.
  1279. */
  1280. ExecuteCommandOptions executeCommandProvider;
  1281. _FORCE_INLINE_ Dictionary to_json() {
  1282. Dictionary dict;
  1283. dict["textDocumentSync"] = (int)textDocumentSync.change;
  1284. dict["completionProvider"] = completionProvider.to_json();
  1285. dict["signatureHelpProvider"] = signatureHelpProvider.to_json();
  1286. dict["codeLensProvider"] = false; // codeLensProvider.to_json();
  1287. dict["documentOnTypeFormattingProvider"] = documentOnTypeFormattingProvider.to_json();
  1288. dict["renameProvider"] = renameProvider.to_json();
  1289. dict["documentLinkProvider"] = documentLinkProvider.to_json();
  1290. dict["colorProvider"] = false; // colorProvider.to_json();
  1291. dict["foldingRangeProvider"] = false; //foldingRangeProvider.to_json();
  1292. dict["executeCommandProvider"] = executeCommandProvider.to_json();
  1293. dict["hoverProvider"] = hoverProvider;
  1294. dict["definitionProvider"] = definitionProvider;
  1295. dict["typeDefinitionProvider"] = typeDefinitionProvider;
  1296. dict["implementationProvider"] = implementationProvider;
  1297. dict["referencesProvider"] = referencesProvider;
  1298. dict["documentHighlightProvider"] = documentHighlightProvider;
  1299. dict["documentSymbolProvider"] = documentSymbolProvider;
  1300. dict["workspaceSymbolProvider"] = workspaceSymbolProvider;
  1301. dict["codeActionProvider"] = codeActionProvider;
  1302. dict["documentFormattingProvider"] = documentFormattingProvider;
  1303. dict["documentRangeFormattingProvider"] = documentRangeFormattingProvider;
  1304. dict["declarationProvider"] = declarationProvider;
  1305. return dict;
  1306. }
  1307. };
  1308. struct InitializeResult {
  1309. /**
  1310. * The capabilities the language server provides.
  1311. */
  1312. ServerCapabilities capabilities;
  1313. _FORCE_INLINE_ Dictionary to_json() {
  1314. Dictionary dict;
  1315. dict["capabilities"] = capabilities.to_json();
  1316. return dict;
  1317. }
  1318. };
  1319. } // namespace lsp
  1320. #endif