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 * ------------------------------------------------------------------------------------------ */
8 integer.MIN_VALUE = -2147483648;
9 integer.MAX_VALUE = 2147483647;
10 })(integer || (integer = {}));
12 (function (uinteger) {
13 uinteger.MIN_VALUE = 0;
14 uinteger.MAX_VALUE = 2147483647;
15 })(uinteger || (uinteger = {}));
17 * The Position namespace provides helper functions to work with
18 * [Position](#Position) literals.
21 (function (Position) {
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.
27 function create(line, character) {
28 if (line === Number.MAX_VALUE) {
29 line = uinteger.MAX_VALUE;
31 if (character === Number.MAX_VALUE) {
32 character = uinteger.MAX_VALUE;
34 return { line: line, character: character };
36 Position.create = create;
38 * Checks whether the given literal conforms to the [Position](#Position) interface.
41 var candidate = value;
42 return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
45 })(Position || (Position = {}));
47 * The Range namespace provides helper functions to work with
48 * [Range](#Range) literals.
52 function create(one, two, three, four) {
53 if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
54 return { start: Position.create(one, two), end: Position.create(three, four) };
56 else if (Position.is(one) && Position.is(two)) {
57 return { start: one, end: two };
60 throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
63 Range.create = create;
65 * Checks whether the given literal conforms to the [Range](#Range) interface.
68 var candidate = value;
69 return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
72 })(Range || (Range = {}));
74 * The Location namespace provides helper functions to work with
75 * [Location](#Location) literals.
78 (function (Location) {
80 * Creates a Location literal.
81 * @param uri The location's uri.
82 * @param range The location's range.
84 function create(uri, range) {
85 return { uri: uri, range: range };
87 Location.create = create;
89 * Checks whether the given literal conforms to the [Location](#Location) interface.
92 var candidate = value;
93 return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
96 })(Location || (Location = {}));
98 * The LocationLink namespace provides helper functions to work with
99 * [LocationLink](#LocationLink) literals.
101 export var LocationLink;
102 (function (LocationLink) {
104 * Creates a LocationLink literal.
105 * @param targetUri The definition's uri.
106 * @param targetRange The full range of the definition.
107 * @param targetSelectionRange The span of the symbol definition at the target.
108 * @param originSelectionRange The span of the symbol being defined in the originating source file.
110 function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
111 return { targetUri: targetUri, targetRange: targetRange, targetSelectionRange: targetSelectionRange, originSelectionRange: originSelectionRange };
113 LocationLink.create = create;
115 * Checks whether the given literal conforms to the [LocationLink](#LocationLink) interface.
118 var candidate = value;
119 return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri)
120 && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange))
121 && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
123 LocationLink.is = is;
124 })(LocationLink || (LocationLink = {}));
126 * The Color namespace provides helper functions to work with
127 * [Color](#Color) literals.
132 * Creates a new Color literal.
134 function create(red, green, blue, alpha) {
142 Color.create = create;
144 * Checks whether the given literal conforms to the [Color](#Color) interface.
147 var candidate = value;
148 return Is.numberRange(candidate.red, 0, 1)
149 && Is.numberRange(candidate.green, 0, 1)
150 && Is.numberRange(candidate.blue, 0, 1)
151 && Is.numberRange(candidate.alpha, 0, 1);
154 })(Color || (Color = {}));
156 * The ColorInformation namespace provides helper functions to work with
157 * [ColorInformation](#ColorInformation) literals.
159 export var ColorInformation;
160 (function (ColorInformation) {
162 * Creates a new ColorInformation literal.
164 function create(range, color) {
170 ColorInformation.create = create;
172 * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
175 var candidate = value;
176 return Range.is(candidate.range) && Color.is(candidate.color);
178 ColorInformation.is = is;
179 })(ColorInformation || (ColorInformation = {}));
181 * The Color namespace provides helper functions to work with
182 * [ColorPresentation](#ColorPresentation) literals.
184 export var ColorPresentation;
185 (function (ColorPresentation) {
187 * Creates a new ColorInformation literal.
189 function create(label, textEdit, additionalTextEdits) {
193 additionalTextEdits: additionalTextEdits,
196 ColorPresentation.create = create;
198 * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
201 var candidate = value;
202 return Is.string(candidate.label)
203 && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
204 && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
206 ColorPresentation.is = is;
207 })(ColorPresentation || (ColorPresentation = {}));
209 * Enum of known range kinds
211 export var FoldingRangeKind;
212 (function (FoldingRangeKind) {
214 * Folding range for a comment
216 FoldingRangeKind["Comment"] = "comment";
218 * Folding range for a imports or includes
220 FoldingRangeKind["Imports"] = "imports";
222 * Folding range for a region (e.g. `#region`)
224 FoldingRangeKind["Region"] = "region";
225 })(FoldingRangeKind || (FoldingRangeKind = {}));
227 * The folding range namespace provides helper functions to work with
228 * [FoldingRange](#FoldingRange) literals.
230 export var FoldingRange;
231 (function (FoldingRange) {
233 * Creates a new FoldingRange literal.
235 function create(startLine, endLine, startCharacter, endCharacter, kind) {
237 startLine: startLine,
240 if (Is.defined(startCharacter)) {
241 result.startCharacter = startCharacter;
243 if (Is.defined(endCharacter)) {
244 result.endCharacter = endCharacter;
246 if (Is.defined(kind)) {
251 FoldingRange.create = create;
253 * Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
256 var candidate = value;
257 return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine)
258 && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter))
259 && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter))
260 && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
262 FoldingRange.is = is;
263 })(FoldingRange || (FoldingRange = {}));
265 * The DiagnosticRelatedInformation namespace provides helper functions to work with
266 * [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
268 export var DiagnosticRelatedInformation;
269 (function (DiagnosticRelatedInformation) {
271 * Creates a new DiagnosticRelatedInformation literal.
273 function create(location, message) {
279 DiagnosticRelatedInformation.create = create;
281 * Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
284 var candidate = value;
285 return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
287 DiagnosticRelatedInformation.is = is;
288 })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
290 * The diagnostic's severity.
292 export var DiagnosticSeverity;
293 (function (DiagnosticSeverity) {
297 DiagnosticSeverity.Error = 1;
301 DiagnosticSeverity.Warning = 2;
303 * Reports an information.
305 DiagnosticSeverity.Information = 3;
309 DiagnosticSeverity.Hint = 4;
310 })(DiagnosticSeverity || (DiagnosticSeverity = {}));
312 * The diagnostic tags.
316 export var DiagnosticTag;
317 (function (DiagnosticTag) {
319 * Unused or unnecessary code.
321 * Clients are allowed to render diagnostics with this tag faded out instead of having
324 DiagnosticTag.Unnecessary = 1;
326 * Deprecated or obsolete code.
328 * Clients are allowed to rendered diagnostics with this tag strike through.
330 DiagnosticTag.Deprecated = 2;
331 })(DiagnosticTag || (DiagnosticTag = {}));
333 * The CodeDescription namespace provides functions to deal with descriptions for diagnostic codes.
337 export var CodeDescription;
338 (function (CodeDescription) {
340 var candidate = value;
341 return candidate !== undefined && candidate !== null && Is.string(candidate.href);
343 CodeDescription.is = is;
344 })(CodeDescription || (CodeDescription = {}));
346 * The Diagnostic namespace provides helper functions to work with
347 * [Diagnostic](#Diagnostic) literals.
349 export var Diagnostic;
350 (function (Diagnostic) {
352 * Creates a new Diagnostic literal.
354 function create(range, message, severity, code, source, relatedInformation) {
355 var result = { range: range, message: message };
356 if (Is.defined(severity)) {
357 result.severity = severity;
359 if (Is.defined(code)) {
362 if (Is.defined(source)) {
363 result.source = source;
365 if (Is.defined(relatedInformation)) {
366 result.relatedInformation = relatedInformation;
370 Diagnostic.create = create;
372 * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
376 var candidate = value;
377 return Is.defined(candidate)
378 && Range.is(candidate.range)
379 && Is.string(candidate.message)
380 && (Is.number(candidate.severity) || Is.undefined(candidate.severity))
381 && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
382 && (Is.undefined(candidate.codeDescription) || (Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)))
383 && (Is.string(candidate.source) || Is.undefined(candidate.source))
384 && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
387 })(Diagnostic || (Diagnostic = {}));
389 * The Command namespace provides helper functions to work with
390 * [Command](#Command) literals.
393 (function (Command) {
395 * Creates a new Command literal.
397 function create(title, command) {
399 for (var _i = 2; _i < arguments.length; _i++) {
400 args[_i - 2] = arguments[_i];
402 var result = { title: title, command: command };
403 if (Is.defined(args) && args.length > 0) {
404 result.arguments = args;
408 Command.create = create;
410 * Checks whether the given literal conforms to the [Command](#Command) interface.
413 var candidate = value;
414 return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
417 })(Command || (Command = {}));
419 * The TextEdit namespace provides helper function to create replace,
420 * insert and delete edits more easily.
423 (function (TextEdit) {
425 * Creates a replace text edit.
426 * @param range The range of text to be replaced.
427 * @param newText The new text.
429 function replace(range, newText) {
430 return { range: range, newText: newText };
432 TextEdit.replace = replace;
434 * Creates a insert text edit.
435 * @param position The position to insert the text at.
436 * @param newText The text to be inserted.
438 function insert(position, newText) {
439 return { range: { start: position, end: position }, newText: newText };
441 TextEdit.insert = insert;
443 * Creates a delete text edit.
444 * @param range The range of text to be deleted.
446 function del(range) {
447 return { range: range, newText: '' };
451 var candidate = value;
452 return Is.objectLiteral(candidate)
453 && Is.string(candidate.newText)
454 && Range.is(candidate.range);
457 })(TextEdit || (TextEdit = {}));
458 export var ChangeAnnotation;
459 (function (ChangeAnnotation) {
460 function create(label, needsConfirmation, description) {
461 var result = { label: label };
462 if (needsConfirmation !== undefined) {
463 result.needsConfirmation = needsConfirmation;
465 if (description !== undefined) {
466 result.description = description;
470 ChangeAnnotation.create = create;
472 var candidate = value;
473 return candidate !== undefined && Is.objectLiteral(candidate) && Is.string(candidate.label) &&
474 (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === undefined) &&
475 (Is.string(candidate.description) || candidate.description === undefined);
477 ChangeAnnotation.is = is;
478 })(ChangeAnnotation || (ChangeAnnotation = {}));
479 export var ChangeAnnotationIdentifier;
480 (function (ChangeAnnotationIdentifier) {
482 var candidate = value;
483 return typeof candidate === 'string';
485 ChangeAnnotationIdentifier.is = is;
486 })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
487 export var AnnotatedTextEdit;
488 (function (AnnotatedTextEdit) {
490 * Creates an annotated replace text edit.
492 * @param range The range of text to be replaced.
493 * @param newText The new text.
494 * @param annotation The annotation.
496 function replace(range, newText, annotation) {
497 return { range: range, newText: newText, annotationId: annotation };
499 AnnotatedTextEdit.replace = replace;
501 * Creates an annotated insert text edit.
503 * @param position The position to insert the text at.
504 * @param newText The text to be inserted.
505 * @param annotation The annotation.
507 function insert(position, newText, annotation) {
508 return { range: { start: position, end: position }, newText: newText, annotationId: annotation };
510 AnnotatedTextEdit.insert = insert;
512 * Creates an annotated delete text edit.
514 * @param range The range of text to be deleted.
515 * @param annotation The annotation.
517 function del(range, annotation) {
518 return { range: range, newText: '', annotationId: annotation };
520 AnnotatedTextEdit.del = del;
522 var candidate = value;
523 return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
525 AnnotatedTextEdit.is = is;
526 })(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
528 * The TextDocumentEdit namespace provides helper function to create
529 * an edit that manipulates a text document.
531 export var TextDocumentEdit;
532 (function (TextDocumentEdit) {
534 * Creates a new `TextDocumentEdit`
536 function create(textDocument, edits) {
537 return { textDocument: textDocument, edits: edits };
539 TextDocumentEdit.create = create;
541 var candidate = value;
542 return Is.defined(candidate)
543 && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument)
544 && Array.isArray(candidate.edits);
546 TextDocumentEdit.is = is;
547 })(TextDocumentEdit || (TextDocumentEdit = {}));
548 export var CreateFile;
549 (function (CreateFile) {
550 function create(uri, options, annotation) {
555 if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
556 result.options = options;
558 if (annotation !== undefined) {
559 result.annotationId = annotation;
563 CreateFile.create = create;
565 var candidate = value;
566 return candidate && candidate.kind === 'create' && Is.string(candidate.uri) && (candidate.options === undefined ||
567 ((candidate.options.overwrite === undefined || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === undefined || Is.boolean(candidate.options.ignoreIfExists)))) && (candidate.annotationId === undefined || ChangeAnnotationIdentifier.is(candidate.annotationId));
570 })(CreateFile || (CreateFile = {}));
571 export var RenameFile;
572 (function (RenameFile) {
573 function create(oldUri, newUri, options, annotation) {
579 if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
580 result.options = options;
582 if (annotation !== undefined) {
583 result.annotationId = annotation;
587 RenameFile.create = create;
589 var candidate = value;
590 return candidate && candidate.kind === 'rename' && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === undefined ||
591 ((candidate.options.overwrite === undefined || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === undefined || Is.boolean(candidate.options.ignoreIfExists)))) && (candidate.annotationId === undefined || ChangeAnnotationIdentifier.is(candidate.annotationId));
594 })(RenameFile || (RenameFile = {}));
595 export var DeleteFile;
596 (function (DeleteFile) {
597 function create(uri, options, annotation) {
602 if (options !== undefined && (options.recursive !== undefined || options.ignoreIfNotExists !== undefined)) {
603 result.options = options;
605 if (annotation !== undefined) {
606 result.annotationId = annotation;
610 DeleteFile.create = create;
612 var candidate = value;
613 return candidate && candidate.kind === 'delete' && Is.string(candidate.uri) && (candidate.options === undefined ||
614 ((candidate.options.recursive === undefined || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === undefined || Is.boolean(candidate.options.ignoreIfNotExists)))) && (candidate.annotationId === undefined || ChangeAnnotationIdentifier.is(candidate.annotationId));
617 })(DeleteFile || (DeleteFile = {}));
618 export var WorkspaceEdit;
619 (function (WorkspaceEdit) {
621 var candidate = value;
623 (candidate.changes !== undefined || candidate.documentChanges !== undefined) &&
624 (candidate.documentChanges === undefined || candidate.documentChanges.every(function (change) {
625 if (Is.string(change.kind)) {
626 return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
629 return TextDocumentEdit.is(change);
633 WorkspaceEdit.is = is;
634 })(WorkspaceEdit || (WorkspaceEdit = {}));
635 var TextEditChangeImpl = /** @class */ (function () {
636 function TextEditChangeImpl(edits, changeAnnotations) {
638 this.changeAnnotations = changeAnnotations;
640 TextEditChangeImpl.prototype.insert = function (position, newText, annotation) {
643 if (annotation === undefined) {
644 edit = TextEdit.insert(position, newText);
646 else if (ChangeAnnotationIdentifier.is(annotation)) {
648 edit = AnnotatedTextEdit.insert(position, newText, annotation);
651 this.assertChangeAnnotations(this.changeAnnotations);
652 id = this.changeAnnotations.manage(annotation);
653 edit = AnnotatedTextEdit.insert(position, newText, id);
655 this.edits.push(edit);
656 if (id !== undefined) {
660 TextEditChangeImpl.prototype.replace = function (range, newText, annotation) {
663 if (annotation === undefined) {
664 edit = TextEdit.replace(range, newText);
666 else if (ChangeAnnotationIdentifier.is(annotation)) {
668 edit = AnnotatedTextEdit.replace(range, newText, annotation);
671 this.assertChangeAnnotations(this.changeAnnotations);
672 id = this.changeAnnotations.manage(annotation);
673 edit = AnnotatedTextEdit.replace(range, newText, id);
675 this.edits.push(edit);
676 if (id !== undefined) {
680 TextEditChangeImpl.prototype.delete = function (range, annotation) {
683 if (annotation === undefined) {
684 edit = TextEdit.del(range);
686 else if (ChangeAnnotationIdentifier.is(annotation)) {
688 edit = AnnotatedTextEdit.del(range, annotation);
691 this.assertChangeAnnotations(this.changeAnnotations);
692 id = this.changeAnnotations.manage(annotation);
693 edit = AnnotatedTextEdit.del(range, id);
695 this.edits.push(edit);
696 if (id !== undefined) {
700 TextEditChangeImpl.prototype.add = function (edit) {
701 this.edits.push(edit);
703 TextEditChangeImpl.prototype.all = function () {
706 TextEditChangeImpl.prototype.clear = function () {
707 this.edits.splice(0, this.edits.length);
709 TextEditChangeImpl.prototype.assertChangeAnnotations = function (value) {
710 if (value === undefined) {
711 throw new Error("Text edit change is not configured to manage change annotations.");
714 return TextEditChangeImpl;
719 var ChangeAnnotations = /** @class */ (function () {
720 function ChangeAnnotations(annotations) {
721 this._annotations = annotations === undefined ? Object.create(null) : annotations;
725 ChangeAnnotations.prototype.all = function () {
726 return this._annotations;
728 Object.defineProperty(ChangeAnnotations.prototype, "size", {
735 ChangeAnnotations.prototype.manage = function (idOrAnnotation, annotation) {
737 if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
742 annotation = idOrAnnotation;
744 if (this._annotations[id] !== undefined) {
745 throw new Error("Id " + id + " is already in use.");
747 if (annotation === undefined) {
748 throw new Error("No annotation provided for id " + id);
750 this._annotations[id] = annotation;
754 ChangeAnnotations.prototype.nextId = function () {
756 return this._counter.toString();
758 return ChangeAnnotations;
761 * A workspace change helps constructing changes to a workspace.
763 var WorkspaceChange = /** @class */ (function () {
764 function WorkspaceChange(workspaceEdit) {
766 this._textEditChanges = Object.create(null);
767 if (workspaceEdit !== undefined) {
768 this._workspaceEdit = workspaceEdit;
769 if (workspaceEdit.documentChanges) {
770 this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
771 workspaceEdit.changeAnnotations = this._changeAnnotations.all();
772 workspaceEdit.documentChanges.forEach(function (change) {
773 if (TextDocumentEdit.is(change)) {
774 var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
775 _this._textEditChanges[change.textDocument.uri] = textEditChange;
779 else if (workspaceEdit.changes) {
780 Object.keys(workspaceEdit.changes).forEach(function (key) {
781 var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
782 _this._textEditChanges[key] = textEditChange;
787 this._workspaceEdit = {};
790 Object.defineProperty(WorkspaceChange.prototype, "edit", {
792 * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
793 * use to be returned from a workspace edit operation like rename.
796 this.initDocumentChanges();
797 if (this._changeAnnotations !== undefined) {
798 if (this._changeAnnotations.size === 0) {
799 this._workspaceEdit.changeAnnotations = undefined;
802 this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
805 return this._workspaceEdit;
810 WorkspaceChange.prototype.getTextEditChange = function (key) {
811 if (OptionalVersionedTextDocumentIdentifier.is(key)) {
812 this.initDocumentChanges();
813 if (this._workspaceEdit.documentChanges === undefined) {
814 throw new Error('Workspace edit is not configured for document changes.');
816 var textDocument = { uri: key.uri, version: key.version };
817 var result = this._textEditChanges[textDocument.uri];
820 var textDocumentEdit = {
821 textDocument: textDocument,
824 this._workspaceEdit.documentChanges.push(textDocumentEdit);
825 result = new TextEditChangeImpl(edits, this._changeAnnotations);
826 this._textEditChanges[textDocument.uri] = result;
832 if (this._workspaceEdit.changes === undefined) {
833 throw new Error('Workspace edit is not configured for normal text edit changes.');
835 var result = this._textEditChanges[key];
838 this._workspaceEdit.changes[key] = edits;
839 result = new TextEditChangeImpl(edits);
840 this._textEditChanges[key] = result;
845 WorkspaceChange.prototype.initDocumentChanges = function () {
846 if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
847 this._changeAnnotations = new ChangeAnnotations();
848 this._workspaceEdit.documentChanges = [];
849 this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
852 WorkspaceChange.prototype.initChanges = function () {
853 if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
854 this._workspaceEdit.changes = Object.create(null);
857 WorkspaceChange.prototype.createFile = function (uri, optionsOrAnnotation, options) {
858 this.initDocumentChanges();
859 if (this._workspaceEdit.documentChanges === undefined) {
860 throw new Error('Workspace edit is not configured for document changes.');
863 if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
864 annotation = optionsOrAnnotation;
867 options = optionsOrAnnotation;
871 if (annotation === undefined) {
872 operation = CreateFile.create(uri, options);
875 id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
876 operation = CreateFile.create(uri, options, id);
878 this._workspaceEdit.documentChanges.push(operation);
879 if (id !== undefined) {
883 WorkspaceChange.prototype.renameFile = function (oldUri, newUri, optionsOrAnnotation, options) {
884 this.initDocumentChanges();
885 if (this._workspaceEdit.documentChanges === undefined) {
886 throw new Error('Workspace edit is not configured for document changes.');
889 if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
890 annotation = optionsOrAnnotation;
893 options = optionsOrAnnotation;
897 if (annotation === undefined) {
898 operation = RenameFile.create(oldUri, newUri, options);
901 id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
902 operation = RenameFile.create(oldUri, newUri, options, id);
904 this._workspaceEdit.documentChanges.push(operation);
905 if (id !== undefined) {
909 WorkspaceChange.prototype.deleteFile = function (uri, optionsOrAnnotation, options) {
910 this.initDocumentChanges();
911 if (this._workspaceEdit.documentChanges === undefined) {
912 throw new Error('Workspace edit is not configured for document changes.');
915 if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
916 annotation = optionsOrAnnotation;
919 options = optionsOrAnnotation;
923 if (annotation === undefined) {
924 operation = DeleteFile.create(uri, options);
927 id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
928 operation = DeleteFile.create(uri, options, id);
930 this._workspaceEdit.documentChanges.push(operation);
931 if (id !== undefined) {
935 return WorkspaceChange;
937 export { WorkspaceChange };
939 * The TextDocumentIdentifier namespace provides helper functions to work with
940 * [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
942 export var TextDocumentIdentifier;
943 (function (TextDocumentIdentifier) {
945 * Creates a new TextDocumentIdentifier literal.
946 * @param uri The document's uri.
948 function create(uri) {
951 TextDocumentIdentifier.create = create;
953 * Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
956 var candidate = value;
957 return Is.defined(candidate) && Is.string(candidate.uri);
959 TextDocumentIdentifier.is = is;
960 })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
962 * The VersionedTextDocumentIdentifier namespace provides helper functions to work with
963 * [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
965 export var VersionedTextDocumentIdentifier;
966 (function (VersionedTextDocumentIdentifier) {
968 * Creates a new VersionedTextDocumentIdentifier literal.
969 * @param uri The document's uri.
970 * @param uri The document's text.
972 function create(uri, version) {
973 return { uri: uri, version: version };
975 VersionedTextDocumentIdentifier.create = create;
977 * Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
980 var candidate = value;
981 return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
983 VersionedTextDocumentIdentifier.is = is;
984 })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
986 * The OptionalVersionedTextDocumentIdentifier namespace provides helper functions to work with
987 * [OptionalVersionedTextDocumentIdentifier](#OptionalVersionedTextDocumentIdentifier) literals.
989 export var OptionalVersionedTextDocumentIdentifier;
990 (function (OptionalVersionedTextDocumentIdentifier) {
992 * Creates a new OptionalVersionedTextDocumentIdentifier literal.
993 * @param uri The document's uri.
994 * @param uri The document's text.
996 function create(uri, version) {
997 return { uri: uri, version: version };
999 OptionalVersionedTextDocumentIdentifier.create = create;
1001 * Checks whether the given literal conforms to the [OptionalVersionedTextDocumentIdentifier](#OptionalVersionedTextDocumentIdentifier) interface.
1003 function is(value) {
1004 var candidate = value;
1005 return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
1007 OptionalVersionedTextDocumentIdentifier.is = is;
1008 })(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
1010 * The TextDocumentItem namespace provides helper functions to work with
1011 * [TextDocumentItem](#TextDocumentItem) literals.
1013 export var TextDocumentItem;
1014 (function (TextDocumentItem) {
1016 * Creates a new TextDocumentItem literal.
1017 * @param uri The document's uri.
1018 * @param languageId The document's language identifier.
1019 * @param version The document's version number.
1020 * @param text The document's text.
1022 function create(uri, languageId, version, text) {
1023 return { uri: uri, languageId: languageId, version: version, text: text };
1025 TextDocumentItem.create = create;
1027 * Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
1029 function is(value) {
1030 var candidate = value;
1031 return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
1033 TextDocumentItem.is = is;
1034 })(TextDocumentItem || (TextDocumentItem = {}));
1036 * Describes the content type that a client supports in various
1037 * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
1039 * Please note that `MarkupKinds` must not start with a `$`. This kinds
1040 * are reserved for internal usage.
1042 export var MarkupKind;
1043 (function (MarkupKind) {
1045 * Plain text is supported as a content format
1047 MarkupKind.PlainText = 'plaintext';
1049 * Markdown is supported as a content format
1051 MarkupKind.Markdown = 'markdown';
1052 })(MarkupKind || (MarkupKind = {}));
1053 (function (MarkupKind) {
1055 * Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
1057 function is(value) {
1058 var candidate = value;
1059 return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
1062 })(MarkupKind || (MarkupKind = {}));
1063 export var MarkupContent;
1064 (function (MarkupContent) {
1066 * Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
1068 function is(value) {
1069 var candidate = value;
1070 return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
1072 MarkupContent.is = is;
1073 })(MarkupContent || (MarkupContent = {}));
1075 * The kind of a completion entry.
1077 export var CompletionItemKind;
1078 (function (CompletionItemKind) {
1079 CompletionItemKind.Text = 1;
1080 CompletionItemKind.Method = 2;
1081 CompletionItemKind.Function = 3;
1082 CompletionItemKind.Constructor = 4;
1083 CompletionItemKind.Field = 5;
1084 CompletionItemKind.Variable = 6;
1085 CompletionItemKind.Class = 7;
1086 CompletionItemKind.Interface = 8;
1087 CompletionItemKind.Module = 9;
1088 CompletionItemKind.Property = 10;
1089 CompletionItemKind.Unit = 11;
1090 CompletionItemKind.Value = 12;
1091 CompletionItemKind.Enum = 13;
1092 CompletionItemKind.Keyword = 14;
1093 CompletionItemKind.Snippet = 15;
1094 CompletionItemKind.Color = 16;
1095 CompletionItemKind.File = 17;
1096 CompletionItemKind.Reference = 18;
1097 CompletionItemKind.Folder = 19;
1098 CompletionItemKind.EnumMember = 20;
1099 CompletionItemKind.Constant = 21;
1100 CompletionItemKind.Struct = 22;
1101 CompletionItemKind.Event = 23;
1102 CompletionItemKind.Operator = 24;
1103 CompletionItemKind.TypeParameter = 25;
1104 })(CompletionItemKind || (CompletionItemKind = {}));
1106 * Defines whether the insert text in a completion item should be interpreted as
1107 * plain text or a snippet.
1109 export var InsertTextFormat;
1110 (function (InsertTextFormat) {
1112 * The primary text to be inserted is treated as a plain string.
1114 InsertTextFormat.PlainText = 1;
1116 * The primary text to be inserted is treated as a snippet.
1118 * A snippet can define tab stops and placeholders with `$1`, `$2`
1119 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
1120 * the end of the snippet. Placeholders with equal identifiers are linked,
1121 * that is typing in one will update others too.
1123 * See also: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#snippet_syntax
1125 InsertTextFormat.Snippet = 2;
1126 })(InsertTextFormat || (InsertTextFormat = {}));
1128 * Completion item tags are extra annotations that tweak the rendering of a completion
1133 export var CompletionItemTag;
1134 (function (CompletionItemTag) {
1136 * Render a completion as obsolete, usually using a strike-out.
1138 CompletionItemTag.Deprecated = 1;
1139 })(CompletionItemTag || (CompletionItemTag = {}));
1141 * The InsertReplaceEdit namespace provides functions to deal with insert / replace edits.
1145 export var InsertReplaceEdit;
1146 (function (InsertReplaceEdit) {
1148 * Creates a new insert / replace edit
1150 function create(newText, insert, replace) {
1151 return { newText: newText, insert: insert, replace: replace };
1153 InsertReplaceEdit.create = create;
1155 * Checks whether the given literal conforms to the [InsertReplaceEdit](#InsertReplaceEdit) interface.
1157 function is(value) {
1158 var candidate = value;
1159 return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
1161 InsertReplaceEdit.is = is;
1162 })(InsertReplaceEdit || (InsertReplaceEdit = {}));
1164 * How whitespace and indentation is handled during completion
1169 export var InsertTextMode;
1170 (function (InsertTextMode) {
1172 * The insertion or replace strings is taken as it is. If the
1173 * value is multi line the lines below the cursor will be
1174 * inserted using the indentation defined in the string value.
1175 * The client will not apply any kind of adjustments to the
1178 InsertTextMode.asIs = 1;
1180 * The editor adjusts leading whitespace of new lines so that
1181 * they match the indentation up to the cursor of the line for
1182 * which the item is accepted.
1184 * Consider a line like this: <2tabs><cursor><3tabs>foo. Accepting a
1185 * multi line completion item is indented using 2 tabs and all
1186 * following lines inserted will be indented using 2 tabs as well.
1188 InsertTextMode.adjustIndentation = 2;
1189 })(InsertTextMode || (InsertTextMode = {}));
1191 * The CompletionItem namespace provides functions to deal with
1194 export var CompletionItem;
1195 (function (CompletionItem) {
1197 * Create a completion item and seed it with a label.
1198 * @param label The completion item's label
1200 function create(label) {
1201 return { label: label };
1203 CompletionItem.create = create;
1204 })(CompletionItem || (CompletionItem = {}));
1206 * The CompletionList namespace provides functions to deal with
1209 export var CompletionList;
1210 (function (CompletionList) {
1212 * Creates a new completion list.
1214 * @param items The completion items.
1215 * @param isIncomplete The list is not complete.
1217 function create(items, isIncomplete) {
1218 return { items: items ? items : [], isIncomplete: !!isIncomplete };
1220 CompletionList.create = create;
1221 })(CompletionList || (CompletionList = {}));
1222 export var MarkedString;
1223 (function (MarkedString) {
1225 * Creates a marked string from plain text.
1227 * @param plainText The plain text.
1229 function fromPlainText(plainText) {
1230 return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
1232 MarkedString.fromPlainText = fromPlainText;
1234 * Checks whether the given value conforms to the [MarkedString](#MarkedString) type.
1236 function is(value) {
1237 var candidate = value;
1238 return Is.string(candidate) || (Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value));
1240 MarkedString.is = is;
1241 })(MarkedString || (MarkedString = {}));
1245 * Checks whether the given value conforms to the [Hover](#Hover) interface.
1247 function is(value) {
1248 var candidate = value;
1249 return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) ||
1250 MarkedString.is(candidate.contents) ||
1251 Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === undefined || Range.is(value.range));
1254 })(Hover || (Hover = {}));
1256 * The ParameterInformation namespace provides helper functions to work with
1257 * [ParameterInformation](#ParameterInformation) literals.
1259 export var ParameterInformation;
1260 (function (ParameterInformation) {
1262 * Creates a new parameter information literal.
1264 * @param label A label string.
1265 * @param documentation A doc string.
1267 function create(label, documentation) {
1268 return documentation ? { label: label, documentation: documentation } : { label: label };
1270 ParameterInformation.create = create;
1271 })(ParameterInformation || (ParameterInformation = {}));
1273 * The SignatureInformation namespace provides helper functions to work with
1274 * [SignatureInformation](#SignatureInformation) literals.
1276 export var SignatureInformation;
1277 (function (SignatureInformation) {
1278 function create(label, documentation) {
1279 var parameters = [];
1280 for (var _i = 2; _i < arguments.length; _i++) {
1281 parameters[_i - 2] = arguments[_i];
1283 var result = { label: label };
1284 if (Is.defined(documentation)) {
1285 result.documentation = documentation;
1287 if (Is.defined(parameters)) {
1288 result.parameters = parameters;
1291 result.parameters = [];
1295 SignatureInformation.create = create;
1296 })(SignatureInformation || (SignatureInformation = {}));
1298 * A document highlight kind.
1300 export var DocumentHighlightKind;
1301 (function (DocumentHighlightKind) {
1303 * A textual occurrence.
1305 DocumentHighlightKind.Text = 1;
1307 * Read-access of a symbol, like reading a variable.
1309 DocumentHighlightKind.Read = 2;
1311 * Write-access of a symbol, like writing to a variable.
1313 DocumentHighlightKind.Write = 3;
1314 })(DocumentHighlightKind || (DocumentHighlightKind = {}));
1316 * DocumentHighlight namespace to provide helper functions to work with
1317 * [DocumentHighlight](#DocumentHighlight) literals.
1319 export var DocumentHighlight;
1320 (function (DocumentHighlight) {
1322 * Create a DocumentHighlight object.
1323 * @param range The range the highlight applies to.
1325 function create(range, kind) {
1326 var result = { range: range };
1327 if (Is.number(kind)) {
1332 DocumentHighlight.create = create;
1333 })(DocumentHighlight || (DocumentHighlight = {}));
1337 export var SymbolKind;
1338 (function (SymbolKind) {
1339 SymbolKind.File = 1;
1340 SymbolKind.Module = 2;
1341 SymbolKind.Namespace = 3;
1342 SymbolKind.Package = 4;
1343 SymbolKind.Class = 5;
1344 SymbolKind.Method = 6;
1345 SymbolKind.Property = 7;
1346 SymbolKind.Field = 8;
1347 SymbolKind.Constructor = 9;
1348 SymbolKind.Enum = 10;
1349 SymbolKind.Interface = 11;
1350 SymbolKind.Function = 12;
1351 SymbolKind.Variable = 13;
1352 SymbolKind.Constant = 14;
1353 SymbolKind.String = 15;
1354 SymbolKind.Number = 16;
1355 SymbolKind.Boolean = 17;
1356 SymbolKind.Array = 18;
1357 SymbolKind.Object = 19;
1358 SymbolKind.Key = 20;
1359 SymbolKind.Null = 21;
1360 SymbolKind.EnumMember = 22;
1361 SymbolKind.Struct = 23;
1362 SymbolKind.Event = 24;
1363 SymbolKind.Operator = 25;
1364 SymbolKind.TypeParameter = 26;
1365 })(SymbolKind || (SymbolKind = {}));
1367 * Symbol tags are extra annotations that tweak the rendering of a symbol.
1370 export var SymbolTag;
1371 (function (SymbolTag) {
1373 * Render a symbol as obsolete, usually using a strike-out.
1375 SymbolTag.Deprecated = 1;
1376 })(SymbolTag || (SymbolTag = {}));
1377 export var SymbolInformation;
1378 (function (SymbolInformation) {
1380 * Creates a new symbol information literal.
1382 * @param name The name of the symbol.
1383 * @param kind The kind of the symbol.
1384 * @param range The range of the location of the symbol.
1385 * @param uri The resource of the location of symbol, defaults to the current document.
1386 * @param containerName The name of the symbol containing the symbol.
1388 function create(name, kind, range, uri, containerName) {
1392 location: { uri: uri, range: range }
1394 if (containerName) {
1395 result.containerName = containerName;
1399 SymbolInformation.create = create;
1400 })(SymbolInformation || (SymbolInformation = {}));
1401 export var DocumentSymbol;
1402 (function (DocumentSymbol) {
1404 * Creates a new symbol information literal.
1406 * @param name The name of the symbol.
1407 * @param detail The detail of the symbol.
1408 * @param kind The kind of the symbol.
1409 * @param range The range of the symbol.
1410 * @param selectionRange The selectionRange of the symbol.
1411 * @param children Children of the symbol.
1413 function create(name, detail, kind, range, selectionRange, children) {
1419 selectionRange: selectionRange
1421 if (children !== undefined) {
1422 result.children = children;
1426 DocumentSymbol.create = create;
1428 * Checks whether the given literal conforms to the [DocumentSymbol](#DocumentSymbol) interface.
1430 function is(value) {
1431 var candidate = value;
1433 Is.string(candidate.name) && Is.number(candidate.kind) &&
1434 Range.is(candidate.range) && Range.is(candidate.selectionRange) &&
1435 (candidate.detail === undefined || Is.string(candidate.detail)) &&
1436 (candidate.deprecated === undefined || Is.boolean(candidate.deprecated)) &&
1437 (candidate.children === undefined || Array.isArray(candidate.children)) &&
1438 (candidate.tags === undefined || Array.isArray(candidate.tags));
1440 DocumentSymbol.is = is;
1441 })(DocumentSymbol || (DocumentSymbol = {}));
1443 * A set of predefined code action kinds
1445 export var CodeActionKind;
1446 (function (CodeActionKind) {
1450 CodeActionKind.Empty = '';
1452 * Base kind for quickfix actions: 'quickfix'
1454 CodeActionKind.QuickFix = 'quickfix';
1456 * Base kind for refactoring actions: 'refactor'
1458 CodeActionKind.Refactor = 'refactor';
1460 * Base kind for refactoring extraction actions: 'refactor.extract'
1462 * Example extract actions:
1465 * - Extract function
1466 * - Extract variable
1467 * - Extract interface from class
1470 CodeActionKind.RefactorExtract = 'refactor.extract';
1472 * Base kind for refactoring inline actions: 'refactor.inline'
1474 * Example inline actions:
1481 CodeActionKind.RefactorInline = 'refactor.inline';
1483 * Base kind for refactoring rewrite actions: 'refactor.rewrite'
1485 * Example rewrite actions:
1487 * - Convert JavaScript function to class
1488 * - Add or remove parameter
1489 * - Encapsulate field
1490 * - Make method static
1491 * - Move method to base class
1494 CodeActionKind.RefactorRewrite = 'refactor.rewrite';
1496 * Base kind for source actions: `source`
1498 * Source code actions apply to the entire file.
1500 CodeActionKind.Source = 'source';
1502 * Base kind for an organize imports source action: `source.organizeImports`
1504 CodeActionKind.SourceOrganizeImports = 'source.organizeImports';
1506 * Base kind for auto-fix source actions: `source.fixAll`.
1508 * Fix all actions automatically fix errors that have a clear fix that do not require user input.
1509 * They should not suppress errors or perform unsafe fixes such as generating new types or classes.
1513 CodeActionKind.SourceFixAll = 'source.fixAll';
1514 })(CodeActionKind || (CodeActionKind = {}));
1516 * The CodeActionContext namespace provides helper functions to work with
1517 * [CodeActionContext](#CodeActionContext) literals.
1519 export var CodeActionContext;
1520 (function (CodeActionContext) {
1522 * Creates a new CodeActionContext literal.
1524 function create(diagnostics, only) {
1525 var result = { diagnostics: diagnostics };
1526 if (only !== undefined && only !== null) {
1531 CodeActionContext.create = create;
1533 * Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface.
1535 function is(value) {
1536 var candidate = value;
1537 return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === undefined || Is.typedArray(candidate.only, Is.string));
1539 CodeActionContext.is = is;
1540 })(CodeActionContext || (CodeActionContext = {}));
1541 export var CodeAction;
1542 (function (CodeAction) {
1543 function create(title, kindOrCommandOrEdit, kind) {
1544 var result = { title: title };
1545 var checkKind = true;
1546 if (typeof kindOrCommandOrEdit === 'string') {
1548 result.kind = kindOrCommandOrEdit;
1550 else if (Command.is(kindOrCommandOrEdit)) {
1551 result.command = kindOrCommandOrEdit;
1554 result.edit = kindOrCommandOrEdit;
1556 if (checkKind && kind !== undefined) {
1561 CodeAction.create = create;
1562 function is(value) {
1563 var candidate = value;
1564 return candidate && Is.string(candidate.title) &&
1565 (candidate.diagnostics === undefined || Is.typedArray(candidate.diagnostics, Diagnostic.is)) &&
1566 (candidate.kind === undefined || Is.string(candidate.kind)) &&
1567 (candidate.edit !== undefined || candidate.command !== undefined) &&
1568 (candidate.command === undefined || Command.is(candidate.command)) &&
1569 (candidate.isPreferred === undefined || Is.boolean(candidate.isPreferred)) &&
1570 (candidate.edit === undefined || WorkspaceEdit.is(candidate.edit));
1573 })(CodeAction || (CodeAction = {}));
1575 * The CodeLens namespace provides helper functions to work with
1576 * [CodeLens](#CodeLens) literals.
1578 export var CodeLens;
1579 (function (CodeLens) {
1581 * Creates a new CodeLens literal.
1583 function create(range, data) {
1584 var result = { range: range };
1585 if (Is.defined(data)) {
1590 CodeLens.create = create;
1592 * Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface.
1594 function is(value) {
1595 var candidate = value;
1596 return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
1599 })(CodeLens || (CodeLens = {}));
1601 * The FormattingOptions namespace provides helper functions to work with
1602 * [FormattingOptions](#FormattingOptions) literals.
1604 export var FormattingOptions;
1605 (function (FormattingOptions) {
1607 * Creates a new FormattingOptions literal.
1609 function create(tabSize, insertSpaces) {
1610 return { tabSize: tabSize, insertSpaces: insertSpaces };
1612 FormattingOptions.create = create;
1614 * Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface.
1616 function is(value) {
1617 var candidate = value;
1618 return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
1620 FormattingOptions.is = is;
1621 })(FormattingOptions || (FormattingOptions = {}));
1623 * The DocumentLink namespace provides helper functions to work with
1624 * [DocumentLink](#DocumentLink) literals.
1626 export var DocumentLink;
1627 (function (DocumentLink) {
1629 * Creates a new DocumentLink literal.
1631 function create(range, target, data) {
1632 return { range: range, target: target, data: data };
1634 DocumentLink.create = create;
1636 * Checks whether the given literal conforms to the [DocumentLink](#DocumentLink) interface.
1638 function is(value) {
1639 var candidate = value;
1640 return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
1642 DocumentLink.is = is;
1643 })(DocumentLink || (DocumentLink = {}));
1645 * The SelectionRange namespace provides helper function to work with
1646 * SelectionRange literals.
1648 export var SelectionRange;
1649 (function (SelectionRange) {
1651 * Creates a new SelectionRange
1652 * @param range the range.
1653 * @param parent an optional parent.
1655 function create(range, parent) {
1656 return { range: range, parent: parent };
1658 SelectionRange.create = create;
1659 function is(value) {
1660 var candidate = value;
1661 return candidate !== undefined && Range.is(candidate.range) && (candidate.parent === undefined || SelectionRange.is(candidate.parent));
1663 SelectionRange.is = is;
1664 })(SelectionRange || (SelectionRange = {}));
1665 export var EOL = ['\n', '\r\n', '\r'];
1667 * @deprecated Use the text document from the new vscode-languageserver-textdocument package.
1669 export var TextDocument;
1670 (function (TextDocument) {
1672 * Creates a new ITextDocument literal from the given uri and content.
1673 * @param uri The document's uri.
1674 * @param languageId The document's language Id.
1675 * @param content The document's content.
1677 function create(uri, languageId, version, content) {
1678 return new FullTextDocument(uri, languageId, version, content);
1680 TextDocument.create = create;
1682 * Checks whether the given literal conforms to the [ITextDocument](#ITextDocument) interface.
1684 function is(value) {
1685 var candidate = value;
1686 return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.uinteger(candidate.lineCount)
1687 && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
1689 TextDocument.is = is;
1690 function applyEdits(document, edits) {
1691 var text = document.getText();
1692 var sortedEdits = mergeSort(edits, function (a, b) {
1693 var diff = a.range.start.line - b.range.start.line;
1695 return a.range.start.character - b.range.start.character;
1699 var lastModifiedOffset = text.length;
1700 for (var i = sortedEdits.length - 1; i >= 0; i--) {
1701 var e = sortedEdits[i];
1702 var startOffset = document.offsetAt(e.range.start);
1703 var endOffset = document.offsetAt(e.range.end);
1704 if (endOffset <= lastModifiedOffset) {
1705 text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
1708 throw new Error('Overlapping edit');
1710 lastModifiedOffset = startOffset;
1714 TextDocument.applyEdits = applyEdits;
1715 function mergeSort(data, compare) {
1716 if (data.length <= 1) {
1720 var p = (data.length / 2) | 0;
1721 var left = data.slice(0, p);
1722 var right = data.slice(p);
1723 mergeSort(left, compare);
1724 mergeSort(right, compare);
1728 while (leftIdx < left.length && rightIdx < right.length) {
1729 var ret = compare(left[leftIdx], right[rightIdx]);
1731 // smaller_equal -> take left to preserve order
1732 data[i++] = left[leftIdx++];
1735 // greater -> take right
1736 data[i++] = right[rightIdx++];
1739 while (leftIdx < left.length) {
1740 data[i++] = left[leftIdx++];
1742 while (rightIdx < right.length) {
1743 data[i++] = right[rightIdx++];
1747 })(TextDocument || (TextDocument = {}));
1749 * @deprecated Use the text document from the new vscode-languageserver-textdocument package.
1751 var FullTextDocument = /** @class */ (function () {
1752 function FullTextDocument(uri, languageId, version, content) {
1754 this._languageId = languageId;
1755 this._version = version;
1756 this._content = content;
1757 this._lineOffsets = undefined;
1759 Object.defineProperty(FullTextDocument.prototype, "uri", {
1766 Object.defineProperty(FullTextDocument.prototype, "languageId", {
1768 return this._languageId;
1773 Object.defineProperty(FullTextDocument.prototype, "version", {
1775 return this._version;
1780 FullTextDocument.prototype.getText = function (range) {
1782 var start = this.offsetAt(range.start);
1783 var end = this.offsetAt(range.end);
1784 return this._content.substring(start, end);
1786 return this._content;
1788 FullTextDocument.prototype.update = function (event, version) {
1789 this._content = event.text;
1790 this._version = version;
1791 this._lineOffsets = undefined;
1793 FullTextDocument.prototype.getLineOffsets = function () {
1794 if (this._lineOffsets === undefined) {
1795 var lineOffsets = [];
1796 var text = this._content;
1797 var isLineStart = true;
1798 for (var i = 0; i < text.length; i++) {
1800 lineOffsets.push(i);
1801 isLineStart = false;
1803 var ch = text.charAt(i);
1804 isLineStart = (ch === '\r' || ch === '\n');
1805 if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
1809 if (isLineStart && text.length > 0) {
1810 lineOffsets.push(text.length);
1812 this._lineOffsets = lineOffsets;
1814 return this._lineOffsets;
1816 FullTextDocument.prototype.positionAt = function (offset) {
1817 offset = Math.max(Math.min(offset, this._content.length), 0);
1818 var lineOffsets = this.getLineOffsets();
1819 var low = 0, high = lineOffsets.length;
1821 return Position.create(0, offset);
1823 while (low < high) {
1824 var mid = Math.floor((low + high) / 2);
1825 if (lineOffsets[mid] > offset) {
1832 // low is the least x for which the line offset is larger than the current offset
1833 // or array.length if no line offset is larger than the current offset
1835 return Position.create(line, offset - lineOffsets[line]);
1837 FullTextDocument.prototype.offsetAt = function (position) {
1838 var lineOffsets = this.getLineOffsets();
1839 if (position.line >= lineOffsets.length) {
1840 return this._content.length;
1842 else if (position.line < 0) {
1845 var lineOffset = lineOffsets[position.line];
1846 var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length;
1847 return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
1849 Object.defineProperty(FullTextDocument.prototype, "lineCount", {
1851 return this.getLineOffsets().length;
1856 return FullTextDocument;
1860 var toString = Object.prototype.toString;
1861 function defined(value) {
1862 return typeof value !== 'undefined';
1864 Is.defined = defined;
1865 function undefined(value) {
1866 return typeof value === 'undefined';
1868 Is.undefined = undefined;
1869 function boolean(value) {
1870 return value === true || value === false;
1872 Is.boolean = boolean;
1873 function string(value) {
1874 return toString.call(value) === '[object String]';
1877 function number(value) {
1878 return toString.call(value) === '[object Number]';
1881 function numberRange(value, min, max) {
1882 return toString.call(value) === '[object Number]' && min <= value && value <= max;
1884 Is.numberRange = numberRange;
1885 function integer(value) {
1886 return toString.call(value) === '[object Number]' && -2147483648 <= value && value <= 2147483647;
1888 Is.integer = integer;
1889 function uinteger(value) {
1890 return toString.call(value) === '[object Number]' && 0 <= value && value <= 2147483647;
1892 Is.uinteger = uinteger;
1893 function func(value) {
1894 return toString.call(value) === '[object Function]';
1897 function objectLiteral(value) {
1898 // Strictly speaking class instances pass this check as well. Since the LSP
1899 // doesn't use classes we ignore this for now. If we do we need to add something
1900 // like this: `Object.getPrototypeOf(Object.getPrototypeOf(x)) === null`
1901 return value !== null && typeof value === 'object';
1903 Is.objectLiteral = objectLiteral;
1904 function typedArray(value, check) {
1905 return Array.isArray(value) && value.every(check);
1907 Is.typedArray = typedArray;
1908 })(Is || (Is = {}));