@21epub/epub-thirdparty
Version:
epub-thirdparty
1,163 lines (1,162 loc) • 111 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
define('vs/language/html/workerManager',["require", "exports", "./fillers/monaco-editor-core"], function (require, exports, monaco_editor_core_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkerManager = void 0;
var STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
var WorkerManager = /** @class */ (function () {
function WorkerManager(defaults) {
var _this = this;
this._defaults = defaults;
this._worker = null;
this._idleCheckInterval = window.setInterval(function () { return _this._checkIfIdle(); }, 30 * 1000);
this._lastUsedTime = 0;
this._configChangeListener = this._defaults.onDidChange(function () { return _this._stopWorker(); });
}
WorkerManager.prototype._stopWorker = function () {
if (this._worker) {
this._worker.dispose();
this._worker = null;
}
this._client = null;
};
WorkerManager.prototype.dispose = function () {
clearInterval(this._idleCheckInterval);
this._configChangeListener.dispose();
this._stopWorker();
};
WorkerManager.prototype._checkIfIdle = function () {
if (!this._worker) {
return;
}
var timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
this._stopWorker();
}
};
WorkerManager.prototype._getClient = function () {
this._lastUsedTime = Date.now();
if (!this._client) {
this._worker = monaco_editor_core_1.editor.createWebWorker({
// module that exports the create() method and returns a `HTMLWorker` instance
moduleId: 'vs/language/html/htmlWorker',
// passed in to the create() method
createData: {
languageSettings: this._defaults.options,
languageId: this._defaults.languageId
},
label: this._defaults.languageId
});
this._client = this._worker.getProxy();
}
return this._client;
};
WorkerManager.prototype.getLanguageServiceWorker = function () {
var _this = this;
var resources = [];
for (var _i = 0; _i < arguments.length; _i++) {
resources[_i] = arguments[_i];
}
var _client;
return this._getClient()
.then(function (client) {
_client = client;
})
.then(function (_) {
if (_this._worker) {
return _this._worker.withSyncedResources(resources);
}
})
.then(function (_) { return _client; });
};
return WorkerManager;
}());
exports.WorkerManager = WorkerManager;
});
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define('vscode-languageserver-types/main',["require", "exports"], factory);
}
})(function (require, exports) {
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
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;
var integer;
(function (integer) {
integer.MIN_VALUE = -2147483648;
integer.MAX_VALUE = 2147483647;
})(integer = exports.integer || (exports.integer = {}));
var uinteger;
(function (uinteger) {
uinteger.MIN_VALUE = 0;
uinteger.MAX_VALUE = 2147483647;
})(uinteger = exports.uinteger || (exports.uinteger = {}));
/**
* The Position namespace provides helper functions to work with
* [Position](#Position) literals.
*/
var Position;
(function (Position) {
/**
* Creates a new Position literal from the given line and character.
* @param line The position's line.
* @param character The position's character.
*/
function create(line, character) {
if (line === Number.MAX_VALUE) {
line = uinteger.MAX_VALUE;
}
if (character === Number.MAX_VALUE) {
character = uinteger.MAX_VALUE;
}
return { line: line, character: character };
}
Position.create = create;
/**
* Checks whether the given literal conforms to the [Position](#Position) interface.
*/
function is(value) {
var candidate = value;
return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
}
Position.is = is;
})(Position = exports.Position || (exports.Position = {}));
/**
* The Range namespace provides helper functions to work with
* [Range](#Range) literals.
*/
var Range;
(function (Range) {
function create(one, two, three, four) {
if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
return { start: Position.create(one, two), end: Position.create(three, four) };
}
else if (Position.is(one) && Position.is(two)) {
return { start: one, end: two };
}
else {
throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
}
}
Range.create = create;
/**
* Checks whether the given literal conforms to the [Range](#Range) interface.
*/
function is(value) {
var candidate = value;
return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
}
Range.is = is;
})(Range = exports.Range || (exports.Range = {}));
/**
* The Location namespace provides helper functions to work with
* [Location](#Location) literals.
*/
var Location;
(function (Location) {
/**
* Creates a Location literal.
* @param uri The location's uri.
* @param range The location's range.
*/
function create(uri, range) {
return { uri: uri, range: range };
}
Location.create = create;
/**
* Checks whether the given literal conforms to the [Location](#Location) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
}
Location.is = is;
})(Location = exports.Location || (exports.Location = {}));
/**
* The LocationLink namespace provides helper functions to work with
* [LocationLink](#LocationLink) literals.
*/
var LocationLink;
(function (LocationLink) {
/**
* Creates a LocationLink literal.
* @param targetUri The definition's uri.
* @param targetRange The full range of the definition.
* @param targetSelectionRange The span of the symbol definition at the target.
* @param originSelectionRange The span of the symbol being defined in the originating source file.
*/
function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
return { targetUri: targetUri, targetRange: targetRange, targetSelectionRange: targetSelectionRange, originSelectionRange: originSelectionRange };
}
LocationLink.create = create;
/**
* Checks whether the given literal conforms to the [LocationLink](#LocationLink) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri)
&& (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange))
&& (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
}
LocationLink.is = is;
})(LocationLink = exports.LocationLink || (exports.LocationLink = {}));
/**
* The Color namespace provides helper functions to work with
* [Color](#Color) literals.
*/
var Color;
(function (Color) {
/**
* Creates a new Color literal.
*/
function create(red, green, blue, alpha) {
return {
red: red,
green: green,
blue: blue,
alpha: alpha,
};
}
Color.create = create;
/**
* Checks whether the given literal conforms to the [Color](#Color) interface.
*/
function is(value) {
var candidate = value;
return Is.numberRange(candidate.red, 0, 1)
&& Is.numberRange(candidate.green, 0, 1)
&& Is.numberRange(candidate.blue, 0, 1)
&& Is.numberRange(candidate.alpha, 0, 1);
}
Color.is = is;
})(Color = exports.Color || (exports.Color = {}));
/**
* The ColorInformation namespace provides helper functions to work with
* [ColorInformation](#ColorInformation) literals.
*/
var ColorInformation;
(function (ColorInformation) {
/**
* Creates a new ColorInformation literal.
*/
function create(range, color) {
return {
range: range,
color: color,
};
}
ColorInformation.create = create;
/**
* Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
*/
function is(value) {
var candidate = value;
return Range.is(candidate.range) && Color.is(candidate.color);
}
ColorInformation.is = is;
})(ColorInformation = exports.ColorInformation || (exports.ColorInformation = {}));
/**
* The Color namespace provides helper functions to work with
* [ColorPresentation](#ColorPresentation) literals.
*/
var ColorPresentation;
(function (ColorPresentation) {
/**
* Creates a new ColorInformation literal.
*/
function create(label, textEdit, additionalTextEdits) {
return {
label: label,
textEdit: textEdit,
additionalTextEdits: additionalTextEdits,
};
}
ColorPresentation.create = create;
/**
* Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
*/
function is(value) {
var candidate = value;
return Is.string(candidate.label)
&& (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
&& (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
}
ColorPresentation.is = is;
})(ColorPresentation = exports.ColorPresentation || (exports.ColorPresentation = {}));
/**
* Enum of known range kinds
*/
var FoldingRangeKind;
(function (FoldingRangeKind) {
/**
* Folding range for a comment
*/
FoldingRangeKind["Comment"] = "comment";
/**
* Folding range for a imports or includes
*/
FoldingRangeKind["Imports"] = "imports";
/**
* Folding range for a region (e.g. `#region`)
*/
FoldingRangeKind["Region"] = "region";
})(FoldingRangeKind = exports.FoldingRangeKind || (exports.FoldingRangeKind = {}));
/**
* The folding range namespace provides helper functions to work with
* [FoldingRange](#FoldingRange) literals.
*/
var FoldingRange;
(function (FoldingRange) {
/**
* Creates a new FoldingRange literal.
*/
function create(startLine, endLine, startCharacter, endCharacter, kind) {
var result = {
startLine: startLine,
endLine: endLine
};
if (Is.defined(startCharacter)) {
result.startCharacter = startCharacter;
}
if (Is.defined(endCharacter)) {
result.endCharacter = endCharacter;
}
if (Is.defined(kind)) {
result.kind = kind;
}
return result;
}
FoldingRange.create = create;
/**
* Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
*/
function is(value) {
var candidate = value;
return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine)
&& (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter))
&& (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter))
&& (Is.undefined(candidate.kind) || Is.string(candidate.kind));
}
FoldingRange.is = is;
})(FoldingRange = exports.FoldingRange || (exports.FoldingRange = {}));
/**
* The DiagnosticRelatedInformation namespace provides helper functions to work with
* [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
*/
var DiagnosticRelatedInformation;
(function (DiagnosticRelatedInformation) {
/**
* Creates a new DiagnosticRelatedInformation literal.
*/
function create(location, message) {
return {
location: location,
message: message
};
}
DiagnosticRelatedInformation.create = create;
/**
* Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
}
DiagnosticRelatedInformation.is = is;
})(DiagnosticRelatedInformation = exports.DiagnosticRelatedInformation || (exports.DiagnosticRelatedInformation = {}));
/**
* The diagnostic's severity.
*/
var DiagnosticSeverity;
(function (DiagnosticSeverity) {
/**
* Reports an error.
*/
DiagnosticSeverity.Error = 1;
/**
* Reports a warning.
*/
DiagnosticSeverity.Warning = 2;
/**
* Reports an information.
*/
DiagnosticSeverity.Information = 3;
/**
* Reports a hint.
*/
DiagnosticSeverity.Hint = 4;
})(DiagnosticSeverity = exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {}));
/**
* The diagnostic tags.
*
* @since 3.15.0
*/
var DiagnosticTag;
(function (DiagnosticTag) {
/**
* Unused or unnecessary code.
*
* Clients are allowed to render diagnostics with this tag faded out instead of having
* an error squiggle.
*/
DiagnosticTag.Unnecessary = 1;
/**
* Deprecated or obsolete code.
*
* Clients are allowed to rendered diagnostics with this tag strike through.
*/
DiagnosticTag.Deprecated = 2;
})(DiagnosticTag = exports.DiagnosticTag || (exports.DiagnosticTag = {}));
/**
* The CodeDescription namespace provides functions to deal with descriptions for diagnostic codes.
*
* @since 3.16.0
*/
var CodeDescription;
(function (CodeDescription) {
function is(value) {
var candidate = value;
return candidate !== undefined && candidate !== null && Is.string(candidate.href);
}
CodeDescription.is = is;
})(CodeDescription = exports.CodeDescription || (exports.CodeDescription = {}));
/**
* The Diagnostic namespace provides helper functions to work with
* [Diagnostic](#Diagnostic) literals.
*/
var Diagnostic;
(function (Diagnostic) {
/**
* Creates a new Diagnostic literal.
*/
function create(range, message, severity, code, source, relatedInformation) {
var result = { range: range, message: message };
if (Is.defined(severity)) {
result.severity = severity;
}
if (Is.defined(code)) {
result.code = code;
}
if (Is.defined(source)) {
result.source = source;
}
if (Is.defined(relatedInformation)) {
result.relatedInformation = relatedInformation;
}
return result;
}
Diagnostic.create = create;
/**
* Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
*/
function is(value) {
var _a;
var candidate = value;
return Is.defined(candidate)
&& Range.is(candidate.range)
&& Is.string(candidate.message)
&& (Is.number(candidate.severity) || Is.undefined(candidate.severity))
&& (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
&& (Is.undefined(candidate.codeDescription) || (Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)))
&& (Is.string(candidate.source) || Is.undefined(candidate.source))
&& (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
}
Diagnostic.is = is;
})(Diagnostic = exports.Diagnostic || (exports.Diagnostic = {}));
/**
* The Command namespace provides helper functions to work with
* [Command](#Command) literals.
*/
var Command;
(function (Command) {
/**
* Creates a new Command literal.
*/
function create(title, command) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var result = { title: title, command: command };
if (Is.defined(args) && args.length > 0) {
result.arguments = args;
}
return result;
}
Command.create = create;
/**
* Checks whether the given literal conforms to the [Command](#Command) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
}
Command.is = is;
})(Command = exports.Command || (exports.Command = {}));
/**
* The TextEdit namespace provides helper function to create replace,
* insert and delete edits more easily.
*/
var TextEdit;
(function (TextEdit) {
/**
* Creates a replace text edit.
* @param range The range of text to be replaced.
* @param newText The new text.
*/
function replace(range, newText) {
return { range: range, newText: newText };
}
TextEdit.replace = replace;
/**
* Creates a insert text edit.
* @param position The position to insert the text at.
* @param newText The text to be inserted.
*/
function insert(position, newText) {
return { range: { start: position, end: position }, newText: newText };
}
TextEdit.insert = insert;
/**
* Creates a delete text edit.
* @param range The range of text to be deleted.
*/
function del(range) {
return { range: range, newText: '' };
}
TextEdit.del = del;
function is(value) {
var candidate = value;
return Is.objectLiteral(candidate)
&& Is.string(candidate.newText)
&& Range.is(candidate.range);
}
TextEdit.is = is;
})(TextEdit = exports.TextEdit || (exports.TextEdit = {}));
var ChangeAnnotation;
(function (ChangeAnnotation) {
function create(label, needsConfirmation, description) {
var result = { label: label };
if (needsConfirmation !== undefined) {
result.needsConfirmation = needsConfirmation;
}
if (description !== undefined) {
result.description = description;
}
return result;
}
ChangeAnnotation.create = create;
function is(value) {
var candidate = value;
return candidate !== undefined && Is.objectLiteral(candidate) && Is.string(candidate.label) &&
(Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === undefined) &&
(Is.string(candidate.description) || candidate.description === undefined);
}
ChangeAnnotation.is = is;
})(ChangeAnnotation = exports.ChangeAnnotation || (exports.ChangeAnnotation = {}));
var ChangeAnnotationIdentifier;
(function (ChangeAnnotationIdentifier) {
function is(value) {
var candidate = value;
return typeof candidate === 'string';
}
ChangeAnnotationIdentifier.is = is;
})(ChangeAnnotationIdentifier = exports.ChangeAnnotationIdentifier || (exports.ChangeAnnotationIdentifier = {}));
var AnnotatedTextEdit;
(function (AnnotatedTextEdit) {
/**
* Creates an annotated replace text edit.
*
* @param range The range of text to be replaced.
* @param newText The new text.
* @param annotation The annotation.
*/
function replace(range, newText, annotation) {
return { range: range, newText: newText, annotationId: annotation };
}
AnnotatedTextEdit.replace = replace;
/**
* Creates an annotated insert text edit.
*
* @param position The position to insert the text at.
* @param newText The text to be inserted.
* @param annotation The annotation.
*/
function insert(position, newText, annotation) {
return { range: { start: position, end: position }, newText: newText, annotationId: annotation };
}
AnnotatedTextEdit.insert = insert;
/**
* Creates an annotated delete text edit.
*
* @param range The range of text to be deleted.
* @param annotation The annotation.
*/
function del(range, annotation) {
return { range: range, newText: '', annotationId: annotation };
}
AnnotatedTextEdit.del = del;
function is(value) {
var candidate = value;
return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
}
AnnotatedTextEdit.is = is;
})(AnnotatedTextEdit = exports.AnnotatedTextEdit || (exports.AnnotatedTextEdit = {}));
/**
* The TextDocumentEdit namespace provides helper function to create
* an edit that manipulates a text document.
*/
var TextDocumentEdit;
(function (TextDocumentEdit) {
/**
* Creates a new `TextDocumentEdit`
*/
function create(textDocument, edits) {
return { textDocument: textDocument, edits: edits };
}
TextDocumentEdit.create = create;
function is(value) {
var candidate = value;
return Is.defined(candidate)
&& OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument)
&& Array.isArray(candidate.edits);
}
TextDocumentEdit.is = is;
})(TextDocumentEdit = exports.TextDocumentEdit || (exports.TextDocumentEdit = {}));
var CreateFile;
(function (CreateFile) {
function create(uri, options, annotation) {
var result = {
kind: 'create',
uri: uri
};
if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
result.options = options;
}
if (annotation !== undefined) {
result.annotationId = annotation;
}
return result;
}
CreateFile.create = create;
function is(value) {
var candidate = value;
return candidate && candidate.kind === 'create' && Is.string(candidate.uri) && (candidate.options === undefined ||
((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));
}
CreateFile.is = is;
})(CreateFile = exports.CreateFile || (exports.CreateFile = {}));
var RenameFile;
(function (RenameFile) {
function create(oldUri, newUri, options, annotation) {
var result = {
kind: 'rename',
oldUri: oldUri,
newUri: newUri
};
if (options !== undefined && (options.overwrite !== undefined || options.ignoreIfExists !== undefined)) {
result.options = options;
}
if (annotation !== undefined) {
result.annotationId = annotation;
}
return result;
}
RenameFile.create = create;
function is(value) {
var candidate = value;
return candidate && candidate.kind === 'rename' && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === undefined ||
((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));
}
RenameFile.is = is;
})(RenameFile = exports.RenameFile || (exports.RenameFile = {}));
var DeleteFile;
(function (DeleteFile) {
function create(uri, options, annotation) {
var result = {
kind: 'delete',
uri: uri
};
if (options !== undefined && (options.recursive !== undefined || options.ignoreIfNotExists !== undefined)) {
result.options = options;
}
if (annotation !== undefined) {
result.annotationId = annotation;
}
return result;
}
DeleteFile.create = create;
function is(value) {
var candidate = value;
return candidate && candidate.kind === 'delete' && Is.string(candidate.uri) && (candidate.options === undefined ||
((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));
}
DeleteFile.is = is;
})(DeleteFile = exports.DeleteFile || (exports.DeleteFile = {}));
var WorkspaceEdit;
(function (WorkspaceEdit) {
function is(value) {
var candidate = value;
return candidate &&
(candidate.changes !== undefined || candidate.documentChanges !== undefined) &&
(candidate.documentChanges === undefined || candidate.documentChanges.every(function (change) {
if (Is.string(change.kind)) {
return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
}
else {
return TextDocumentEdit.is(change);
}
}));
}
WorkspaceEdit.is = is;
})(WorkspaceEdit = exports.WorkspaceEdit || (exports.WorkspaceEdit = {}));
var TextEditChangeImpl = /** @class */ (function () {
function TextEditChangeImpl(edits, changeAnnotations) {
this.edits = edits;
this.changeAnnotations = changeAnnotations;
}
TextEditChangeImpl.prototype.insert = function (position, newText, annotation) {
var edit;
var id;
if (annotation === undefined) {
edit = TextEdit.insert(position, newText);
}
else if (ChangeAnnotationIdentifier.is(annotation)) {
id = annotation;
edit = AnnotatedTextEdit.insert(position, newText, annotation);
}
else {
this.assertChangeAnnotations(this.changeAnnotations);
id = this.changeAnnotations.manage(annotation);
edit = AnnotatedTextEdit.insert(position, newText, id);
}
this.edits.push(edit);
if (id !== undefined) {
return id;
}
};
TextEditChangeImpl.prototype.replace = function (range, newText, annotation) {
var edit;
var id;
if (annotation === undefined) {
edit = TextEdit.replace(range, newText);
}
else if (ChangeAnnotationIdentifier.is(annotation)) {
id = annotation;
edit = AnnotatedTextEdit.replace(range, newText, annotation);
}
else {
this.assertChangeAnnotations(this.changeAnnotations);
id = this.changeAnnotations.manage(annotation);
edit = AnnotatedTextEdit.replace(range, newText, id);
}
this.edits.push(edit);
if (id !== undefined) {
return id;
}
};
TextEditChangeImpl.prototype.delete = function (range, annotation) {
var edit;
var id;
if (annotation === undefined) {
edit = TextEdit.del(range);
}
else if (ChangeAnnotationIdentifier.is(annotation)) {
id = annotation;
edit = AnnotatedTextEdit.del(range, annotation);
}
else {
this.assertChangeAnnotations(this.changeAnnotations);
id = this.changeAnnotations.manage(annotation);
edit = AnnotatedTextEdit.del(range, id);
}
this.edits.push(edit);
if (id !== undefined) {
return id;
}
};
TextEditChangeImpl.prototype.add = function (edit) {
this.edits.push(edit);
};
TextEditChangeImpl.prototype.all = function () {
return this.edits;
};
TextEditChangeImpl.prototype.clear = function () {
this.edits.splice(0, this.edits.length);
};
TextEditChangeImpl.prototype.assertChangeAnnotations = function (value) {
if (value === undefined) {
throw new Error("Text edit change is not configured to manage change annotations.");
}
};
return TextEditChangeImpl;
}());
/**
* A helper class
*/
var ChangeAnnotations = /** @class */ (function () {
function ChangeAnnotations(annotations) {
this._annotations = annotations === undefined ? Object.create(null) : annotations;
this._counter = 0;
this._size = 0;
}
ChangeAnnotations.prototype.all = function () {
return this._annotations;
};
Object.defineProperty(ChangeAnnotations.prototype, "size", {
get: function () {
return this._size;
},
enumerable: false,
configurable: true
});
ChangeAnnotations.prototype.manage = function (idOrAnnotation, annotation) {
var id;
if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
id = idOrAnnotation;
}
else {
id = this.nextId();
annotation = idOrAnnotation;
}
if (this._annotations[id] !== undefined) {
throw new Error("Id " + id + " is already in use.");
}
if (annotation === undefined) {
throw new Error("No annotation provided for id " + id);
}
this._annotations[id] = annotation;
this._size++;
return id;
};
ChangeAnnotations.prototype.nextId = function () {
this._counter++;
return this._counter.toString();
};
return ChangeAnnotations;
}());
/**
* A workspace change helps constructing changes to a workspace.
*/
var WorkspaceChange = /** @class */ (function () {
function WorkspaceChange(workspaceEdit) {
var _this = this;
this._textEditChanges = Object.create(null);
if (workspaceEdit !== undefined) {
this._workspaceEdit = workspaceEdit;
if (workspaceEdit.documentChanges) {
this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
workspaceEdit.changeAnnotations = this._changeAnnotations.all();
workspaceEdit.documentChanges.forEach(function (change) {
if (TextDocumentEdit.is(change)) {
var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
_this._textEditChanges[change.textDocument.uri] = textEditChange;
}
});
}
else if (workspaceEdit.changes) {
Object.keys(workspaceEdit.changes).forEach(function (key) {
var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
_this._textEditChanges[key] = textEditChange;
});
}
}
else {
this._workspaceEdit = {};
}
}
Object.defineProperty(WorkspaceChange.prototype, "edit", {
/**
* Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
* use to be returned from a workspace edit operation like rename.
*/
get: function () {
this.initDocumentChanges();
if (this._changeAnnotations !== undefined) {
if (this._changeAnnotations.size === 0) {
this._workspaceEdit.changeAnnotations = undefined;
}
else {
this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
}
}
return this._workspaceEdit;
},
enumerable: false,
configurable: true
});
WorkspaceChange.prototype.getTextEditChange = function (key) {
if (OptionalVersionedTextDocumentIdentifier.is(key)) {
this.initDocumentChanges();
if (this._workspaceEdit.documentChanges === undefined) {
throw new Error('Workspace edit is not configured for document changes.');
}
var textDocument = { uri: key.uri, version: key.version };
var result = this._textEditChanges[textDocument.uri];
if (!result) {
var edits = [];
var textDocumentEdit = {
textDocument: textDocument,
edits: edits
};
this._workspaceEdit.documentChanges.push(textDocumentEdit);
result = new TextEditChangeImpl(edits, this._changeAnnotations);
this._textEditChanges[textDocument.uri] = result;
}
return result;
}
else {
this.initChanges();
if (this._workspaceEdit.changes === undefined) {
throw new Error('Workspace edit is not configured for normal text edit changes.');
}
var result = this._textEditChanges[key];
if (!result) {
var edits = [];
this._workspaceEdit.changes[key] = edits;
result = new TextEditChangeImpl(edits);
this._textEditChanges[key] = result;
}
return result;
}
};
WorkspaceChange.prototype.initDocumentChanges = function () {
if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
this._changeAnnotations = new ChangeAnnotations();
this._workspaceEdit.documentChanges = [];
this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
}
};
WorkspaceChange.prototype.initChanges = function () {
if (this._workspaceEdit.documentChanges === undefined && this._workspaceEdit.changes === undefined) {
this._workspaceEdit.changes = Object.create(null);
}
};
WorkspaceChange.prototype.createFile = function (uri, optionsOrAnnotation, options) {
this.initDocumentChanges();
if (this._workspaceEdit.documentChanges === undefined) {
throw new Error('Workspace edit is not configured for document changes.');
}
var annotation;
if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
annotation = optionsOrAnnotation;
}
else {
options = optionsOrAnnotation;
}
var operation;
var id;
if (annotation === undefined) {
operation = CreateFile.create(uri, options);
}
else {
id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
operation = CreateFile.create(uri, options, id);
}
this._workspaceEdit.documentChanges.push(operation);
if (id !== undefined) {
return id;
}
};
WorkspaceChange.prototype.renameFile = function (oldUri, newUri, optionsOrAnnotation, options) {
this.initDocumentChanges();
if (this._workspaceEdit.documentChanges === undefined) {
throw new Error('Workspace edit is not configured for document changes.');
}
var annotation;
if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
annotation = optionsOrAnnotation;
}
else {
options = optionsOrAnnotation;
}
var operation;
var id;
if (annotation === undefined) {
operation = RenameFile.create(oldUri, newUri, options);
}
else {
id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
operation = RenameFile.create(oldUri, newUri, options, id);
}
this._workspaceEdit.documentChanges.push(operation);
if (id !== undefined) {
return id;
}
};
WorkspaceChange.prototype.deleteFile = function (uri, optionsOrAnnotation, options) {
this.initDocumentChanges();
if (this._workspaceEdit.documentChanges === undefined) {
throw new Error('Workspace edit is not configured for document changes.');
}
var annotation;
if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
annotation = optionsOrAnnotation;
}
else {
options = optionsOrAnnotation;
}
var operation;
var id;
if (annotation === undefined) {
operation = DeleteFile.create(uri, options);
}
else {
id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
operation = DeleteFile.create(uri, options, id);
}
this._workspaceEdit.documentChanges.push(operation);
if (id !== undefined) {
return id;
}
};
return WorkspaceChange;
}());
exports.WorkspaceChange = WorkspaceChange;
/**
* The TextDocumentIdentifier namespace provides helper functions to work with
* [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
*/
var TextDocumentIdentifier;
(function (TextDocumentIdentifier) {
/**
* Creates a new TextDocumentIdentifier literal.
* @param uri The document's uri.
*/
function create(uri) {
return { uri: uri };
}
TextDocumentIdentifier.create = create;
/**
* Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Is.string(candidate.uri);
}
TextDocumentIdentifier.is = is;
})(TextDocumentIdentifier = exports.TextDocumentIdentifier || (exports.TextDocumentIdentifier = {}));
/**
* The VersionedTextDocumentIdentifier namespace provides helper functions to work with
* [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
*/
var VersionedTextDocumentIdentifier;
(function (VersionedTextDocumentIdentifier) {
/**
* Creates a new VersionedTextDocumentIdentifier literal.
* @param uri The document's uri.
* @param uri The document's text.
*/
function create(uri, version) {
return { uri: uri, version: version };
}
VersionedTextDocumentIdentifier.create = create;
/**
* Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
}
VersionedTextDocumentIdentifier.is = is;
})(VersionedTextDocumentIdentifier = exports.VersionedTextDocumentIdentifier || (exports.VersionedTextDocumentIdentifier = {}));
/**
* The OptionalVersionedTextDocumentIdentifier namespace provides helper functions to work with
* [OptionalVersionedTextDocumentIdentifier](#OptionalVersionedTextDocumentIdentifier) literals.
*/
var OptionalVersionedTextDocumentIdentifier;
(function (OptionalVersionedTextDocumentIdentifier) {
/**
* Creates a new OptionalVersionedTextDocumentIdentifier literal.
* @param uri The document's uri.
* @param uri The document's text.
*/
function create(uri, version) {
return { uri: uri, version: version };
}
OptionalVersionedTextDocumentIdentifier.create = create;
/**
* Checks whether the given literal conforms to the [OptionalVersionedTextDocumentIdentifier](#OptionalVersionedTextDocumentIdentifier) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
}
OptionalVersionedTextDocumentIdentifier.is = is;
})(OptionalVersionedTextDocumentIdentifier = exports.OptionalVersionedTextDocumentIdentifier || (exports.OptionalVersionedTextDocumentIdentifier = {}));
/**
* The TextDocumentItem namespace provides helper functions to work with
* [TextDocumentItem](#TextDocumentItem) literals.
*/
var TextDocumentItem;
(function (TextDocumentItem) {
/**
* Creates a new TextDocumentItem literal.
* @param uri The document's uri.
* @param languageId The document's language identifier.
* @param version The document's version number.
* @param text The document's text.
*/
function create(uri, languageId, version, text) {
return { uri: uri, languageId: languageId, version: version, text: text };
}
TextDocumentItem.create = create;
/**
* Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
*/
function is(value) {
var candidate = value;
return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
}
TextDocumentItem.is = is;
})(TextDocumentItem = exports.TextDocumentItem || (exports.TextDocumentItem = {}));
/**
* Describes the content type that a client supports in various
* result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
*
* Please note that `MarkupKinds` must not start with a `$`. This kinds
* are reserved for internal usage.
*/
var MarkupKind;
(function (MarkupKind) {
/**
* Plain text is supported as a content format
*/
MarkupKind.PlainText = 'plaintext';
/**
* Markdown is supported as a content format
*/
MarkupKind.Markdown = 'markdown';
})(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
(function (MarkupKind) {
/**
* Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
*/
function is(value) {
var candidate = value;
return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
}
MarkupKind.is = is;
})(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
var MarkupContent;
(function (MarkupContent) {
/**
* Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
*/
function is(value) {
var candidate = value;
return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
}
MarkupContent.is = is;
})(MarkupContent = exports.MarkupContent || (exports.MarkupContent =