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.

1539 lines
61 KiB

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