2
0

lsp.hpp 33 KB

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