main.d.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * A tagging type for string properties that are actually URIs.
  3. */
  4. export declare type DocumentUri = string;
  5. /**
  6. * Position in a text document expressed as zero-based line and character offset.
  7. * The offsets are based on a UTF-16 string representation. So a string of the form
  8. * `a𐐀b` the character offset of the character `a` is 0, the character offset of `𐐀`
  9. * is 1 and the character offset of b is 3 since `𐐀` is represented using two code
  10. * units in UTF-16.
  11. *
  12. * Positions are line end character agnostic. So you can not specify a position that
  13. * denotes `\r|\n` or `\n|` where `|` represents the character offset.
  14. */
  15. export interface Position {
  16. /**
  17. * Line position in a document (zero-based).
  18. * If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.
  19. * If a line number is negative, it defaults to 0.
  20. */
  21. line: number;
  22. /**
  23. * Character offset on a line in a document (zero-based). Assuming that the line is
  24. * represented as a string, the `character` value represents the gap between the
  25. * `character` and `character + 1`.
  26. *
  27. * If the character value is greater than the line length it defaults back to the
  28. * line length.
  29. * If a line number is negative, it defaults to 0.
  30. */
  31. character: number;
  32. }
  33. /**
  34. * A range in a text document expressed as (zero-based) start and end positions.
  35. *
  36. * If you want to specify a range that contains a line including the line ending
  37. * character(s) then use an end position denoting the start of the next line.
  38. * For example:
  39. * ```ts
  40. * {
  41. * start: { line: 5, character: 23 }
  42. * end : { line 6, character : 0 }
  43. * }
  44. * ```
  45. */
  46. export interface Range {
  47. /**
  48. * The range's start position
  49. */
  50. start: Position;
  51. /**
  52. * The range's end position.
  53. */
  54. end: Position;
  55. }
  56. /**
  57. * A text edit applicable to a text document.
  58. */
  59. export interface TextEdit {
  60. /**
  61. * The range of the text document to be manipulated. To insert
  62. * text into a document create a range where start === end.
  63. */
  64. range: Range;
  65. /**
  66. * The string to be inserted. For delete operations use an
  67. * empty string.
  68. */
  69. newText: string;
  70. }
  71. /**
  72. * An event describing a change to a text document. If range and rangeLength are omitted
  73. * the new text is considered to be the full content of the document.
  74. */
  75. export declare type TextDocumentContentChangeEvent = {
  76. /**
  77. * The range of the document that changed.
  78. */
  79. range: Range;
  80. /**
  81. * The optional length of the range that got replaced.
  82. *
  83. * @deprecated use range instead.
  84. */
  85. rangeLength?: number;
  86. /**
  87. * The new text for the provided range.
  88. */
  89. text: string;
  90. } | {
  91. /**
  92. * The new text of the whole document.
  93. */
  94. text: string;
  95. };
  96. /**
  97. * A simple text document. Not to be implemented. The document keeps the content
  98. * as string.
  99. */
  100. export interface TextDocument {
  101. /**
  102. * The associated URI for this document. Most documents have the __file__-scheme, indicating that they
  103. * represent files on disk. However, some documents may have other schemes indicating that they are not
  104. * available on disk.
  105. *
  106. * @readonly
  107. */
  108. readonly uri: DocumentUri;
  109. /**
  110. * The identifier of the language associated with this document.
  111. *
  112. * @readonly
  113. */
  114. readonly languageId: string;
  115. /**
  116. * The version number of this document (it will increase after each
  117. * change, including undo/redo).
  118. *
  119. * @readonly
  120. */
  121. readonly version: number;
  122. /**
  123. * Get the text of this document. A substring can be retrieved by
  124. * providing a range.
  125. *
  126. * @param range (optional) An range within the document to return.
  127. * If no range is passed, the full content is returned.
  128. * Invalid range positions are adjusted as described in [Position.line](#Position.line)
  129. * and [Position.character](#Position.character).
  130. * If the start range position is greater than the end range position,
  131. * then the effect of getText is as if the two positions were swapped.
  132. * @return The text of this document or a substring of the text if a
  133. * range is provided.
  134. */
  135. getText(range?: Range): string;
  136. /**
  137. * Converts a zero-based offset to a position.
  138. *
  139. * @param offset A zero-based offset.
  140. * @return A valid [position](#Position).
  141. */
  142. positionAt(offset: number): Position;
  143. /**
  144. * Converts the position to a zero-based offset.
  145. * Invalid positions are adjusted as described in [Position.line](#Position.line)
  146. * and [Position.character](#Position.character).
  147. *
  148. * @param position A position.
  149. * @return A valid zero-based offset.
  150. */
  151. offsetAt(position: Position): number;
  152. /**
  153. * The number of lines in this document.
  154. *
  155. * @readonly
  156. */
  157. readonly lineCount: number;
  158. }
  159. export declare namespace TextDocument {
  160. /**
  161. * Creates a new text document.
  162. *
  163. * @param uri The document's uri.
  164. * @param languageId The document's language Id.
  165. * @param version The document's initial version number.
  166. * @param content The document's content.
  167. */
  168. function create(uri: DocumentUri, languageId: string, version: number, content: string): TextDocument;
  169. /**
  170. * Updates a TextDocument by modifing its content.
  171. *
  172. * @param document the document to update. Only documents created by TextDocument.create are valid inputs.
  173. * @param changes the changes to apply to the document.
  174. * @returns The updated TextDocument. Note: That's the same document instance passed in as first parameter.
  175. *
  176. */
  177. function update(document: TextDocument, changes: TextDocumentContentChangeEvent[], version: number): TextDocument;
  178. function applyEdits(document: TextDocument, edits: TextEdit[]): string;
  179. }