My dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1528 line
53 KiB

  1. /* --------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. * ------------------------------------------------------------------------------------------ */
  5. 'use strict';
  6. /**
  7. * The Position namespace provides helper functions to work with
  8. * [Position](#Position) literals.
  9. */
  10. export var Position;
  11. (function (Position) {
  12. /**
  13. * Creates a new Position literal from the given line and character.
  14. * @param line The position's line.
  15. * @param character The position's character.
  16. */
  17. function create(line, character) {
  18. return { line: line, character: character };
  19. }
  20. Position.create = create;
  21. /**
  22. * Checks whether the given liternal conforms to the [Position](#Position) interface.
  23. */
  24. function is(value) {
  25. var candidate = value;
  26. return Is.objectLiteral(candidate) && Is.number(candidate.line) && Is.number(candidate.character);
  27. }
  28. Position.is = is;
  29. })(Position || (Position = {}));
  30. /**
  31. * The Range namespace provides helper functions to work with
  32. * [Range](#Range) literals.
  33. */
  34. export var Range;
  35. (function (Range) {
  36. function create(one, two, three, four) {
  37. if (Is.number(one) && Is.number(two) && Is.number(three) && Is.number(four)) {
  38. return { start: Position.create(one, two), end: Position.create(three, four) };
  39. }
  40. else if (Position.is(one) && Position.is(two)) {
  41. return { start: one, end: two };
  42. }
  43. else {
  44. throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
  45. }
  46. }
  47. Range.create = create;
  48. /**
  49. * Checks whether the given literal conforms to the [Range](#Range) interface.
  50. */
  51. function is(value) {
  52. var candidate = value;
  53. return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
  54. }
  55. Range.is = is;
  56. })(Range || (Range = {}));
  57. /**
  58. * The Location namespace provides helper functions to work with
  59. * [Location](#Location) literals.
  60. */
  61. export var Location;
  62. (function (Location) {
  63. /**
  64. * Creates a Location literal.
  65. * @param uri The location's uri.
  66. * @param range The location's range.
  67. */
  68. function create(uri, range) {
  69. return { uri: uri, range: range };
  70. }
  71. Location.create = create;
  72. /**
  73. * Checks whether the given literal conforms to the [Location](#Location) interface.
  74. */
  75. function is(value) {
  76. var candidate = value;
  77. return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
  78. }
  79. Location.is = is;
  80. })(Location || (Location = {}));
  81. /**
  82. * The LocationLink namespace provides helper functions to work with
  83. * [LocationLink](#LocationLink) literals.
  84. */
  85. export var LocationLink;
  86. (function (LocationLink) {
  87. /**
  88. * Creates a LocationLink literal.
  89. * @param targetUri The definition's uri.
  90. * @param targetRange The full range of the definition.
  91. * @param targetSelectionRange The span of the symbol definition at the target.
  92. * @param originSelectionRange The span of the symbol being defined in the originating source file.
  93. */
  94. function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
  95. return { targetUri: targetUri, targetRange: targetRange, targetSelectionRange: targetSelectionRange, originSelectionRange: originSelectionRange };
  96. }
  97. LocationLink.create = create;
  98. /**
  99. * Checks whether the given literal conforms to the [LocationLink](#LocationLink) interface.
  100. */
  101. function is(value) {
  102. var candidate = value;
  103. return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri)
  104. && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange))
  105. && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
  106. }
  107. LocationLink.is = is;
  108. })(LocationLink || (LocationLink = {}));
  109. /**
  110. * The Color namespace provides helper functions to work with
  111. * [Color](#Color) literals.
  112. */
  113. export var Color;
  114. (function (Color) {
  115. /**
  116. * Creates a new Color literal.
  117. */
  118. function create(red, green, blue, alpha) {
  119. return {
  120. red: red,
  121. green: green,
  122. blue: blue,
  123. alpha: alpha,
  124. };
  125. }
  126. Color.create = create;
  127. /**
  128. * Checks whether the given literal conforms to the [Color](#Color) interface.
  129. */
  130. function is(value) {
  131. var candidate = value;
  132. return Is.number(candidate.red)
  133. && Is.number(candidate.green)
  134. && Is.number(candidate.blue)
  135. && Is.number(candidate.alpha);
  136. }
  137. Color.is = is;
  138. })(Color || (Color = {}));
  139. /**
  140. * The ColorInformation namespace provides helper functions to work with
  141. * [ColorInformation](#ColorInformation) literals.
  142. */
  143. export var ColorInformation;
  144. (function (ColorInformation) {
  145. /**
  146. * Creates a new ColorInformation literal.
  147. */
  148. function create(range, color) {
  149. return {
  150. range: range,
  151. color: color,
  152. };
  153. }
  154. ColorInformation.create = create;
  155. /**
  156. * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
  157. */
  158. function is(value) {
  159. var candidate = value;
  160. return Range.is(candidate.range) && Color.is(candidate.color);
  161. }
  162. ColorInformation.is = is;
  163. })(ColorInformation || (ColorInformation = {}));
  164. /**
  165. * The Color namespace provides helper functions to work with
  166. * [ColorPresentation](#ColorPresentation) literals.
  167. */
  168. export var ColorPresentation;
  169. (function (ColorPresentation) {
  170. /**
  171. * Creates a new ColorInformation literal.
  172. */
  173. function create(label, textEdit, additionalTextEdits) {
  174. return {
  175. label: label,
  176. textEdit: textEdit,
  177. additionalTextEdits: additionalTextEdits,
  178. };
  179. }
  180. ColorPresentation.create = create;
  181. /**
  182. * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
  183. */
  184. function is(value) {
  185. var candidate = value;
  186. return Is.string(candidate.label)
  187. && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
  188. && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
  189. }
  190. ColorPresentation.is = is;
  191. })(ColorPresentation || (ColorPresentation = {}));
  192. /**
  193. * Enum of known range kinds
  194. */
  195. export var FoldingRangeKind;
  196. (function (FoldingRangeKind) {
  197. /**
  198. * Folding range for a comment
  199. */
  200. FoldingRangeKind["Comment"] = "comment";
  201. /**
  202. * Folding range for a imports or includes
  203. */
  204. FoldingRangeKind["Imports"] = "imports";
  205. /**
  206. * Folding range for a region (e.g. `#region`)
  207. */
  208. FoldingRangeKind["Region"] = "region";
  209. })(FoldingRangeKind || (FoldingRangeKind = {}));
  210. /**
  211. * The folding range namespace provides helper functions to work with
  212. * [FoldingRange](#FoldingRange) literals.
  213. */
  214. export var FoldingRange;
  215. (function (FoldingRange) {
  216. /**
  217. * Creates a new FoldingRange literal.
  218. */
  219. function create(startLine, endLine, startCharacter, endCharacter, kind) {
  220. var result = {
  221. startLine: startLine,
  222. endLine: endLine
  223. };
  224. if (Is.defined(startCharacter)) {
  225. result.startCharacter = startCharacter;
  226. }
  227. if (Is.defined(endCharacter)) {
  228. result.endCharacter = endCharacter;
  229. }
  230. if (Is.defined(kind)) {
  231. result.kind = kind;
  232. }
  233. return result;
  234. }
  235. FoldingRange.create = create;
  236. /**
  237. * Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
  238. */
  239. function is(value) {
  240. var candidate = value;
  241. return Is.number(candidate.startLine) && Is.number(candidate.startLine)
  242. && (Is.undefined(candidate.startCharacter) || Is.number(candidate.startCharacter))
  243. && (Is.undefined(candidate.endCharacter) || Is.number(candidate.endCharacter))
  244. && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
  245. }
  246. FoldingRange.is = is;
  247. })(FoldingRange || (FoldingRange = {}));
  248. /**
  249. * The DiagnosticRelatedInformation namespace provides helper functions to work with
  250. * [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
  251. */
  252. export var DiagnosticRelatedInformation;
  253. (function (DiagnosticRelatedInformation) {
  254. /**
  255. * Creates a new DiagnosticRelatedInformation literal.
  256. */
  257. function create(location, message) {
  258. return {
  259. location: location,
  260. message: message
  261. };
  262. }
  263. DiagnosticRelatedInformation.create = create;
  264. /**
  265. * Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
  266. */
  267. function is(value) {
  268. var candidate = value;
  269. return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
  270. }
  271. DiagnosticRelatedInformation.is = is;
  272. })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
  273. /**
  274. * The diagnostic's severity.
  275. */
  276. export var DiagnosticSeverity;
  277. (function (DiagnosticSeverity) {
  278. /**
  279. * Reports an error.
  280. */
  281. DiagnosticSeverity.Error = 1;
  282. /**
  283. * Reports a warning.
  284. */
  285. DiagnosticSeverity.Warning = 2;
  286. /**
  287. * Reports an information.
  288. */
  289. DiagnosticSeverity.Information = 3;
  290. /**
  291. * Reports a hint.
  292. */
  293. DiagnosticSeverity.Hint = 4;
  294. })(DiagnosticSeverity || (DiagnosticSeverity = {}));
  295. /**
  296. * The diagnostic tags.
  297. *
  298. * @since 3.15.0
  299. */
  300. export var DiagnosticTag;
  301. (function (DiagnosticTag) {
  302. /**
  303. * Unused or unnecessary code.
  304. *
  305. * Clients are allowed to render diagnostics with this tag faded out instead of having
  306. * an error squiggle.
  307. */
  308. DiagnosticTag.Unnecessary = 1;
  309. /**
  310. * Deprecated or obsolete code.
  311. *
  312. * Clients are allowed to rendered diagnostics with this tag strike through.
  313. */
  314. DiagnosticTag.Deprecated = 2;
  315. })(DiagnosticTag || (DiagnosticTag = {}));
  316. /**
  317. * The Diagnostic namespace provides helper functions to work with
  318. * [Diagnostic](#Diagnostic) literals.
  319. */
  320. export var Diagnostic;
  321. (function (Diagnostic) {
  322. /**
  323. * Creates a new Diagnostic literal.
  324. */
  325. function create(range, message, severity, code, source, relatedInformation) {
  326. var result = { range: range, message: message };
  327. if (Is.defined(severity)) {
  328. result.severity = severity;
  329. }
  330. if (Is.defined(code)) {
  331. result.code = code;
  332. }
  333. if (Is.defined(source)) {
  334. result.source = source;
  335. }
  336. if (Is.defined(relatedInformation)) {
  337. result.relatedInformation = relatedInformation;
  338. }
  339. return result;
  340. }
  341. Diagnostic.create = create;
  342. /**
  343. * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
  344. */
  345. function is(value) {
  346. var candidate = value;
  347. return Is.defined(candidate)
  348. && Range.is(candidate.range)
  349. && Is.string(candidate.message)
  350. && (Is.number(candidate.severity) || Is.undefined(candidate.severity))
  351. && (Is.number(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
  352. && (Is.string(candidate.source) || Is.undefined(candidate.source))
  353. && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
  354. }
  355. Diagnostic.is = is;
  356. })(Diagnostic || (Diagnostic = {}));
  357. /**
  358. * The Command namespace provides helper functions to work with
  359. * [Command](#Command) literals.
  360. */
  361. export var Command;
  362. (function (Command) {
  363. /**
  364. * Creates a new Command literal.
  365. */
  366. function create(title, command) {
  367. var args = [];
  368. for (var _i = 2; _i < arguments.length; _i++) {
  369. args[_i - 2] = arguments[_i];
  370. }
  371. var result = { title: title, command: command };
  372. if (Is.defined(args) && args.length > 0) {
  373. result.arguments = args;
  374. }
  375. return result;
  376. }
  377. Command.create = create;
  378. /**
  379. * Checks whether the given literal conforms to the [Command](#Command) interface.
  380. */
  381. function is(value) {
  382. var candidate = value;
  383. return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
  384. }
  385. Command.is = is;
  386. })(Command || (Command = {}));
  387. /**
  388. * The TextEdit namespace provides helper function to create replace,
  389. * insert and delete edits more easily.
  390. */
  391. export var TextEdit;
  392. (function (TextEdit) {
  393. /**
  394. * Creates a replace text edit.
  395. * @param range The range of text to be replaced.
  396. * @param newText The new text.
  397. */
  398. function replace(range, newText) {
  399. return { range: range, newText: newText };
  400. }
  401. TextEdit.replace = replace;
  402. /**
  403. * Creates a insert text edit.
  404. * @param position The position to insert the text at.
  405. * @param newText The text to be inserted.
  406. */
  407. function insert(position, newText) {
  408. return { range: { start: position, end: position }, newText: newText };
  409. }
  410. TextEdit.insert = insert;
  411. /**
  412. * Creates a delete text edit.
  413. * @param range The range of text to be deleted.
  414. */
  415. function del(range) {
  416. return { range: range, newText: '' };
  417. }
  418. TextEdit.del = del;
  419. function is(value) {
  420. var candidate = value;
  421. return Is.objectLiteral(candidate)
  422. && Is.string(candidate.newText)
  423. && Range.is(candidate.range);
  424. }
  425. TextEdit.is = is;
  426. })(TextEdit || (TextEdit = {}));
  427. /**
  428. * The TextDocumentEdit namespace provides helper function to create
  429. * an edit that manipulates a text document.
  430. */
  431. export var TextDocumentEdit;
  432. (function (TextDocumentEdit) {
  433. /**
  434. * Creates a new `TextDocumentEdit`
  435. */
  436. function create(textDocument, edits) {
  437. return { textDocument: textDocument, edits: edits };
  438. }
  439. TextDocumentEdit.create = create;
  440. function is(value) {
  441. var candidate = value;
  442. return Is.defined(candidate)
  443. && VersionedTextDocumentIdentifier.is(candidate.textDocument)
  444. && Array.isArray(candidate.edits);
  445. }
  446. TextDocumentEdit.is = is;
  447. })(TextDocumentEdit || (TextDocumentEdit = {}));
  448. export var CreateFile;
  449. (function (CreateFile) {
  450. function create(uri, options) {
  451. var result = {
  452. kind: 'create',
  453. uri: uri
  454. };
  455. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  456. result.options = options;
  457. }
  458. return result;
  459. }
  460. CreateFile.create = create;
  461. function is(value) {
  462. var candidate = value;
  463. return candidate && candidate.kind === 'create' && Is.string(candidate.uri) &&
  464. (candidate.options === void 0 ||
  465. ((candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))));
  466. }
  467. CreateFile.is = is;
  468. })(CreateFile || (CreateFile = {}));
  469. export var RenameFile;
  470. (function (RenameFile) {
  471. function create(oldUri, newUri, options) {
  472. var result = {
  473. kind: 'rename',
  474. oldUri: oldUri,
  475. newUri: newUri
  476. };
  477. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  478. result.options = options;
  479. }
  480. return result;
  481. }
  482. RenameFile.create = create;
  483. function is(value) {
  484. var candidate = value;
  485. return candidate && candidate.kind === 'rename' && Is.string(candidate.oldUri) && Is.string(candidate.newUri) &&
  486. (candidate.options === void 0 ||
  487. ((candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))));
  488. }
  489. RenameFile.is = is;
  490. })(RenameFile || (RenameFile = {}));
  491. export var DeleteFile;
  492. (function (DeleteFile) {
  493. function create(uri, options) {
  494. var result = {
  495. kind: 'delete',
  496. uri: uri
  497. };
  498. if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) {
  499. result.options = options;
  500. }
  501. return result;
  502. }
  503. DeleteFile.create = create;
  504. function is(value) {
  505. var candidate = value;
  506. return candidate && candidate.kind === 'delete' && Is.string(candidate.uri) &&
  507. (candidate.options === void 0 ||
  508. ((candidate.options.recursive === void 0 || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === void 0 || Is.boolean(candidate.options.ignoreIfNotExists))));
  509. }
  510. DeleteFile.is = is;
  511. })(DeleteFile || (DeleteFile = {}));
  512. export var WorkspaceEdit;
  513. (function (WorkspaceEdit) {
  514. function is(value) {
  515. var candidate = value;
  516. return candidate &&
  517. (candidate.changes !== void 0 || candidate.documentChanges !== void 0) &&
  518. (candidate.documentChanges === void 0 || candidate.documentChanges.every(function (change) {
  519. if (Is.string(change.kind)) {
  520. return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
  521. }
  522. else {
  523. return TextDocumentEdit.is(change);
  524. }
  525. }));
  526. }
  527. WorkspaceEdit.is = is;
  528. })(WorkspaceEdit || (WorkspaceEdit = {}));
  529. var TextEditChangeImpl = /** @class */ (function () {
  530. function TextEditChangeImpl(edits) {
  531. this.edits = edits;
  532. }
  533. TextEditChangeImpl.prototype.insert = function (position, newText) {
  534. this.edits.push(TextEdit.insert(position, newText));
  535. };
  536. TextEditChangeImpl.prototype.replace = function (range, newText) {
  537. this.edits.push(TextEdit.replace(range, newText));
  538. };
  539. TextEditChangeImpl.prototype.delete = function (range) {
  540. this.edits.push(TextEdit.del(range));
  541. };
  542. TextEditChangeImpl.prototype.add = function (edit) {
  543. this.edits.push(edit);
  544. };
  545. TextEditChangeImpl.prototype.all = function () {
  546. return this.edits;
  547. };
  548. TextEditChangeImpl.prototype.clear = function () {
  549. this.edits.splice(0, this.edits.length);
  550. };
  551. return TextEditChangeImpl;
  552. }());
  553. /**
  554. * A workspace change helps constructing changes to a workspace.
  555. */
  556. var WorkspaceChange = /** @class */ (function () {
  557. function WorkspaceChange(workspaceEdit) {
  558. var _this = this;
  559. this._textEditChanges = Object.create(null);
  560. if (workspaceEdit) {
  561. this._workspaceEdit = workspaceEdit;
  562. if (workspaceEdit.documentChanges) {
  563. workspaceEdit.documentChanges.forEach(function (change) {
  564. if (TextDocumentEdit.is(change)) {
  565. var textEditChange = new TextEditChangeImpl(change.edits);
  566. _this._textEditChanges[change.textDocument.uri] = textEditChange;
  567. }
  568. });
  569. }
  570. else if (workspaceEdit.changes) {
  571. Object.keys(workspaceEdit.changes).forEach(function (key) {
  572. var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
  573. _this._textEditChanges[key] = textEditChange;
  574. });
  575. }
  576. }
  577. }
  578. Object.defineProperty(WorkspaceChange.prototype, "edit", {
  579. /**
  580. * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
  581. * use to be returned from a workspace edit operation like rename.
  582. */
  583. get: function () {
  584. return this._workspaceEdit;
  585. },
  586. enumerable: true,
  587. configurable: true
  588. });
  589. WorkspaceChange.prototype.getTextEditChange = function (key) {
  590. if (VersionedTextDocumentIdentifier.is(key)) {
  591. if (!this._workspaceEdit) {
  592. this._workspaceEdit = {
  593. documentChanges: []
  594. };
  595. }
  596. if (!this._workspaceEdit.documentChanges) {
  597. throw new Error('Workspace edit is not configured for document changes.');
  598. }
  599. var textDocument = key;
  600. var result = this._textEditChanges[textDocument.uri];
  601. if (!result) {
  602. var edits = [];
  603. var textDocumentEdit = {
  604. textDocument: textDocument,
  605. edits: edits
  606. };
  607. this._workspaceEdit.documentChanges.push(textDocumentEdit);
  608. result = new TextEditChangeImpl(edits);
  609. this._textEditChanges[textDocument.uri] = result;
  610. }
  611. return result;
  612. }
  613. else {
  614. if (!this._workspaceEdit) {
  615. this._workspaceEdit = {
  616. changes: Object.create(null)
  617. };
  618. }
  619. if (!this._workspaceEdit.changes) {
  620. throw new Error('Workspace edit is not configured for normal text edit changes.');
  621. }
  622. var result = this._textEditChanges[key];
  623. if (!result) {
  624. var edits = [];
  625. this._workspaceEdit.changes[key] = edits;
  626. result = new TextEditChangeImpl(edits);
  627. this._textEditChanges[key] = result;
  628. }
  629. return result;
  630. }
  631. };
  632. WorkspaceChange.prototype.createFile = function (uri, options) {
  633. this.checkDocumentChanges();
  634. this._workspaceEdit.documentChanges.push(CreateFile.create(uri, options));
  635. };
  636. WorkspaceChange.prototype.renameFile = function (oldUri, newUri, options) {
  637. this.checkDocumentChanges();
  638. this._workspaceEdit.documentChanges.push(RenameFile.create(oldUri, newUri, options));
  639. };
  640. WorkspaceChange.prototype.deleteFile = function (uri, options) {
  641. this.checkDocumentChanges();
  642. this._workspaceEdit.documentChanges.push(DeleteFile.create(uri, options));
  643. };
  644. WorkspaceChange.prototype.checkDocumentChanges = function () {
  645. if (!this._workspaceEdit || !this._workspaceEdit.documentChanges) {
  646. throw new Error('Workspace edit is not configured for document changes.');
  647. }
  648. };
  649. return WorkspaceChange;
  650. }());
  651. export { WorkspaceChange };
  652. /**
  653. * The TextDocumentIdentifier namespace provides helper functions to work with
  654. * [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
  655. */
  656. export var TextDocumentIdentifier;
  657. (function (TextDocumentIdentifier) {
  658. /**
  659. * Creates a new TextDocumentIdentifier literal.
  660. * @param uri The document's uri.
  661. */
  662. function create(uri) {
  663. return { uri: uri };
  664. }
  665. TextDocumentIdentifier.create = create;
  666. /**
  667. * Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
  668. */
  669. function is(value) {
  670. var candidate = value;
  671. return Is.defined(candidate) && Is.string(candidate.uri);
  672. }
  673. TextDocumentIdentifier.is = is;
  674. })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
  675. /**
  676. * The VersionedTextDocumentIdentifier namespace provides helper functions to work with
  677. * [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
  678. */
  679. export var VersionedTextDocumentIdentifier;
  680. (function (VersionedTextDocumentIdentifier) {
  681. /**
  682. * Creates a new VersionedTextDocumentIdentifier literal.
  683. * @param uri The document's uri.
  684. * @param uri The document's text.
  685. */
  686. function create(uri, version) {
  687. return { uri: uri, version: version };
  688. }
  689. VersionedTextDocumentIdentifier.create = create;
  690. /**
  691. * Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
  692. */
  693. function is(value) {
  694. var candidate = value;
  695. return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.number(candidate.version));
  696. }
  697. VersionedTextDocumentIdentifier.is = is;
  698. })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
  699. /**
  700. * The TextDocumentItem namespace provides helper functions to work with
  701. * [TextDocumentItem](#TextDocumentItem) literals.
  702. */
  703. export var TextDocumentItem;
  704. (function (TextDocumentItem) {
  705. /**
  706. * Creates a new TextDocumentItem literal.
  707. * @param uri The document's uri.
  708. * @param languageId The document's language identifier.
  709. * @param version The document's version number.
  710. * @param text The document's text.
  711. */
  712. function create(uri, languageId, version, text) {
  713. return { uri: uri, languageId: languageId, version: version, text: text };
  714. }
  715. TextDocumentItem.create = create;
  716. /**
  717. * Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
  718. */
  719. function is(value) {
  720. var candidate = value;
  721. return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.number(candidate.version) && Is.string(candidate.text);
  722. }
  723. TextDocumentItem.is = is;
  724. })(TextDocumentItem || (TextDocumentItem = {}));
  725. /**
  726. * Describes the content type that a client supports in various
  727. * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
  728. *
  729. * Please note that `MarkupKinds` must not start with a `$`. This kinds
  730. * are reserved for internal usage.
  731. */
  732. export var MarkupKind;
  733. (function (MarkupKind) {
  734. /**
  735. * Plain text is supported as a content format
  736. */
  737. MarkupKind.PlainText = 'plaintext';
  738. /**
  739. * Markdown is supported as a content format
  740. */
  741. MarkupKind.Markdown = 'markdown';
  742. })(MarkupKind || (MarkupKind = {}));
  743. (function (MarkupKind) {
  744. /**
  745. * Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
  746. */
  747. function is(value) {
  748. var candidate = value;
  749. return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
  750. }
  751. MarkupKind.is = is;
  752. })(MarkupKind || (MarkupKind = {}));
  753. export var MarkupContent;
  754. (function (MarkupContent) {
  755. /**
  756. * Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
  757. */
  758. function is(value) {
  759. var candidate = value;
  760. return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
  761. }
  762. MarkupContent.is = is;
  763. })(MarkupContent || (MarkupContent = {}));
  764. /**
  765. * The kind of a completion entry.
  766. */
  767. export var CompletionItemKind;
  768. (function (CompletionItemKind) {
  769. CompletionItemKind.Text = 1;
  770. CompletionItemKind.Method = 2;
  771. CompletionItemKind.Function = 3;
  772. CompletionItemKind.Constructor = 4;
  773. CompletionItemKind.Field = 5;
  774. CompletionItemKind.Variable = 6;
  775. CompletionItemKind.Class = 7;
  776. CompletionItemKind.Interface = 8;
  777. CompletionItemKind.Module = 9;
  778. CompletionItemKind.Property = 10;
  779. CompletionItemKind.Unit = 11;
  780. CompletionItemKind.Value = 12;
  781. CompletionItemKind.Enum = 13;
  782. CompletionItemKind.Keyword = 14;
  783. CompletionItemKind.Snippet = 15;
  784. CompletionItemKind.Color = 16;
  785. CompletionItemKind.File = 17;
  786. CompletionItemKind.Reference = 18;
  787. CompletionItemKind.Folder = 19;
  788. CompletionItemKind.EnumMember = 20;
  789. CompletionItemKind.Constant = 21;
  790. CompletionItemKind.Struct = 22;
  791. CompletionItemKind.Event = 23;
  792. CompletionItemKind.Operator = 24;
  793. CompletionItemKind.TypeParameter = 25;
  794. })(CompletionItemKind || (CompletionItemKind = {}));
  795. /**
  796. * Defines whether the insert text in a completion item should be interpreted as
  797. * plain text or a snippet.
  798. */
  799. export var InsertTextFormat;
  800. (function (InsertTextFormat) {
  801. /**
  802. * The primary text to be inserted is treated as a plain string.
  803. */
  804. InsertTextFormat.PlainText = 1;
  805. /**
  806. * The primary text to be inserted is treated as a snippet.
  807. *
  808. * A snippet can define tab stops and placeholders with `$1`, `$2`
  809. * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
  810. * the end of the snippet. Placeholders with equal identifiers are linked,
  811. * that is typing in one will update others too.
  812. *
  813. * See also: https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
  814. */
  815. InsertTextFormat.Snippet = 2;
  816. })(InsertTextFormat || (InsertTextFormat = {}));
  817. /**
  818. * Completion item tags are extra annotations that tweak the rendering of a completion
  819. * item.
  820. *
  821. * @since 3.15.0
  822. */
  823. export var CompletionItemTag;
  824. (function (CompletionItemTag) {
  825. /**
  826. * Render a completion as obsolete, usually using a strike-out.
  827. */
  828. CompletionItemTag.Deprecated = 1;
  829. })(CompletionItemTag || (CompletionItemTag = {}));
  830. /**
  831. * The CompletionItem namespace provides functions to deal with
  832. * completion items.
  833. */
  834. export var CompletionItem;
  835. (function (CompletionItem) {
  836. /**
  837. * Create a completion item and seed it with a label.
  838. * @param label The completion item's label
  839. */
  840. function create(label) {
  841. return { label: label };
  842. }
  843. CompletionItem.create = create;
  844. })(CompletionItem || (CompletionItem = {}));
  845. /**
  846. * The CompletionList namespace provides functions to deal with
  847. * completion lists.
  848. */
  849. export var CompletionList;
  850. (function (CompletionList) {
  851. /**
  852. * Creates a new completion list.
  853. *
  854. * @param items The completion items.
  855. * @param isIncomplete The list is not complete.
  856. */
  857. function create(items, isIncomplete) {
  858. return { items: items ? items : [], isIncomplete: !!isIncomplete };
  859. }
  860. CompletionList.create = create;
  861. })(CompletionList || (CompletionList = {}));
  862. export var MarkedString;
  863. (function (MarkedString) {
  864. /**
  865. * Creates a marked string from plain text.
  866. *
  867. * @param plainText The plain text.
  868. */
  869. function fromPlainText(plainText) {
  870. return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
  871. }
  872. MarkedString.fromPlainText = fromPlainText;
  873. /**
  874. * Checks whether the given value conforms to the [MarkedString](#MarkedString) type.
  875. */
  876. function is(value) {
  877. var candidate = value;
  878. return Is.string(candidate) || (Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value));
  879. }
  880. MarkedString.is = is;
  881. })(MarkedString || (MarkedString = {}));
  882. export var Hover;
  883. (function (Hover) {
  884. /**
  885. * Checks whether the given value conforms to the [Hover](#Hover) interface.
  886. */
  887. function is(value) {
  888. var candidate = value;
  889. return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) ||
  890. MarkedString.is(candidate.contents) ||
  891. Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
  892. }
  893. Hover.is = is;
  894. })(Hover || (Hover = {}));
  895. /**
  896. * The ParameterInformation namespace provides helper functions to work with
  897. * [ParameterInformation](#ParameterInformation) literals.
  898. */
  899. export var ParameterInformation;
  900. (function (ParameterInformation) {
  901. /**
  902. * Creates a new parameter information literal.
  903. *
  904. * @param label A label string.
  905. * @param documentation A doc string.
  906. */
  907. function create(label, documentation) {
  908. return documentation ? { label: label, documentation: documentation } : { label: label };
  909. }
  910. ParameterInformation.create = create;
  911. })(ParameterInformation || (ParameterInformation = {}));
  912. /**
  913. * The SignatureInformation namespace provides helper functions to work with
  914. * [SignatureInformation](#SignatureInformation) literals.
  915. */
  916. export var SignatureInformation;
  917. (function (SignatureInformation) {
  918. function create(label, documentation) {
  919. var parameters = [];
  920. for (var _i = 2; _i < arguments.length; _i++) {
  921. parameters[_i - 2] = arguments[_i];
  922. }
  923. var result = { label: label };
  924. if (Is.defined(documentation)) {
  925. result.documentation = documentation;
  926. }
  927. if (Is.defined(parameters)) {
  928. result.parameters = parameters;
  929. }
  930. else {
  931. result.parameters = [];
  932. }
  933. return result;
  934. }
  935. SignatureInformation.create = create;
  936. })(SignatureInformation || (SignatureInformation = {}));
  937. /**
  938. * A document highlight kind.
  939. */
  940. export var DocumentHighlightKind;
  941. (function (DocumentHighlightKind) {
  942. /**
  943. * A textual occurrence.
  944. */
  945. DocumentHighlightKind.Text = 1;
  946. /**
  947. * Read-access of a symbol, like reading a variable.
  948. */
  949. DocumentHighlightKind.Read = 2;
  950. /**
  951. * Write-access of a symbol, like writing to a variable.
  952. */
  953. DocumentHighlightKind.Write = 3;
  954. })(DocumentHighlightKind || (DocumentHighlightKind = {}));
  955. /**
  956. * DocumentHighlight namespace to provide helper functions to work with
  957. * [DocumentHighlight](#DocumentHighlight) literals.
  958. */
  959. export var DocumentHighlight;
  960. (function (DocumentHighlight) {
  961. /**
  962. * Create a DocumentHighlight object.
  963. * @param range The range the highlight applies to.
  964. */
  965. function create(range, kind) {
  966. var result = { range: range };
  967. if (Is.number(kind)) {
  968. result.kind = kind;
  969. }
  970. return result;
  971. }
  972. DocumentHighlight.create = create;
  973. })(DocumentHighlight || (DocumentHighlight = {}));
  974. /**
  975. * A symbol kind.
  976. */
  977. export var SymbolKind;
  978. (function (SymbolKind) {
  979. SymbolKind.File = 1;
  980. SymbolKind.Module = 2;
  981. SymbolKind.Namespace = 3;
  982. SymbolKind.Package = 4;
  983. SymbolKind.Class = 5;
  984. SymbolKind.Method = 6;
  985. SymbolKind.Property = 7;
  986. SymbolKind.Field = 8;
  987. SymbolKind.Constructor = 9;
  988. SymbolKind.Enum = 10;
  989. SymbolKind.Interface = 11;
  990. SymbolKind.Function = 12;
  991. SymbolKind.Variable = 13;
  992. SymbolKind.Constant = 14;
  993. SymbolKind.String = 15;
  994. SymbolKind.Number = 16;
  995. SymbolKind.Boolean = 17;
  996. SymbolKind.Array = 18;
  997. SymbolKind.Object = 19;
  998. SymbolKind.Key = 20;
  999. SymbolKind.Null = 21;
  1000. SymbolKind.EnumMember = 22;
  1001. SymbolKind.Struct = 23;
  1002. SymbolKind.Event = 24;
  1003. SymbolKind.Operator = 25;
  1004. SymbolKind.TypeParameter = 26;
  1005. })(SymbolKind || (SymbolKind = {}));
  1006. /**
  1007. * Symbol tags are extra annotations that tweak the rendering of a symbol.
  1008. * @since 3.15
  1009. */
  1010. export var SymbolTag;
  1011. (function (SymbolTag) {
  1012. /**
  1013. * Render a symbol as obsolete, usually using a strike-out.
  1014. */
  1015. SymbolTag.Deprecated = 1;
  1016. })(SymbolTag || (SymbolTag = {}));
  1017. export var SymbolInformation;
  1018. (function (SymbolInformation) {
  1019. /**
  1020. * Creates a new symbol information literal.
  1021. *
  1022. * @param name The name of the symbol.
  1023. * @param kind The kind of the symbol.
  1024. * @param range The range of the location of the symbol.
  1025. * @param uri The resource of the location of symbol, defaults to the current document.
  1026. * @param containerName The name of the symbol containing the symbol.
  1027. */
  1028. function create(name, kind, range, uri, containerName) {
  1029. var result = {
  1030. name: name,
  1031. kind: kind,
  1032. location: { uri: uri, range: range }
  1033. };
  1034. if (containerName) {
  1035. result.containerName = containerName;
  1036. }
  1037. return result;
  1038. }
  1039. SymbolInformation.create = create;
  1040. })(SymbolInformation || (SymbolInformation = {}));
  1041. export var DocumentSymbol;
  1042. (function (DocumentSymbol) {
  1043. /**
  1044. * Creates a new symbol information literal.
  1045. *
  1046. * @param name The name of the symbol.
  1047. * @param detail The detail of the symbol.
  1048. * @param kind The kind of the symbol.
  1049. * @param range The range of the symbol.
  1050. * @param selectionRange The selectionRange of the symbol.
  1051. * @param children Children of the symbol.
  1052. */
  1053. function create(name, detail, kind, range, selectionRange, children) {
  1054. var result = {
  1055. name: name,
  1056. detail: detail,
  1057. kind: kind,
  1058. range: range,
  1059. selectionRange: selectionRange
  1060. };
  1061. if (children !== void 0) {
  1062. result.children = children;
  1063. }
  1064. return result;
  1065. }
  1066. DocumentSymbol.create = create;
  1067. /**
  1068. * Checks whether the given literal conforms to the [DocumentSymbol](#DocumentSymbol) interface.
  1069. */
  1070. function is(value) {
  1071. var candidate = value;
  1072. return candidate &&
  1073. Is.string(candidate.name) && Is.number(candidate.kind) &&
  1074. Range.is(candidate.range) && Range.is(candidate.selectionRange) &&
  1075. (candidate.detail === void 0 || Is.string(candidate.detail)) &&
  1076. (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) &&
  1077. (candidate.children === void 0 || Array.isArray(candidate.children));
  1078. }
  1079. DocumentSymbol.is = is;
  1080. })(DocumentSymbol || (DocumentSymbol = {}));
  1081. /**
  1082. * A set of predefined code action kinds
  1083. */
  1084. export var CodeActionKind;
  1085. (function (CodeActionKind) {
  1086. /**
  1087. * Empty kind.
  1088. */
  1089. CodeActionKind.Empty = '';
  1090. /**
  1091. * Base kind for quickfix actions: 'quickfix'
  1092. */
  1093. CodeActionKind.QuickFix = 'quickfix';
  1094. /**
  1095. * Base kind for refactoring actions: 'refactor'
  1096. */
  1097. CodeActionKind.Refactor = 'refactor';
  1098. /**
  1099. * Base kind for refactoring extraction actions: 'refactor.extract'
  1100. *
  1101. * Example extract actions:
  1102. *
  1103. * - Extract method
  1104. * - Extract function
  1105. * - Extract variable
  1106. * - Extract interface from class
  1107. * - ...
  1108. */
  1109. CodeActionKind.RefactorExtract = 'refactor.extract';
  1110. /**
  1111. * Base kind for refactoring inline actions: 'refactor.inline'
  1112. *
  1113. * Example inline actions:
  1114. *
  1115. * - Inline function
  1116. * - Inline variable
  1117. * - Inline constant
  1118. * - ...
  1119. */
  1120. CodeActionKind.RefactorInline = 'refactor.inline';
  1121. /**
  1122. * Base kind for refactoring rewrite actions: 'refactor.rewrite'
  1123. *
  1124. * Example rewrite actions:
  1125. *
  1126. * - Convert JavaScript function to class
  1127. * - Add or remove parameter
  1128. * - Encapsulate field
  1129. * - Make method static
  1130. * - Move method to base class
  1131. * - ...
  1132. */
  1133. CodeActionKind.RefactorRewrite = 'refactor.rewrite';
  1134. /**
  1135. * Base kind for source actions: `source`
  1136. *
  1137. * Source code actions apply to the entire file.
  1138. */
  1139. CodeActionKind.Source = 'source';
  1140. /**
  1141. * Base kind for an organize imports source action: `source.organizeImports`
  1142. */
  1143. CodeActionKind.SourceOrganizeImports = 'source.organizeImports';
  1144. /**
  1145. * Base kind for auto-fix source actions: `source.fixAll`.
  1146. *
  1147. * Fix all actions automatically fix errors that have a clear fix that do not require user input.
  1148. * They should not suppress errors or perform unsafe fixes such as generating new types or classes.
  1149. *
  1150. * @since 3.15.0
  1151. */
  1152. CodeActionKind.SourceFixAll = 'source.fixAll';
  1153. })(CodeActionKind || (CodeActionKind = {}));
  1154. /**
  1155. * The CodeActionContext namespace provides helper functions to work with
  1156. * [CodeActionContext](#CodeActionContext) literals.
  1157. */
  1158. export var CodeActionContext;
  1159. (function (CodeActionContext) {
  1160. /**
  1161. * Creates a new CodeActionContext literal.
  1162. */
  1163. function create(diagnostics, only) {
  1164. var result = { diagnostics: diagnostics };
  1165. if (only !== void 0 && only !== null) {
  1166. result.only = only;
  1167. }
  1168. return result;
  1169. }
  1170. CodeActionContext.create = create;
  1171. /**
  1172. * Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface.
  1173. */
  1174. function is(value) {
  1175. var candidate = value;
  1176. return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
  1177. }
  1178. CodeActionContext.is = is;
  1179. })(CodeActionContext || (CodeActionContext = {}));
  1180. export var CodeAction;
  1181. (function (CodeAction) {
  1182. function create(title, commandOrEdit, kind) {
  1183. var result = { title: title };
  1184. if (Command.is(commandOrEdit)) {
  1185. result.command = commandOrEdit;
  1186. }
  1187. else {
  1188. result.edit = commandOrEdit;
  1189. }
  1190. if (kind !== void 0) {
  1191. result.kind = kind;
  1192. }
  1193. return result;
  1194. }
  1195. CodeAction.create = create;
  1196. function is(value) {
  1197. var candidate = value;
  1198. return candidate && Is.string(candidate.title) &&
  1199. (candidate.diagnostics === void 0 || Is.typedArray(candidate.diagnostics, Diagnostic.is)) &&
  1200. (candidate.kind === void 0 || Is.string(candidate.kind)) &&
  1201. (candidate.edit !== void 0 || candidate.command !== void 0) &&
  1202. (candidate.command === void 0 || Command.is(candidate.command)) &&
  1203. (candidate.isPreferred === void 0 || Is.boolean(candidate.isPreferred)) &&
  1204. (candidate.edit === void 0 || WorkspaceEdit.is(candidate.edit));
  1205. }
  1206. CodeAction.is = is;
  1207. })(CodeAction || (CodeAction = {}));
  1208. /**
  1209. * The CodeLens namespace provides helper functions to work with
  1210. * [CodeLens](#CodeLens) literals.
  1211. */
  1212. export var CodeLens;
  1213. (function (CodeLens) {
  1214. /**
  1215. * Creates a new CodeLens literal.
  1216. */
  1217. function create(range, data) {
  1218. var result = { range: range };
  1219. if (Is.defined(data)) {
  1220. result.data = data;
  1221. }
  1222. return result;
  1223. }
  1224. CodeLens.create = create;
  1225. /**
  1226. * Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface.
  1227. */
  1228. function is(value) {
  1229. var candidate = value;
  1230. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
  1231. }
  1232. CodeLens.is = is;
  1233. })(CodeLens || (CodeLens = {}));
  1234. /**
  1235. * The FormattingOptions namespace provides helper functions to work with
  1236. * [FormattingOptions](#FormattingOptions) literals.
  1237. */
  1238. export var FormattingOptions;
  1239. (function (FormattingOptions) {
  1240. /**
  1241. * Creates a new FormattingOptions literal.
  1242. */
  1243. function create(tabSize, insertSpaces) {
  1244. return { tabSize: tabSize, insertSpaces: insertSpaces };
  1245. }
  1246. FormattingOptions.create = create;
  1247. /**
  1248. * Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface.
  1249. */
  1250. function is(value) {
  1251. var candidate = value;
  1252. return Is.defined(candidate) && Is.number(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
  1253. }
  1254. FormattingOptions.is = is;
  1255. })(FormattingOptions || (FormattingOptions = {}));
  1256. /**
  1257. * The DocumentLink namespace provides helper functions to work with
  1258. * [DocumentLink](#DocumentLink) literals.
  1259. */
  1260. export var DocumentLink;
  1261. (function (DocumentLink) {
  1262. /**
  1263. * Creates a new DocumentLink literal.
  1264. */
  1265. function create(range, target, data) {
  1266. return { range: range, target: target, data: data };
  1267. }
  1268. DocumentLink.create = create;
  1269. /**
  1270. * Checks whether the given literal conforms to the [DocumentLink](#DocumentLink) interface.
  1271. */
  1272. function is(value) {
  1273. var candidate = value;
  1274. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
  1275. }
  1276. DocumentLink.is = is;
  1277. })(DocumentLink || (DocumentLink = {}));
  1278. /**
  1279. * The SelectionRange namespace provides helper function to work with
  1280. * SelectionRange literals.
  1281. */
  1282. export var SelectionRange;
  1283. (function (SelectionRange) {
  1284. /**
  1285. * Creates a new SelectionRange
  1286. * @param range the range.
  1287. * @param parent an optional parent.
  1288. */
  1289. function create(range, parent) {
  1290. return { range: range, parent: parent };
  1291. }
  1292. SelectionRange.create = create;
  1293. function is(value) {
  1294. var candidate = value;
  1295. return candidate !== undefined && Range.is(candidate.range) && (candidate.parent === undefined || SelectionRange.is(candidate.parent));
  1296. }
  1297. SelectionRange.is = is;
  1298. })(SelectionRange || (SelectionRange = {}));
  1299. export var EOL = ['\n', '\r\n', '\r'];
  1300. /**
  1301. * @deprecated Use the text document from the new vscode-languageserver-textdocument package.
  1302. */
  1303. export var TextDocument;
  1304. (function (TextDocument) {
  1305. /**
  1306. * Creates a new ITextDocument literal from the given uri and content.
  1307. * @param uri The document's uri.
  1308. * @param languageId The document's language Id.
  1309. * @param content The document's content.
  1310. */
  1311. function create(uri, languageId, version, content) {
  1312. return new FullTextDocument(uri, languageId, version, content);
  1313. }
  1314. TextDocument.create = create;
  1315. /**
  1316. * Checks whether the given literal conforms to the [ITextDocument](#ITextDocument) interface.
  1317. */
  1318. function is(value) {
  1319. var candidate = value;
  1320. return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.number(candidate.lineCount)
  1321. && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
  1322. }
  1323. TextDocument.is = is;
  1324. function applyEdits(document, edits) {
  1325. var text = document.getText();
  1326. var sortedEdits = mergeSort(edits, function (a, b) {
  1327. var diff = a.range.start.line - b.range.start.line;
  1328. if (diff === 0) {
  1329. return a.range.start.character - b.range.start.character;
  1330. }
  1331. return diff;
  1332. });
  1333. var lastModifiedOffset = text.length;
  1334. for (var i = sortedEdits.length - 1; i >= 0; i--) {
  1335. var e = sortedEdits[i];
  1336. var startOffset = document.offsetAt(e.range.start);
  1337. var endOffset = document.offsetAt(e.range.end);
  1338. if (endOffset <= lastModifiedOffset) {
  1339. text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
  1340. }
  1341. else {
  1342. throw new Error('Overlapping edit');
  1343. }
  1344. lastModifiedOffset = startOffset;
  1345. }
  1346. return text;
  1347. }
  1348. TextDocument.applyEdits = applyEdits;
  1349. function mergeSort(data, compare) {
  1350. if (data.length <= 1) {
  1351. // sorted
  1352. return data;
  1353. }
  1354. var p = (data.length / 2) | 0;
  1355. var left = data.slice(0, p);
  1356. var right = data.slice(p);
  1357. mergeSort(left, compare);
  1358. mergeSort(right, compare);
  1359. var leftIdx = 0;
  1360. var rightIdx = 0;
  1361. var i = 0;
  1362. while (leftIdx < left.length && rightIdx < right.length) {
  1363. var ret = compare(left[leftIdx], right[rightIdx]);
  1364. if (ret <= 0) {
  1365. // smaller_equal -> take left to preserve order
  1366. data[i++] = left[leftIdx++];
  1367. }
  1368. else {
  1369. // greater -> take right
  1370. data[i++] = right[rightIdx++];
  1371. }
  1372. }
  1373. while (leftIdx < left.length) {
  1374. data[i++] = left[leftIdx++];
  1375. }
  1376. while (rightIdx < right.length) {
  1377. data[i++] = right[rightIdx++];
  1378. }
  1379. return data;
  1380. }
  1381. })(TextDocument || (TextDocument = {}));
  1382. var FullTextDocument = /** @class */ (function () {
  1383. function FullTextDocument(uri, languageId, version, content) {
  1384. this._uri = uri;
  1385. this._languageId = languageId;
  1386. this._version = version;
  1387. this._content = content;
  1388. this._lineOffsets = undefined;
  1389. }
  1390. Object.defineProperty(FullTextDocument.prototype, "uri", {
  1391. get: function () {
  1392. return this._uri;
  1393. },
  1394. enumerable: true,
  1395. configurable: true
  1396. });
  1397. Object.defineProperty(FullTextDocument.prototype, "languageId", {
  1398. get: function () {
  1399. return this._languageId;
  1400. },
  1401. enumerable: true,
  1402. configurable: true
  1403. });
  1404. Object.defineProperty(FullTextDocument.prototype, "version", {
  1405. get: function () {
  1406. return this._version;
  1407. },
  1408. enumerable: true,
  1409. configurable: true
  1410. });
  1411. FullTextDocument.prototype.getText = function (range) {
  1412. if (range) {
  1413. var start = this.offsetAt(range.start);
  1414. var end = this.offsetAt(range.end);
  1415. return this._content.substring(start, end);
  1416. }
  1417. return this._content;
  1418. };
  1419. FullTextDocument.prototype.update = function (event, version) {
  1420. this._content = event.text;
  1421. this._version = version;
  1422. this._lineOffsets = undefined;
  1423. };
  1424. FullTextDocument.prototype.getLineOffsets = function () {
  1425. if (this._lineOffsets === undefined) {
  1426. var lineOffsets = [];
  1427. var text = this._content;
  1428. var isLineStart = true;
  1429. for (var i = 0; i < text.length; i++) {
  1430. if (isLineStart) {
  1431. lineOffsets.push(i);
  1432. isLineStart = false;
  1433. }
  1434. var ch = text.charAt(i);
  1435. isLineStart = (ch === '\r' || ch === '\n');
  1436. if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
  1437. i++;
  1438. }
  1439. }
  1440. if (isLineStart && text.length > 0) {
  1441. lineOffsets.push(text.length);
  1442. }
  1443. this._lineOffsets = lineOffsets;
  1444. }
  1445. return this._lineOffsets;
  1446. };
  1447. FullTextDocument.prototype.positionAt = function (offset) {
  1448. offset = Math.max(Math.min(offset, this._content.length), 0);
  1449. var lineOffsets = this.getLineOffsets();
  1450. var low = 0, high = lineOffsets.length;
  1451. if (high === 0) {
  1452. return Position.create(0, offset);
  1453. }
  1454. while (low < high) {
  1455. var mid = Math.floor((low + high) / 2);
  1456. if (lineOffsets[mid] > offset) {
  1457. high = mid;
  1458. }
  1459. else {
  1460. low = mid + 1;
  1461. }
  1462. }
  1463. // low is the least x for which the line offset is larger than the current offset
  1464. // or array.length if no line offset is larger than the current offset
  1465. var line = low - 1;
  1466. return Position.create(line, offset - lineOffsets[line]);
  1467. };
  1468. FullTextDocument.prototype.offsetAt = function (position) {
  1469. var lineOffsets = this.getLineOffsets();
  1470. if (position.line >= lineOffsets.length) {
  1471. return this._content.length;
  1472. }
  1473. else if (position.line < 0) {
  1474. return 0;
  1475. }
  1476. var lineOffset = lineOffsets[position.line];
  1477. var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length;
  1478. return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
  1479. };
  1480. Object.defineProperty(FullTextDocument.prototype, "lineCount", {
  1481. get: function () {
  1482. return this.getLineOffsets().length;
  1483. },
  1484. enumerable: true,
  1485. configurable: true
  1486. });
  1487. return FullTextDocument;
  1488. }());
  1489. var Is;
  1490. (function (Is) {
  1491. var toString = Object.prototype.toString;
  1492. function defined(value) {
  1493. return typeof value !== 'undefined';
  1494. }
  1495. Is.defined = defined;
  1496. function undefined(value) {
  1497. return typeof value === 'undefined';
  1498. }
  1499. Is.undefined = undefined;
  1500. function boolean(value) {
  1501. return value === true || value === false;
  1502. }
  1503. Is.boolean = boolean;
  1504. function string(value) {
  1505. return toString.call(value) === '[object String]';
  1506. }
  1507. Is.string = string;
  1508. function number(value) {
  1509. return toString.call(value) === '[object Number]';
  1510. }
  1511. Is.number = number;
  1512. function func(value) {
  1513. return toString.call(value) === '[object Function]';
  1514. }
  1515. Is.func = func;
  1516. function objectLiteral(value) {
  1517. // Strictly speaking class instances pass this check as well. Since the LSP
  1518. // doesn't use classes we ignore this for now. If we do we need to add something
  1519. // like this: `Object.getPrototypeOf(Object.getPrototypeOf(x)) === null`
  1520. return value !== null && typeof value === 'object';
  1521. }
  1522. Is.objectLiteral = objectLiteral;
  1523. function typedArray(value, check) {
  1524. return Array.isArray(value) && value.every(check);
  1525. }
  1526. Is.typedArray = typedArray;
  1527. })(Is || (Is = {}));