2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports"], factory);
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 * ------------------------------------------------------------------------------------------ */
15 Object.defineProperty(exports, "__esModule", { value: true });
16 exports.TextDocument = exports.EOL = exports.SelectionRange = exports.DocumentLink = exports.FormattingOptions = exports.CodeLens = exports.CodeAction = exports.CodeActionContext = exports.CodeActionKind = exports.DocumentSymbol = exports.SymbolInformation = exports.SymbolTag = exports.SymbolKind = exports.DocumentHighlight = exports.DocumentHighlightKind = exports.SignatureInformation = exports.ParameterInformation = exports.Hover = exports.MarkedString = exports.CompletionList = exports.CompletionItem = exports.InsertTextMode = exports.InsertReplaceEdit = exports.CompletionItemTag = exports.InsertTextFormat = exports.CompletionItemKind = exports.MarkupContent = exports.MarkupKind = exports.TextDocumentItem = exports.OptionalVersionedTextDocumentIdentifier = exports.VersionedTextDocumentIdentifier = exports.TextDocumentIdentifier = exports.WorkspaceChange = exports.WorkspaceEdit = exports.DeleteFile = exports.RenameFile = exports.CreateFile = exports.TextDocumentEdit = exports.AnnotatedTextEdit = exports.ChangeAnnotationIdentifier = exports.ChangeAnnotation = exports.TextEdit = exports.Command = exports.Diagnostic = exports.CodeDescription = exports.DiagnosticTag = exports.DiagnosticSeverity = exports.DiagnosticRelatedInformation = exports.FoldingRange = exports.FoldingRangeKind = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.LocationLink = exports.Location = exports.Range = exports.Position = exports.uinteger = exports.integer = void 0;
19 integer.MIN_VALUE = -2147483648;
20 integer.MAX_VALUE = 2147483647;
21 })(integer = exports.integer || (exports.integer = {}));
23 (function (uinteger) {
24 uinteger.MIN_VALUE = 0;
25 uinteger.MAX_VALUE = 2147483647;
26 })(uinteger = exports.uinteger || (exports.uinteger = {}));
28 * The Position namespace provides helper functions to work with
29 * [Position](#Position) literals.
32 (function (Position) {
34 * Creates a new Position literal from the given line and character.
35 * @param line The position's line.
36 * @param character The position's character.
38 function create(line, character) {
39 if (line === Number.MAX_VALUE) {
40 line = uinteger.MAX_VALUE;
42 if (character === Number.MAX_VALUE) {
43 character = uinteger.MAX_VALUE;
45 return { line: line, character: character };
47 Position.create = create;
49 * Checks whether the given literal conforms to the [Position](#Position) interface.
52 var candidate = value;
53 return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
56 })(Position = exports.Position || (exports.Position = {}));
58 * The Range namespace provides helper functions to work with
59 * [Range](#Range) literals.
63 function create(one, two, three, four) {
64 if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
65 return { start: Position.create(one, two), end: Position.create(three, four) };
67 else if (Position.is(one) && Position.is(two)) {
68 return { start: one, end: two };
71 throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
74 Range.create = create;
76 * Checks whether the given literal conforms to the [Range](#Range) interface.
79 var candidate = value;
80 return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
83 })(Range = exports.Range || (exports.Range = {}));
85 * The Location namespace provides helper functions to work with
86 * [Location](#Location) literals.
89 (function (Location) {
91 * Creates a Location literal.
92 * @param uri The location's uri.
93 * @param range The location's range.
95 function create(uri, range) {
96 return { uri: uri, range: range };
98 Location.create = create;
100 * Checks whether the given literal conforms to the [Location](#Location) interface.
103 var candidate = value;
104 return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
107 })(Location = exports.Location || (exports.Location = {}));
109 * The LocationLink namespace provides helper functions to work with
110 * [LocationLink](#LocationLink) literals.
113 (function (LocationLink) {
115 * Creates a LocationLink literal.
116 * @param targetUri The definition's uri.
117 * @param targetRange The full range of the definition.
118 * @param targetSelectionRange The span of the symbol definition at the target.
119 * @param originSelectionRange The span of the symbol being defined in the originating source file.
121 function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
122 return { targetUri: targetUri, targetRange: targetRange, targetSelectionRange: targetSelectionRange, originSelectionRange: originSelectionRange };
124 LocationLink.create = create;
126 * Checks whether the given literal conforms to the [LocationLink](#LocationLink) interface.
129 var candidate = value;
130 return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri)
131 && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange))
132 && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
134 LocationLink.is = is;
135 })(LocationLink = exports.LocationLink || (exports.LocationLink = {}));
137 * The Color namespace provides helper functions to work with
138 * [Color](#Color) literals.
143 * Creates a new Color literal.
145 function create(red, green, blue, alpha) {
153 Color.create = create;
155 * Checks whether the given literal conforms to the [Color](#Color) interface.
158 var candidate = value;
159 return Is.numberRange(candidate.red, 0, 1)
160 && Is.numberRange(candidate.green, 0, 1)
161 && Is.numberRange(candidate.blue, 0, 1)
162 && Is.numberRange(candidate.alpha, 0, 1);
165 })(Color = exports.Color || (exports.Color = {}));
167 * The ColorInformation namespace provides helper functions to work with
168 * [ColorInformation](#ColorInformation) literals.
170 var ColorInformation;
171 (function (ColorInformation) {
173 * Creates a new ColorInformation literal.
175 function create(range, color) {
181 ColorInformation.create = create;
183 * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
186 var candidate = value;
187 return Range.is(candidate.range) && Color.is(candidate.color);
189 ColorInformation.is = is;
190 })(ColorInformation = exports.ColorInformation || (exports.ColorInformation = {}));
192 * The Color namespace provides helper functions to work with
193 * [ColorPresentation](#ColorPresentation) literals.
195 var ColorPresentation;
196 (function (ColorPresentation) {
198 * Creates a new ColorInformation literal.
200 function create(label, textEdit, additionalTextEdits) {
204 additionalTextEdits: additionalTextEdits,
207 ColorPresentation.create = create;
209 * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
212 var candidate = value;
213 return Is.string(candidate.label)
214 && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
215 && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
217 ColorPresentation.is = is;
218 })(ColorPresentation = exports.ColorPresentation || (exports.ColorPresentation = {}));
220 * Enum of known range kinds
222 var FoldingRangeKind;
223 (function (FoldingRangeKind) {
225 * Folding range for a comment
227 FoldingRangeKind["Comment"] = "comment";
229 * Folding range for a imports or includes
231 FoldingRangeKind["Imports"] = "imports";
233 * Folding range for a region (e.g. `#region`)
235 FoldingRangeKind["Region"] = "region";
236 })(FoldingRangeKind = exports.FoldingRangeKind || (exports.FoldingRangeKind = {}));
238 * The folding range namespace provides helper functions to work with
239 * [FoldingRange](#FoldingRange) literals.
242 (function (FoldingRange) {
244 * Creates a new FoldingRange literal.
246 function create(startLine, endLine, startCharacter, endCharacter, kind) {
248 startLine: startLine,
251 if (Is.defined(startCharacter)) {
252 result.startCharacter = startCharacter;
254 if (Is.defined(endCharacter)) {
255 result.endCharacter = endCharacter;
257 if (Is.defined(kind)) {
262 FoldingRange.create = create;
264 * Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
267 var candidate = value;
268 return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine)
269 && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter))
270 && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter))
271 && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
273 FoldingRange.is = is;
274 })(FoldingRange = exports.FoldingRange || (exports.FoldingRange = {}));
276 * The DiagnosticRelatedInformation namespace provides helper functions to work with
277 * [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
279 var DiagnosticRelatedInformation;
280 (function (DiagnosticRelatedInformation) {
282 * Creates a new DiagnosticRelatedInformation literal.
284 function create(location, message) {
290 DiagnosticRelatedInformation.create = create;
292 * Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
295 var candidate = value;
296 return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
298 DiagnosticRelatedInformation.is = is;
299 })(DiagnosticRelatedInformation = exports.DiagnosticRelatedInformation || (exports.DiagnosticRelatedInformation = {}));
301 * The diagnostic's severity.
303 var DiagnosticSeverity;
304 (function (DiagnosticSeverity) {
308 DiagnosticSeverity.Error = 1;
312 DiagnosticSeverity.Warning = 2;
314 * Reports an information.
316 DiagnosticSeverity.Information = 3;
320 DiagnosticSeverity.Hint = 4;
321 })(DiagnosticSeverity = exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {}));
323 * The diagnostic tags.
328 (function (DiagnosticTag) {
330 * Unused or unnecessary code.
332 * Clients are allowed to render diagnostics with this tag faded out instead of having
335 DiagnosticTag.Unnecessary = 1;
337 * Deprecated or obsolete code.
339 * Clients are allowed to rendered diagnostics with this tag strike through.
341 DiagnosticTag.Deprecated = 2;
342 })(DiagnosticTag = exports.DiagnosticTag || (exports.DiagnosticTag = {}));
344 * The CodeDescription namespace provides functions to deal with descriptions for diagnostic codes.
349 (function (CodeDescription) {
351 var candidate = value;
352 return candidate !== undefined && candidate !== null && Is.string(candidate.href);
354 CodeDescription.is = is;
355 })(CodeDescription = exports.CodeDescription || (exports.CodeDescription = {}));
357 * The Diagnostic namespace provides helper functions to work with
358 * [Diagnostic](#Diagnostic) literals.
361 (function (Diagnostic) {
363 * Creates a new Diagnostic literal.
365 function create(range, message, severity, code, source, relatedInformation) {
366 var result = { range: range, message: message };
367 if (Is.defined(severity)) {
368 result.severity = severity;
370 if (Is.defined(code)) {
373 if (Is.defined(source)) {
374 result.source = source;
376 if (Is.defined(relatedInformation)) {
377 result.relatedInformation = relatedInformation;
381 Diagnostic.create = create;
383 * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
387 var candidate = value;
388 return Is.defined(candidate)
389 && Range.is(candidate.range)
390 && Is.string(candidate.message)
391 && (Is.number(candidate.severity) || Is.undefined(candidate.severity))
392 && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
393 && (Is.undefined(candidate.codeDescription) || (Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)))
394 && (Is.string(candidate.source) || Is.undefined(candidate.source))
395 && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
398 })(Diagnostic = exports.Diagnostic || (exports.Diagnostic = {}));
400 * The Command namespace provides helper functions to work with
401 * [Command](#Command) literals.
404 (function (Command) {
406 * Creates a new Command literal.
408 function create(title, command) {
410 for (var _i = 2; _i < arguments.length; _i++) {
411 args[_i - 2] = arguments[_i];
413 var result = { title: title, command: command };
414 if (Is.defined(args) && args.length > 0) {
415 result.arguments = args;
419 Command.create = create;
421 * Checks whether the given literal conforms to the [Command](#Command) interface.
424 var candidate = value;
425 return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
428 })(Command = exports.Command || (exports.Command = {}));
430 * The TextEdit namespace provides helper function to create replace,
431 * insert and delete edits more easily.
434 (function (TextEdit) {
436 * Creates a replace text edit.
437 * @param range The range of text to be replaced.
438 * @param newText The new text.
440 function replace(range, newText) {
441 return { range: range, newText: newText };
443 TextEdit.replace = replace;
445 * Creates a insert text edit.
446 * @param position The position to insert the text at.
447 * @param newText The text to be inserted.
449 function insert(position, newText) {
450 return { range: { start: position, end: position }, newText: newText };
452 TextEdit.insert = insert;
454 * Creates a delete text edit.
455 * @param range The range of text to be deleted.
457 function del(range) {
458 return { range: range, newText: '' };
462 var candidate = value;
463 return Is.objectLiteral(candidate)
464 && Is.string(candidate.newText)
465 && Range.is(candidate.range);
468 })(TextEdit = exports.TextEdit || (exports.TextEdit = {}));
469 var ChangeAnnotation;
470 (function (ChangeAnnotation) {
471 function create(label, needsConfirmation, description) {
472 var result = { label: label };
473 if (needsConfirmation !== undefined) {
474 result.needsConfirmation = needsConfirmation;
476 if (description !== undefined) {
477 result.description = description;
481 ChangeAnnotation.create = create;
483 var candidate = value;
484 return candidate !== undefined && Is.objectLiteral(candidate) && Is.string(candidate.label) &&
485 (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === undefined) &&
486 (Is.string(candidate.description) || candidate.description === undefined);
488 ChangeAnnotation.is = is;
489 })(ChangeAnnotation = exports.ChangeAnnotation || (exports.ChangeAnnotation = {}));
490 var ChangeAnnotationIdentifier;
491 (function (ChangeAnnotationIdentifier) {
493 var candidate = value;
494 return typeof candidate === 'string';
496 ChangeAnnotationIdentifier.is = is;
497 })(ChangeAnnotationIdentifier = exports.ChangeAnnotationIdentifier || (exports.ChangeAnnotationIdentifier = {}));
498 var AnnotatedTextEdit;
499 (function (AnnotatedTextEdit) {
501 * Creates an annotated replace text edit.
503 * @param range The range of text to be replaced.
504 * @param newText The new text.
505 * @param annotation The annotation.
507 function replace(range, newText, annotation) {
508 return { range: range, newText: newText, annotationId: annotation };
510 AnnotatedTextEdit.replace = replace;
512 * Creates an annotated insert text edit.
514 * @param position The position to insert the text at.
515 * @param newText The text to be inserted.
516 * @param annotation The annotation.
518 function insert(position, newText, annotation) {
519 return { range: { start: position, end: position }, newText: newText, annotationId: annotation };
521 AnnotatedTextEdit.insert = insert;
523 * Creates an annotated delete text edit.
525 * @param range The range of text to be deleted.
526 * @param annotation The annotation.
528 function del(range, annotation) {
529 return { range: range, newText: '', annotationId: annotation };
531 AnnotatedTextEdit.del = del;
533 var candidate = value;
534 return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
536 AnnotatedTextEdit.is = is;
537 })(AnnotatedTextEdit = exports.AnnotatedTextEdit || (exports.AnnotatedTextEdit = {}));
539 * The TextDocumentEdit namespace provides helper function to create
540 * an edit that manipulates a text document.
542 var TextDocumentEdit;
543 (function (TextDocumentEdit) {
545 * Creates a new `TextDocumentEdit`
547 function create(textDocument, edits) {
548 return { textDocument: textDocument, edits: edits };
550 TextDocumentEdit.create = create;
552 var candidate = value;
553 return Is.defined(candidate)
554 && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument)
555 && Array.isArray(candidate.edits);
557 TextDocumentEdit.is = is;
558 })(TextDocumentEdit = exports.TextDocumentEdit || (exports.TextDocumentEdit = {}));
560 (function (CreateFile) {
561 function create(uri, options, annotation) {
566 if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
567 result.options = options;
569 if (annotation !== undefined) {
570 result.annotationId = annotation;
574 CreateFile.create = create;
576 var candidate = value;
577 return candidate && candidate.kind === 'create' && Is.string(candidate.uri) && (candidate.options === undefined ||
578 ((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));
581 })(CreateFile = exports.CreateFile || (exports.CreateFile = {}));
583 (function (RenameFile) {
584 function create(oldUri, newUri, options, annotation) {
590 if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
591 result.options = options;
593 if (annotation !== undefined) {
594 result.annotationId = annotation;
598 RenameFile.create = create;
600 var candidate = value;
601 return candidate && candidate.kind === 'rename' && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === undefined ||
602 ((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));
605 })(RenameFile = exports.RenameFile || (exports.RenameFile = {}));
607 (function (DeleteFile) {
608 function create(uri, options, annotation) {
613 if (options !== undefined && (options.recursive !== undefined || options.ignoreIfNotExists !== undefined)) {
614 result.options = options;
616 if (annotation !== undefined) {
617 result.annotationId = annotation;
621 DeleteFile.create = create;
623 var candidate = value;
624 return candidate && candidate.kind === 'delete' && Is.string(candidate.uri) && (candidate.options === undefined ||
625 ((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));
628 })(DeleteFile = exports.DeleteFile || (exports.DeleteFile = {}));
630 (function (WorkspaceEdit) {
632 var candidate = value;
634 (candidate.changes !== undefined || candidate.documentChanges !== undefined) &&
635 (candidate.documentChanges === undefined || candidate.documentChanges.every(function (change) {
636 if (Is.string(change.kind)) {
637 return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
640 return TextDocumentEdit.is(change);
644 WorkspaceEdit.is = is;
645 })(WorkspaceEdit = exports.WorkspaceEdit || (exports.WorkspaceEdit = {}));
646 var TextEditChangeImpl = /** @class */ (function () {
647 function TextEditChangeImpl(edits, changeAnnotations) {
649 this.changeAnnotations = changeAnnotations;
651 TextEditChangeImpl.prototype.insert = function (position, newText, annotation) {
654 if (annotation === undefined) {
655 edit = TextEdit.insert(position, newText);
657 else if (ChangeAnnotationIdentifier.is(annotation)) {
659 edit = AnnotatedTextEdit.insert(position, newText, annotation);
662 this.assertChangeAnnotations(this.changeAnnotations);
663 id = this.changeAnnotations.manage(annotation);
664 edit = AnnotatedTextEdit.insert(position, newText, id);
666 this.edits.push(edit);
667 if (id !== undefined) {
671 TextEditChangeImpl.prototype.replace = function (range, newText, annotation) {
674 if (annotation === undefined) {
675 edit = TextEdit.replace(range, newText);
677 else if (ChangeAnnotationIdentifier.is(annotation)) {
679 edit = AnnotatedTextEdit.replace(range, newText, annotation);
682 this.assertChangeAnnotations(this.changeAnnotations);
683 id = this.changeAnnotations.manage(annotation);
684 edit = AnnotatedTextEdit.replace(range, newText, id);
686 this.edits.push(edit);
687 if (id !== undefined) {
691 TextEditChangeImpl.prototype.delete = function (range, annotation) {
694 if (annotation === undefined) {
695 edit = TextEdit.del(range);
697 else if (ChangeAnnotationIdentifier.is(annotation)) {
699 edit = AnnotatedTextEdit.del(range, annotation);
702 this.assertChangeAnnotations(this.changeAnnotations);
703 id = this.changeAnnotations.manage(annotation);
704 edit = AnnotatedTextEdit.del(range, id);
706 this.edits.push(edit);
707 if (id !== undefined) {
711 TextEditChangeImpl.prototype.add = function (edit) {
712 this.edits.push(edit);
714 TextEditChangeImpl.prototype.all = function () {
717 TextEditChangeImpl.prototype.clear = function () {
718 this.edits.splice(0, this.edits.length);
720 TextEditChangeImpl.prototype.assertChangeAnnotations = function (value) {
721 if (value === undefined) {
722 throw new Error("Text edit change is not configured to manage change annotations.");
725 return TextEditChangeImpl;
730 var ChangeAnnotations = /** @class */ (function () {
731 function ChangeAnnotations(annotations) {
732 this._annotations = annotations === undefined ? Object.create(null) : annotations;
736 ChangeAnnotations.prototype.all = function () {
737 return this._annotations;
739 Object.defineProperty(ChangeAnnotations.prototype, "size", {
746 ChangeAnnotations.prototype.manage = function (idOrAnnotation, annotation) {
748 if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
753 annotation = idOrAnnotation;
755 if (this._annotations[id] !== undefined) {
756 throw new Error("Id " + id + " is already in use.");
758 if (annotation === undefined) {
759 throw new Error("No annotation provided for id " + id);
761 this._annotations[id] = annotation;
765 ChangeAnnotations.prototype.nextId = function () {
767 return this._counter.toString();
769 return ChangeAnnotations;
772 * A workspace change helps constructing changes to a workspace.
774 var WorkspaceChange = /** @class */ (function () {
775 function WorkspaceChange(workspaceEdit) {
777 this._textEditChanges = Object.create(null);
778 if (workspaceEdit !== undefined) {
779 this._workspaceEdit = workspaceEdit;
780 if (workspaceEdit.documentChanges) {
781 this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
782 workspaceEdit.changeAnnotations = this._changeAnnotations.all();
783 workspaceEdit.documentChanges.forEach(function (change) {
784 if (TextDocumentEdit.is(change)) {
785 var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
786 _this._textEditChanges[change.textDocument.uri] = textEditChange;
790 else if (workspaceEdit.changes) {
791 Object.keys(workspaceEdit.changes).forEach(function (key) {
792 var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
793 _this._textEditChanges[key] = textEditChange;
798 this._workspaceEdit = {};
801 Object.defineProperty(WorkspaceChange.prototype, "edit", {
803 * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
804 * use to be returned from a workspace edit operation like rename.
807 this.initDocumentChanges();
808 if (this._changeAnnotations !== undefined) {
809 if (this._changeAnnotations.size === 0) {
810 this._workspaceEdit.changeAnnotations = undefined;
813 this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
816 return this._workspaceEdit;
821 WorkspaceChange.prototype.getTextEditChange = function (key) {
822 if (OptionalVersionedTextDocumentIdentifier.is(key)) {
823 this.initDocumentChanges();
824 if (this._workspaceEdit.documentChanges === undefined) {
825 throw new Error('Workspace edit is not configured for document changes.');
827 var textDocument = { uri: key.uri, version: key.version };
828 var result = this._textEditChanges[textDocument.uri];
831 var textDocumentEdit = {
832 textDocument: textDocument,
835 this._workspaceEdit.documentChanges.push(textDocumentEdit);
836 result = new TextEditChangeImpl(edits, this._changeAnnotations);
837 this._textEditChanges[textDocument.uri] = result;
843 if (this._workspaceEdit.changes === undefined) {
844 throw new Error('Workspace edit is not configured for normal text edit changes.');
846 var result = this._textEditChanges[key];
849 this._workspaceEdit.changes[key] = edits;
850 result = new TextEditChangeImpl(edits);
851 this._textEditChanges[key] = result;
856 WorkspaceChange.prototype.initDocumentChanges = function () {
857 if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
858 this._changeAnnotations = new ChangeAnnotations();
859 this._workspaceEdit.documentChanges = [];
860 this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
863 WorkspaceChange.prototype.initChanges = function () {
864 if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
865 this._workspaceEdit.changes = Object.create(null);
868 WorkspaceChange.prototype.createFile = function (uri, optionsOrAnnotation, options) {
869 this.initDocumentChanges();
870 if (this._workspaceEdit.documentChanges === undefined) {
871 throw new Error('Workspace edit is not configured for document changes.');
874 if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
875 annotation = optionsOrAnnotation;
878 options = optionsOrAnnotation;
882 if (annotation === undefined) {
883 operation = CreateFile.create(uri, options);
886 id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
887 operation = CreateFile.create(uri, options, id);
889 this._workspaceEdit.documentChanges.push(operation);
890 if (id !== undefined) {
894 WorkspaceChange.prototype.renameFile = function (oldUri, newUri, optionsOrAnnotation, options) {
895 this.initDocumentChanges();
896 if (this._workspaceEdit.documentChanges === undefined) {
897 throw new Error('Workspace edit is not configured for document changes.');
900 if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
901 annotation = optionsOrAnnotation;
904 options = optionsOrAnnotation;
908 if (annotation === undefined) {
909 operation = RenameFile.create(oldUri, newUri, options);
912 id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
913 operation = RenameFile.create(oldUri, newUri, options, id);
915 this._workspaceEdit.documentChanges.push(operation);
916 if (id !== undefined) {
920 WorkspaceChange.prototype.deleteFile = function (uri, optionsOrAnnotation, options) {
921 this.initDocumentChanges();
922 if (this._workspaceEdit.documentChanges === undefined) {
923 throw new Error('Workspace edit is not configured for document changes.');
926 if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
927 annotation = optionsOrAnnotation;
930 options = optionsOrAnnotation;
934 if (annotation === undefined) {
935 operation = DeleteFile.create(uri, options);
938 id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
939 operation = DeleteFile.create(uri, options, id);
941 this._workspaceEdit.documentChanges.push(operation);
942 if (id !== undefined) {
946 return WorkspaceChange;
948 exports.WorkspaceChange = WorkspaceChange;
950 * The TextDocumentIdentifier namespace provides helper functions to work with
951 * [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
953 var TextDocumentIdentifier;
954 (function (TextDocumentIdentifier) {
956 * Creates a new TextDocumentIdentifier literal.
957 * @param uri The document's uri.
959 function create(uri) {
962 TextDocumentIdentifier.create = create;
964 * Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
967 var candidate = value;
968 return Is.defined(candidate) && Is.string(candidate.uri);
970 TextDocumentIdentifier.is = is;
971 })(TextDocumentIdentifier = exports.TextDocumentIdentifier || (exports.TextDocumentIdentifier = {}));
973 * The VersionedTextDocumentIdentifier namespace provides helper functions to work with
974 * [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
976 var VersionedTextDocumentIdentifier;
977 (function (VersionedTextDocumentIdentifier) {
979 * Creates a new VersionedTextDocumentIdentifier literal.
980 * @param uri The document's uri.
981 * @param uri The document's text.
983 function create(uri, version) {
984 return { uri: uri, version: version };
986 VersionedTextDocumentIdentifier.create = create;
988 * Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
991 var candidate = value;
992 return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
994 VersionedTextDocumentIdentifier.is = is;
995 })(VersionedTextDocumentIdentifier = exports.VersionedTextDocumentIdentifier || (exports.VersionedTextDocumentIdentifier = {}));
997 * The OptionalVersionedTextDocumentIdentifier namespace provides helper functions to work with
998 * [OptionalVersionedTextDocumentIdentifier](#OptionalVersionedTextDocumentIdentifier) literals.
1000 var OptionalVersionedTextDocumentIdentifier;
1001 (function (OptionalVersionedTextDocumentIdentifier) {
1003 * Creates a new OptionalVersionedTextDocumentIdentifier literal.
1004 * @param uri The document's uri.
1005 * @param uri The document's text.
1007 function create(uri, version) {
1008 return { uri: uri, version: version };
1010 OptionalVersionedTextDocumentIdentifier.create = create;
1012 * Checks whether the given literal conforms to the [OptionalVersionedTextDocumentIdentifier](#OptionalVersionedTextDocumentIdentifier) interface.
1014 function is(value) {
1015 var candidate = value;
1016 return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
1018 OptionalVersionedTextDocumentIdentifier.is = is;
1019 })(OptionalVersionedTextDocumentIdentifier = exports.OptionalVersionedTextDocumentIdentifier || (exports.OptionalVersionedTextDocumentIdentifier = {}));
1021 * The TextDocumentItem namespace provides helper functions to work with
1022 * [TextDocumentItem](#TextDocumentItem) literals.
1024 var TextDocumentItem;
1025 (function (TextDocumentItem) {
1027 * Creates a new TextDocumentItem literal.
1028 * @param uri The document's uri.
1029 * @param languageId The document's language identifier.
1030 * @param version The document's version number.
1031 * @param text The document's text.
1033 function create(uri, languageId, version, text) {
1034 return { uri: uri, languageId: languageId, version: version, text: text };
1036 TextDocumentItem.create = create;
1038 * Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
1040 function is(value) {
1041 var candidate = value;
1042 return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
1044 TextDocumentItem.is = is;
1045 })(TextDocumentItem = exports.TextDocumentItem || (exports.TextDocumentItem = {}));
1047 * Describes the content type that a client supports in various
1048 * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
1050 * Please note that `MarkupKinds` must not start with a `$`. This kinds
1051 * are reserved for internal usage.
1054 (function (MarkupKind) {
1056 * Plain text is supported as a content format
1058 MarkupKind.PlainText = 'plaintext';
1060 * Markdown is supported as a content format
1062 MarkupKind.Markdown = 'markdown';
1063 })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
1064 (function (MarkupKind) {
1066 * Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
1068 function is(value) {
1069 var candidate = value;
1070 return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
1073 })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
1075 (function (MarkupContent) {
1077 * Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
1079 function is(value) {
1080 var candidate = value;
1081 return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
1083 MarkupContent.is = is;
1084 })(MarkupContent = exports.MarkupContent || (exports.MarkupContent = {}));
1086 * The kind of a completion entry.
1088 var CompletionItemKind;
1089 (function (CompletionItemKind) {
1090 CompletionItemKind.Text = 1;
1091 CompletionItemKind.Method = 2;
1092 CompletionItemKind.Function = 3;
1093 CompletionItemKind.Constructor = 4;
1094 CompletionItemKind.Field = 5;
1095 CompletionItemKind.Variable = 6;
1096 CompletionItemKind.Class = 7;
1097 CompletionItemKind.Interface = 8;
1098 CompletionItemKind.Module = 9;
1099 CompletionItemKind.Property = 10;
1100 CompletionItemKind.Unit = 11;
1101 CompletionItemKind.Value = 12;
1102 CompletionItemKind.Enum = 13;
1103 CompletionItemKind.Keyword = 14;
1104 CompletionItemKind.Snippet = 15;
1105 CompletionItemKind.Color = 16;
1106 CompletionItemKind.File = 17;
1107 CompletionItemKind.Reference = 18;
1108 CompletionItemKind.Folder = 19;
1109 CompletionItemKind.EnumMember = 20;
1110 CompletionItemKind.Constant = 21;
1111 CompletionItemKind.Struct = 22;
1112 CompletionItemKind.Event = 23;
1113 CompletionItemKind.Operator = 24;
1114 CompletionItemKind.TypeParameter = 25;
1115 })(CompletionItemKind = exports.CompletionItemKind || (exports.CompletionItemKind = {}));
1117 * Defines whether the insert text in a completion item should be interpreted as
1118 * plain text or a snippet.
1120 var InsertTextFormat;
1121 (function (InsertTextFormat) {
1123 * The primary text to be inserted is treated as a plain string.
1125 InsertTextFormat.PlainText = 1;
1127 * The primary text to be inserted is treated as a snippet.
1129 * A snippet can define tab stops and placeholders with `$1`, `$2`
1130 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
1131 * the end of the snippet. Placeholders with equal identifiers are linked,
1132 * that is typing in one will update others too.
1134 * See also: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#snippet_syntax
1136 InsertTextFormat.Snippet = 2;
1137 })(InsertTextFormat = exports.InsertTextFormat || (exports.InsertTextFormat = {}));
1139 * Completion item tags are extra annotations that tweak the rendering of a completion
1144 var CompletionItemTag;
1145 (function (CompletionItemTag) {
1147 * Render a completion as obsolete, usually using a strike-out.
1149 CompletionItemTag.Deprecated = 1;
1150 })(CompletionItemTag = exports.CompletionItemTag || (exports.CompletionItemTag = {}));
1152 * The InsertReplaceEdit namespace provides functions to deal with insert / replace edits.
1156 var InsertReplaceEdit;
1157 (function (InsertReplaceEdit) {
1159 * Creates a new insert / replace edit
1161 function create(newText, insert, replace) {
1162 return { newText: newText, insert: insert, replace: replace };
1164 InsertReplaceEdit.create = create;
1166 * Checks whether the given literal conforms to the [InsertReplaceEdit](#InsertReplaceEdit) interface.
1168 function is(value) {
1169 var candidate = value;
1170 return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
1172 InsertReplaceEdit.is = is;
1173 })(InsertReplaceEdit = exports.InsertReplaceEdit || (exports.InsertReplaceEdit = {}));
1175 * How whitespace and indentation is handled during completion
1181 (function (InsertTextMode) {
1183 * The insertion or replace strings is taken as it is. If the
1184 * value is multi line the lines below the cursor will be
1185 * inserted using the indentation defined in the string value.
1186 * The client will not apply any kind of adjustments to the
1189 InsertTextMode.asIs = 1;
1191 * The editor adjusts leading whitespace of new lines so that
1192 * they match the indentation up to the cursor of the line for
1193 * which the item is accepted.
1195 * Consider a line like this: <2tabs><cursor><3tabs>foo. Accepting a
1196 * multi line completion item is indented using 2 tabs and all
1197 * following lines inserted will be indented using 2 tabs as well.
1199 InsertTextMode.adjustIndentation = 2;
1200 })(InsertTextMode = exports.InsertTextMode || (exports.InsertTextMode = {}));
1202 * The CompletionItem namespace provides functions to deal with
1206 (function (CompletionItem) {
1208 * Create a completion item and seed it with a label.
1209 * @param label The completion item's label
1211 function create(label) {
1212 return { label: label };
1214 CompletionItem.create = create;
1215 })(CompletionItem = exports.CompletionItem || (exports.CompletionItem = {}));
1217 * The CompletionList namespace provides functions to deal with
1221 (function (CompletionList) {
1223 * Creates a new completion list.
1225 * @param items The completion items.
1226 * @param isIncomplete The list is not complete.
1228 function create(items, isIncomplete) {
1229 return { items: items ? items : [], isIncomplete: !!isIncomplete };
1231 CompletionList.create = create;
1232 })(CompletionList = exports.CompletionList || (exports.CompletionList = {}));
1234 (function (MarkedString) {
1236 * Creates a marked string from plain text.
1238 * @param plainText The plain text.
1240 function fromPlainText(plainText) {
1241 return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
1243 MarkedString.fromPlainText = fromPlainText;
1245 * Checks whether the given value conforms to the [MarkedString](#MarkedString) type.
1247 function is(value) {
1248 var candidate = value;
1249 return Is.string(candidate) || (Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value));
1251 MarkedString.is = is;
1252 })(MarkedString = exports.MarkedString || (exports.MarkedString = {}));
1256 * Checks whether the given value conforms to the [Hover](#Hover) interface.
1258 function is(value) {
1259 var candidate = value;
1260 return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) ||
1261 MarkedString.is(candidate.contents) ||
1262 Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === undefined || Range.is(value.range));
1265 })(Hover = exports.Hover || (exports.Hover = {}));
1267 * The ParameterInformation namespace provides helper functions to work with
1268 * [ParameterInformation](#ParameterInformation) literals.
1270 var ParameterInformation;
1271 (function (ParameterInformation) {
1273 * Creates a new parameter information literal.
1275 * @param label A label string.
1276 * @param documentation A doc string.
1278 function create(label, documentation) {
1279 return documentation ? { label: label, documentation: documentation } : { label: label };
1281 ParameterInformation.create = create;
1282 })(ParameterInformation = exports.ParameterInformation || (exports.ParameterInformation = {}));
1284 * The SignatureInformation namespace provides helper functions to work with
1285 * [SignatureInformation](#SignatureInformation) literals.
1287 var SignatureInformation;
1288 (function (SignatureInformation) {
1289 function create(label, documentation) {
1290 var parameters = [];
1291 for (var _i = 2; _i < arguments.length; _i++) {
1292 parameters[_i - 2] = arguments[_i];
1294 var result = { label: label };
1295 if (Is.defined(documentation)) {
1296 result.documentation = documentation;
1298 if (Is.defined(parameters)) {
1299 result.parameters = parameters;
1302 result.parameters = [];
1306 SignatureInformation.create = create;
1307 })(SignatureInformation = exports.SignatureInformation || (exports.SignatureInformation = {}));
1309 * A document highlight kind.
1311 var DocumentHighlightKind;
1312 (function (DocumentHighlightKind) {
1314 * A textual occurrence.
1316 DocumentHighlightKind.Text = 1;
1318 * Read-access of a symbol, like reading a variable.
1320 DocumentHighlightKind.Read = 2;
1322 * Write-access of a symbol, like writing to a variable.
1324 DocumentHighlightKind.Write = 3;
1325 })(DocumentHighlightKind = exports.DocumentHighlightKind || (exports.DocumentHighlightKind = {}));
1327 * DocumentHighlight namespace to provide helper functions to work with
1328 * [DocumentHighlight](#DocumentHighlight) literals.
1330 var DocumentHighlight;
1331 (function (DocumentHighlight) {
1333 * Create a DocumentHighlight object.
1334 * @param range The range the highlight applies to.
1336 function create(range, kind) {
1337 var result = { range: range };
1338 if (Is.number(kind)) {
1343 DocumentHighlight.create = create;
1344 })(DocumentHighlight = exports.DocumentHighlight || (exports.DocumentHighlight = {}));
1349 (function (SymbolKind) {
1350 SymbolKind.File = 1;
1351 SymbolKind.Module = 2;
1352 SymbolKind.Namespace = 3;
1353 SymbolKind.Package = 4;
1354 SymbolKind.Class = 5;
1355 SymbolKind.Method = 6;
1356 SymbolKind.Property = 7;
1357 SymbolKind.Field = 8;
1358 SymbolKind.Constructor = 9;
1359 SymbolKind.Enum = 10;
1360 SymbolKind.Interface = 11;
1361 SymbolKind.Function = 12;
1362 SymbolKind.Variable = 13;
1363 SymbolKind.Constant = 14;
1364 SymbolKind.String = 15;
1365 SymbolKind.Number = 16;
1366 SymbolKind.Boolean = 17;
1367 SymbolKind.Array = 18;
1368 SymbolKind.Object = 19;
1369 SymbolKind.Key = 20;
1370 SymbolKind.Null = 21;
1371 SymbolKind.EnumMember = 22;
1372 SymbolKind.Struct = 23;
1373 SymbolKind.Event = 24;
1374 SymbolKind.Operator = 25;
1375 SymbolKind.TypeParameter = 26;
1376 })(SymbolKind = exports.SymbolKind || (exports.SymbolKind = {}));
1378 * Symbol tags are extra annotations that tweak the rendering of a symbol.
1382 (function (SymbolTag) {
1384 * Render a symbol as obsolete, usually using a strike-out.
1386 SymbolTag.Deprecated = 1;
1387 })(SymbolTag = exports.SymbolTag || (exports.SymbolTag = {}));
1388 var SymbolInformation;
1389 (function (SymbolInformation) {
1391 * Creates a new symbol information literal.
1393 * @param name The name of the symbol.
1394 * @param kind The kind of the symbol.
1395 * @param range The range of the location of the symbol.
1396 * @param uri The resource of the location of symbol, defaults to the current document.
1397 * @param containerName The name of the symbol containing the symbol.
1399 function create(name, kind, range, uri, containerName) {
1403 location: { uri: uri, range: range }
1405 if (containerName) {
1406 result.containerName = containerName;
1410 SymbolInformation.create = create;
1411 })(SymbolInformation = exports.SymbolInformation || (exports.SymbolInformation = {}));
1413 (function (DocumentSymbol) {
1415 * Creates a new symbol information literal.
1417 * @param name The name of the symbol.
1418 * @param detail The detail of the symbol.
1419 * @param kind The kind of the symbol.
1420 * @param range The range of the symbol.
1421 * @param selectionRange The selectionRange of the symbol.
1422 * @param children Children of the symbol.
1424 function create(name, detail, kind, range, selectionRange, children) {
1430 selectionRange: selectionRange
1432 if (children !== undefined) {
1433 result.children = children;
1437 DocumentSymbol.create = create;
1439 * Checks whether the given literal conforms to the [DocumentSymbol](#DocumentSymbol) interface.
1441 function is(value) {
1442 var candidate = value;
1444 Is.string(candidate.name) && Is.number(candidate.kind) &&
1445 Range.is(candidate.range) && Range.is(candidate.selectionRange) &&
1446 (candidate.detail === undefined || Is.string(candidate.detail)) &&
1447 (candidate.deprecated === undefined || Is.boolean(candidate.deprecated)) &&
1448 (candidate.children === undefined || Array.isArray(candidate.children)) &&
1449 (candidate.tags === undefined || Array.isArray(candidate.tags));
1451 DocumentSymbol.is = is;
1452 })(DocumentSymbol = exports.DocumentSymbol || (exports.DocumentSymbol = {}));
1454 * A set of predefined code action kinds
1457 (function (CodeActionKind) {
1461 CodeActionKind.Empty = '';
1463 * Base kind for quickfix actions: 'quickfix'
1465 CodeActionKind.QuickFix = 'quickfix';
1467 * Base kind for refactoring actions: 'refactor'
1469 CodeActionKind.Refactor = 'refactor';
1471 * Base kind for refactoring extraction actions: 'refactor.extract'
1473 * Example extract actions:
1476 * - Extract function
1477 * - Extract variable
1478 * - Extract interface from class
1481 CodeActionKind.RefactorExtract = 'refactor.extract';
1483 * Base kind for refactoring inline actions: 'refactor.inline'
1485 * Example inline actions:
1492 CodeActionKind.RefactorInline = 'refactor.inline';
1494 * Base kind for refactoring rewrite actions: 'refactor.rewrite'
1496 * Example rewrite actions:
1498 * - Convert JavaScript function to class
1499 * - Add or remove parameter
1500 * - Encapsulate field
1501 * - Make method static
1502 * - Move method to base class
1505 CodeActionKind.RefactorRewrite = 'refactor.rewrite';
1507 * Base kind for source actions: `source`
1509 * Source code actions apply to the entire file.
1511 CodeActionKind.Source = 'source';
1513 * Base kind for an organize imports source action: `source.organizeImports`
1515 CodeActionKind.SourceOrganizeImports = 'source.organizeImports';
1517 * Base kind for auto-fix source actions: `source.fixAll`.
1519 * Fix all actions automatically fix errors that have a clear fix that do not require user input.
1520 * They should not suppress errors or perform unsafe fixes such as generating new types or classes.
1524 CodeActionKind.SourceFixAll = 'source.fixAll';
1525 })(CodeActionKind = exports.CodeActionKind || (exports.CodeActionKind = {}));
1527 * The CodeActionContext namespace provides helper functions to work with
1528 * [CodeActionContext](#CodeActionContext) literals.
1530 var CodeActionContext;
1531 (function (CodeActionContext) {
1533 * Creates a new CodeActionContext literal.
1535 function create(diagnostics, only) {
1536 var result = { diagnostics: diagnostics };
1537 if (only !== undefined && only !== null) {
1542 CodeActionContext.create = create;
1544 * Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface.
1546 function is(value) {
1547 var candidate = value;
1548 return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === undefined || Is.typedArray(candidate.only, Is.string));
1550 CodeActionContext.is = is;
1551 })(CodeActionContext = exports.CodeActionContext || (exports.CodeActionContext = {}));
1553 (function (CodeAction) {
1554 function create(title, kindOrCommandOrEdit, kind) {
1555 var result = { title: title };
1556 var checkKind = true;
1557 if (typeof kindOrCommandOrEdit === 'string') {
1559 result.kind = kindOrCommandOrEdit;
1561 else if (Command.is(kindOrCommandOrEdit)) {
1562 result.command = kindOrCommandOrEdit;
1565 result.edit = kindOrCommandOrEdit;
1567 if (checkKind && kind !== undefined) {
1572 CodeAction.create = create;
1573 function is(value) {
1574 var candidate = value;
1575 return candidate && Is.string(candidate.title) &&
1576 (candidate.diagnostics === undefined || Is.typedArray(candidate.diagnostics, Diagnostic.is)) &&
1577 (candidate.kind === undefined || Is.string(candidate.kind)) &&
1578 (candidate.edit !== undefined || candidate.command !== undefined) &&
1579 (candidate.command === undefined || Command.is(candidate.command)) &&
1580 (candidate.isPreferred === undefined || Is.boolean(candidate.isPreferred)) &&
1581 (candidate.edit === undefined || WorkspaceEdit.is(candidate.edit));
1584 })(CodeAction = exports.CodeAction || (exports.CodeAction = {}));
1586 * The CodeLens namespace provides helper functions to work with
1587 * [CodeLens](#CodeLens) literals.
1590 (function (CodeLens) {
1592 * Creates a new CodeLens literal.
1594 function create(range, data) {
1595 var result = { range: range };
1596 if (Is.defined(data)) {
1601 CodeLens.create = create;
1603 * Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface.
1605 function is(value) {
1606 var candidate = value;
1607 return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
1610 })(CodeLens = exports.CodeLens || (exports.CodeLens = {}));
1612 * The FormattingOptions namespace provides helper functions to work with
1613 * [FormattingOptions](#FormattingOptions) literals.
1615 var FormattingOptions;
1616 (function (FormattingOptions) {
1618 * Creates a new FormattingOptions literal.
1620 function create(tabSize, insertSpaces) {
1621 return { tabSize: tabSize, insertSpaces: insertSpaces };
1623 FormattingOptions.create = create;
1625 * Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface.
1627 function is(value) {
1628 var candidate = value;
1629 return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
1631 FormattingOptions.is = is;
1632 })(FormattingOptions = exports.FormattingOptions || (exports.FormattingOptions = {}));
1634 * The DocumentLink namespace provides helper functions to work with
1635 * [DocumentLink](#DocumentLink) literals.
1638 (function (DocumentLink) {
1640 * Creates a new DocumentLink literal.
1642 function create(range, target, data) {
1643 return { range: range, target: target, data: data };
1645 DocumentLink.create = create;
1647 * Checks whether the given literal conforms to the [DocumentLink](#DocumentLink) interface.
1649 function is(value) {
1650 var candidate = value;
1651 return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
1653 DocumentLink.is = is;
1654 })(DocumentLink = exports.DocumentLink || (exports.DocumentLink = {}));
1656 * The SelectionRange namespace provides helper function to work with
1657 * SelectionRange literals.
1660 (function (SelectionRange) {
1662 * Creates a new SelectionRange
1663 * @param range the range.
1664 * @param parent an optional parent.
1666 function create(range, parent) {
1667 return { range: range, parent: parent };
1669 SelectionRange.create = create;
1670 function is(value) {
1671 var candidate = value;
1672 return candidate !== undefined && Range.is(candidate.range) && (candidate.parent === undefined || SelectionRange.is(candidate.parent));
1674 SelectionRange.is = is;
1675 })(SelectionRange = exports.SelectionRange || (exports.SelectionRange = {}));
1676 exports.EOL = ['\n', '\r\n', '\r'];
1678 * @deprecated Use the text document from the new vscode-languageserver-textdocument package.
1681 (function (TextDocument) {
1683 * Creates a new ITextDocument literal from the given uri and content.
1684 * @param uri The document's uri.
1685 * @param languageId The document's language Id.
1686 * @param content The document's content.
1688 function create(uri, languageId, version, content) {
1689 return new FullTextDocument(uri, languageId, version, content);
1691 TextDocument.create = create;
1693 * Checks whether the given literal conforms to the [ITextDocument](#ITextDocument) interface.
1695 function is(value) {
1696 var candidate = value;
1697 return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.uinteger(candidate.lineCount)
1698 && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
1700 TextDocument.is = is;
1701 function applyEdits(document, edits) {
1702 var text = document.getText();
1703 var sortedEdits = mergeSort(edits, function (a, b) {
1704 var diff = a.range.start.line - b.range.start.line;
1706 return a.range.start.character - b.range.start.character;
1710 var lastModifiedOffset = text.length;
1711 for (var i = sortedEdits.length - 1; i >= 0; i--) {
1712 var e = sortedEdits[i];
1713 var startOffset = document.offsetAt(e.range.start);
1714 var endOffset = document.offsetAt(e.range.end);
1715 if (endOffset <= lastModifiedOffset) {
1716 text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
1719 throw new Error('Overlapping edit');
1721 lastModifiedOffset = startOffset;
1725 TextDocument.applyEdits = applyEdits;
1726 function mergeSort(data, compare) {
1727 if (data.length <= 1) {
1731 var p = (data.length / 2) | 0;
1732 var left = data.slice(0, p);
1733 var right = data.slice(p);
1734 mergeSort(left, compare);
1735 mergeSort(right, compare);
1739 while (leftIdx < left.length && rightIdx < right.length) {
1740 var ret = compare(left[leftIdx], right[rightIdx]);
1742 // smaller_equal -> take left to preserve order
1743 data[i++] = left[leftIdx++];
1746 // greater -> take right
1747 data[i++] = right[rightIdx++];
1750 while (leftIdx < left.length) {
1751 data[i++] = left[leftIdx++];
1753 while (rightIdx < right.length) {
1754 data[i++] = right[rightIdx++];
1758 })(TextDocument = exports.TextDocument || (exports.TextDocument = {}));
1760 * @deprecated Use the text document from the new vscode-languageserver-textdocument package.
1762 var FullTextDocument = /** @class */ (function () {
1763 function FullTextDocument(uri, languageId, version, content) {
1765 this._languageId = languageId;
1766 this._version = version;
1767 this._content = content;
1768 this._lineOffsets = undefined;
1770 Object.defineProperty(FullTextDocument.prototype, "uri", {
1777 Object.defineProperty(FullTextDocument.prototype, "languageId", {
1779 return this._languageId;
1784 Object.defineProperty(FullTextDocument.prototype, "version", {
1786 return this._version;
1791 FullTextDocument.prototype.getText = function (range) {
1793 var start = this.offsetAt(range.start);
1794 var end = this.offsetAt(range.end);
1795 return this._content.substring(start, end);
1797 return this._content;
1799 FullTextDocument.prototype.update = function (event, version) {
1800 this._content = event.text;
1801 this._version = version;
1802 this._lineOffsets = undefined;
1804 FullTextDocument.prototype.getLineOffsets = function () {
1805 if (this._lineOffsets === undefined) {
1806 var lineOffsets = [];
1807 var text = this._content;
1808 var isLineStart = true;
1809 for (var i = 0; i < text.length; i++) {
1811 lineOffsets.push(i);
1812 isLineStart = false;
1814 var ch = text.charAt(i);
1815 isLineStart = (ch === '\r' || ch === '\n');
1816 if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
1820 if (isLineStart && text.length > 0) {
1821 lineOffsets.push(text.length);
1823 this._lineOffsets = lineOffsets;
1825 return this._lineOffsets;
1827 FullTextDocument.prototype.positionAt = function (offset) {
1828 offset = Math.max(Math.min(offset, this._content.length), 0);
1829 var lineOffsets = this.getLineOffsets();
1830 var low = 0, high = lineOffsets.length;
1832 return Position.create(0, offset);
1834 while (low < high) {
1835 var mid = Math.floor((low + high) / 2);
1836 if (lineOffsets[mid] > offset) {
1843 // low is the least x for which the line offset is larger than the current offset
1844 // or array.length if no line offset is larger than the current offset
1846 return Position.create(line, offset - lineOffsets[line]);
1848 FullTextDocument.prototype.offsetAt = function (position) {
1849 var lineOffsets = this.getLineOffsets();
1850 if (position.line >= lineOffsets.length) {
1851 return this._content.length;
1853 else if (position.line < 0) {
1856 var lineOffset = lineOffsets[position.line];
1857 var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length;
1858 return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
1860 Object.defineProperty(FullTextDocument.prototype, "lineCount", {
1862 return this.getLineOffsets().length;
1867 return FullTextDocument;
1871 var toString = Object.prototype.toString;
1872 function defined(value) {
1873 return typeof value !== 'undefined';
1875 Is.defined = defined;
1876 function undefined(value) {
1877 return typeof value === 'undefined';
1879 Is.undefined = undefined;
1880 function boolean(value) {
1881 return value === true || value === false;
1883 Is.boolean = boolean;
1884 function string(value) {
1885 return toString.call(value) === '[object String]';
1888 function number(value) {
1889 return toString.call(value) === '[object Number]';
1892 function numberRange(value, min, max) {
1893 return toString.call(value) === '[object Number]' && min <= value && value <= max;
1895 Is.numberRange = numberRange;
1896 function integer(value) {
1897 return toString.call(value) === '[object Number]' && -2147483648 <= value && value <= 2147483647;
1899 Is.integer = integer;
1900 function uinteger(value) {
1901 return toString.call(value) === '[object Number]' && 0 <= value && value <= 2147483647;
1903 Is.uinteger = uinteger;
1904 function func(value) {
1905 return toString.call(value) === '[object Function]';
1908 function objectLiteral(value) {
1909 // Strictly speaking class instances pass this check as well. Since the LSP
1910 // doesn't use classes we ignore this for now. If we do we need to add something
1911 // like this: `Object.getPrototypeOf(Object.getPrototypeOf(x)) === null`
1912 return value !== null && typeof value === 'object';
1914 Is.objectLiteral = objectLiteral;
1915 function typedArray(value, check) {
1916 return Array.isArray(value) && value.every(check);
1918 Is.typedArray = typedArray;
1919 })(Is || (Is = {}));
1921 //# sourceMappingURL=main.js.map