"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestTag = exports.TestMessageStackFrame = exports.TestMessage = exports.CodeActionTriggerKind = exports.InlayHintKind = exports.InlayHintLabelPart = exports.InlayHint = exports.InlineValueContext = exports.InlineValue = exports.EvaluatableExpression = exports.DefinitionLink = exports.ViewColumn = exports.SIDE_GROUP = exports.ACTIVE_GROUP = exports.SignatureHelp = exports.SignatureInformation = exports.ParameterInformation = exports.CallHierarchyOutgoingCall = exports.CallHierarchyIncomingCall = exports.TypeHierarchyItem = exports.CallHierarchyItem = exports.ProgressLocation = exports.Position = exports.WorkspaceSymbol = exports.CompletionItemTag = exports.CompletionItem = exports.CompletionItemKind = exports.SymbolTag = exports.SymbolKind = exports.GlobPattern = exports.DecorationRangeBehavior = exports.WorkspaceEdit = exports.ThemableDecorationAttachmentRenderOptions = exports.ThemableDecorationRenderOptions = exports.DecorationRenderOptions = exports.TextEditorLineNumbersStyle = exports.Selection = exports.DocumentLink = exports.Diagnostic = exports.DocumentHighlight = exports.Color = exports.ColorPresentation = exports.SnippetTextEdit = exports.TextEdit = exports.EndOfLine = exports.location = exports.Hover = exports.MarkdownString = exports.Range = exports.TextEditorOpenOptions = void 0;
exports.NotebookCellKind = exports.NotebookCellExecutionSummary = exports.NotebookRange = exports.ChatMessageRole = exports.ChatMessage = exports.ChatFollowup = exports.ChatReplyFollowup = exports.DataTransfer = exports.DataTransferItem = exports.DocumentSelector = exports.TestResults = exports.TestItem = void 0;
exports.toPosition = toPosition;
exports.fromPosition = fromPosition;
exports.fromRange = fromRange;
exports.toRange = toRange;
exports.fromMarkdown = fromMarkdown;
exports.fromManyMarkdown = fromManyMarkdown;
exports.fromHover = fromHover;
exports.fromLanguageSelector = fromLanguageSelector;
exports.fromGlobPattern = fromGlobPattern;
exports.fromLocation = fromLocation;
exports.toLocation = toLocation;
exports.fromTextEdit = fromTextEdit;
exports.fromDefinitionLink = fromDefinitionLink;
exports.fromFoldingRange = fromFoldingRange;
exports.fromFoldingRangeKind = fromFoldingRangeKind;
exports.fromSelectionRange = fromSelectionRange;
exports.fromColor = fromColor;
exports.toColor = toColor;
exports.fromColorPresentation = fromColorPresentation;
exports.fromDocumentHighlightKind = fromDocumentHighlightKind;
exports.toSelection = toSelection;
exports.fromSelection = fromSelection;
exports.fromDocumentLink = fromDocumentLink;
exports.pathOrURIToURI = pathOrURIToURI;
exports.fromDocumentSymbol = fromDocumentSymbol;
exports.fromSymbolInformation = fromSymbolInformation;
exports.toSymbolInformation = toSymbolInformation;
exports.viewColumnToResourceOpenOptions = viewColumnToResourceOpenOptions;
exports.fromFileStat = fromFileStat;
exports.toFileStat = toFileStat;
exports.isLikelyVscodeRange = isLikelyVscodeRange;
const tslib_1 = require("tslib");
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
const utils_1 = require("@opensumi/ide-components/lib/utils");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const notebook_1 = require("@opensumi/ide-editor/lib/common/notebook");
const ide_file_service_1 = require("@opensumi/ide-file-service");
const common_1 = require("@opensumi/ide-testing/lib/common");
const enums_1 = require("./enums");
const types = tslib_1.__importStar(require("./ext-types"));
const model = tslib_1.__importStar(require("./model.api"));
const models_1 = require("./models");
const testApi_1 = require("./testing/testApi");
const { parse } = ide_core_common_1.path;
const { cloneAndChange } = ide_core_common_1.objects;
const { coalesce, asArray } = ide_core_common_1.arrays;
var TextEditorOpenOptions;
(function (TextEditorOpenOptions) {
    function from(options) {
        if (options) {
            return {
                pinned: typeof options.preview === 'boolean' ? !options.preview : undefined,
                inactive: options.background,
                preserveFocus: options.preserveFocus,
                selection: typeof options.selection === 'object' ? Range.from(options.selection) : undefined,
                override: typeof options.override === 'boolean' ? false : undefined,
            };
        }
        return undefined;
    }
    TextEditorOpenOptions.from = from;
})(TextEditorOpenOptions || (exports.TextEditorOpenOptions = TextEditorOpenOptions = {}));
function toPosition(position) {
    return new types.Position(position.lineNumber - 1, position.column - 1);
}
function fromPosition(position) {
    return { lineNumber: position.line + 1, column: position.character + 1 };
}
var Range;
(function (Range) {
    function from(range) {
        if (!range) {
            return undefined;
        }
        const { start, end } = range;
        return {
            startLineNumber: start.line + 1,
            startColumn: start.character + 1,
            endLineNumber: end.line + 1,
            endColumn: end.character + 1,
        };
    }
    Range.from = from;
    function to(range) {
        if (!range) {
            return undefined;
        }
        const { startLineNumber, startColumn, endLineNumber, endColumn } = range;
        return new types.Range(startLineNumber - 1, startColumn - 1, endLineNumber - 1, endColumn - 1);
    }
    Range.to = to;
})(Range || (exports.Range = Range = {}));
function fromRange(range) {
    return Range.from(range);
}
/**
 * @deprecated 之后使用 vscode 的形式 Range.to 代替
 * @param range
 */
function toRange(range) {
    return Range.to(range);
}
function isCodeblock(thing) {
    return (thing &&
        typeof thing === 'object' &&
        typeof thing.language === 'string' &&
        typeof thing.value === 'string');
}
function fromMarkdown(markup) {
    if (isCodeblock(markup)) {
        const { language, value } = markup;
        return { value: '```' + language + '\n' + value + '\n```\n' };
    }
    else if ((0, models_1.isMarkdownString)(markup)) {
        return markup;
    }
    else if (typeof markup === 'string') {
        return { value: markup };
    }
    else {
        return { value: '' };
    }
}
var MarkdownString;
(function (MarkdownString) {
    function fromMany(markup) {
        return markup.map(MarkdownString.from);
    }
    MarkdownString.fromMany = fromMany;
    function isCodeblock(thing) {
        return (thing &&
            typeof thing === 'object' &&
            typeof thing.language === 'string' &&
            typeof thing.value === 'string');
    }
    function from(markup) {
        let res;
        if (isCodeblock(markup)) {
            const { language, value } = markup;
            res = { value: '```' + language + '\n' + value + '\n```\n' };
        }
        else if (types.MarkdownString.isMarkdownString(markup)) {
            res = {
                value: markup.value,
                isTrusted: markup.isTrusted,
                supportHtml: markup.supportHtml,
                supportThemeIcons: markup.supportThemeIcons,
                baseUri: markup.baseUri,
            };
        }
        else if (typeof markup === 'string') {
            res = { value: markup };
        }
        else {
            res = { value: '' };
        }
        // extract uris into a separate object
        const resUris = Object.create(null);
        res.uris = resUris;
        const collectUri = (href) => {
            try {
                let uri = ide_core_common_1.Uri.parse(href);
                uri = uri.with({ query: _uriMassage(uri.query, resUris) });
                resUris[href] = uri;
            }
            catch (e) {
                // ignore
            }
            return '';
        };
        const renderer = (0, utils_1.createMarkedRenderer)();
        renderer.link = ({ href }) => (href ? collectUri(href) : '');
        renderer.image = ({ href }) => (href ? collectUri((0, models_1.parseHrefAndDimensions)(href).href) : '');
        (0, utils_1.toMarkdownHtml)(res.value, { renderer });
        return res;
    }
    MarkdownString.from = from;
    function _uriMassage(part, bucket) {
        if (!part) {
            return part;
        }
        let data;
        try {
            data = parse(part);
        }
        catch (e) {
            // ignore
        }
        if (!data) {
            return part;
        }
        let changed = false;
        data = cloneAndChange(data, (value) => {
            if (ide_core_common_1.Uri.isUri(value)) {
                const key = `__uri_${(0, ide_core_common_1.randomString)(6)}`;
                bucket[key] = value;
                changed = true;
                return key;
            }
            else {
                return undefined;
            }
        });
        if (!changed) {
            return part;
        }
        return JSON.stringify(data);
    }
    function to(value) {
        const result = new types.MarkdownString(value.value, value.supportThemeIcons);
        result.isTrusted = value.isTrusted;
        result.supportHtml = value.supportHtml;
        result.baseUri = value.baseUri ? ide_core_common_1.URI.revive(value.baseUri) : undefined;
        return result;
    }
    MarkdownString.to = to;
    function fromStrict(value) {
        if (!value) {
            return undefined;
        }
        return typeof value === 'string' ? value : MarkdownString.from(value);
    }
    MarkdownString.fromStrict = fromStrict;
})(MarkdownString || (exports.MarkdownString = MarkdownString = {}));
/**
 * @deprecated
 */
function fromManyMarkdown(markup) {
    return markup.map(fromMarkdown);
}
var Hover;
(function (Hover) {
    function from(hover) {
        return {
            range: Range.from(hover.range),
            contents: MarkdownString.fromMany(hover.contents),
        };
    }
    Hover.from = from;
    function to(info) {
        return new types.Hover(info.contents.map(MarkdownString.to), Range.to(info.range));
    }
    Hover.to = to;
})(Hover || (exports.Hover = Hover = {}));
function fromHover(hover) {
    return {
        range: hover.range && fromRange(hover.range),
        contents: fromManyMarkdown(hover.contents),
    };
}
function fromLanguageSelector(selector) {
    if (!selector) {
        return undefined;
    }
    else if (Array.isArray(selector)) {
        return selector.map(fromLanguageSelector);
    }
    else if (typeof selector === 'string') {
        return selector;
    }
    else {
        return {
            language: selector.language,
            scheme: selector.scheme,
            pattern: fromGlobPattern(selector.pattern),
        };
    }
}
function fromGlobPattern(pattern) {
    if (typeof pattern === 'string') {
        return pattern;
    }
    if (isRelativePattern(pattern)) {
        return new types.RelativePattern(pattern.base, pattern.pattern);
    }
    return pattern;
}
function isRelativePattern(obj) {
    const rp = obj;
    return rp && typeof rp.base === 'string' && typeof rp.pattern === 'string';
}
var location;
(function (location) {
    function from(value) {
        return {
            range: value.range && Range.from(value.range),
            uri: value.uri,
        };
    }
    location.from = from;
    function to(value) {
        return new types.Location(value.uri, Range.to(value.range));
    }
    location.to = to;
})(location || (exports.location = location = {}));
/**
 * @deprecated
 */
function fromLocation(value) {
    return {
        range: value.range && fromRange(value.range),
        uri: value.uri,
    };
}
/**
 * @deprecated
 */
function toLocation(value) {
    return new types.Location(value.uri, toRange(value.range));
}
var EndOfLine;
(function (EndOfLine) {
    function from(eol) {
        if (eol === types.EndOfLine.CRLF) {
            return 1 /* EndOfLineSequence.CRLF */;
        }
        else if (eol === types.EndOfLine.LF) {
            return 0 /* EndOfLineSequence.LF */;
        }
        return undefined;
    }
    EndOfLine.from = from;
    function to(eol) {
        if (eol === 1 /* EndOfLineSequence.CRLF */) {
            return types.EndOfLine.CRLF;
        }
        else if (eol === 0 /* EndOfLineSequence.LF */) {
            return types.EndOfLine.LF;
        }
        return undefined;
    }
    EndOfLine.to = to;
})(EndOfLine || (exports.EndOfLine = EndOfLine = {}));
var TextEdit;
(function (TextEdit) {
    function from(edit) {
        return {
            text: edit.newText,
            eol: edit.newEol && EndOfLine.from(edit.newEol),
            range: Range.from(edit.range),
        };
    }
    TextEdit.from = from;
    function to(edit) {
        const result = new types.TextEdit(Range.to(edit.range), edit.text);
        result.newEol = (typeof edit.eol === 'undefined' ? undefined : EndOfLine.to(edit.eol));
        return result;
    }
    TextEdit.to = to;
})(TextEdit || (exports.TextEdit = TextEdit = {}));
var SnippetTextEdit;
(function (SnippetTextEdit) {
    function from(edit) {
        return {
            text: edit.snippet.value,
            range: fromRange(edit.range),
            insertAsSnippet: true,
        };
    }
    SnippetTextEdit.from = from;
})(SnippetTextEdit || (exports.SnippetTextEdit = SnippetTextEdit = {}));
function fromTextEdit(edit) {
    return {
        text: edit.newText,
        range: fromRange(edit.range),
    };
}
function fromDefinitionLink(definitionLink) {
    return {
        uri: definitionLink.targetUri,
        range: fromRange(definitionLink.targetRange),
        origin: definitionLink.originSelectionRange ? fromRange(definitionLink.originSelectionRange) : undefined,
        selectionRange: definitionLink.targetSelectionRange ? fromRange(definitionLink.targetSelectionRange) : undefined,
    };
}
function fromFoldingRange(foldingRange) {
    const range = {
        start: foldingRange.start + 1,
        end: foldingRange.end + 1,
    };
    if (foldingRange.kind) {
        range.kind = fromFoldingRangeKind(foldingRange.kind);
    }
    return range;
}
function fromFoldingRangeKind(kind) {
    if (kind) {
        switch (kind) {
            case types.FoldingRangeKind.Comment:
                return model.FoldingRangeKind.Comment;
            case types.FoldingRangeKind.Imports:
                return model.FoldingRangeKind.Imports;
            case types.FoldingRangeKind.Region:
                return model.FoldingRangeKind.Region;
        }
    }
    return undefined;
}
function fromSelectionRange(obj) {
    return { range: fromRange(obj.range) };
}
var ColorPresentation;
(function (ColorPresentation) {
    function to(colorPresentation) {
        const cp = new types.ColorPresentation(colorPresentation.label);
        if (colorPresentation.textEdit) {
            cp.textEdit = TextEdit.to(colorPresentation.textEdit);
        }
        if (colorPresentation.additionalTextEdits) {
            cp.additionalTextEdits = colorPresentation.additionalTextEdits.map((value) => TextEdit.to(value));
        }
        return cp;
    }
    ColorPresentation.to = to;
    function from(colorPresentation) {
        return {
            label: colorPresentation.label,
            textEdit: colorPresentation.textEdit ? TextEdit.from(colorPresentation.textEdit) : undefined,
            additionalTextEdits: colorPresentation.additionalTextEdits
                ? colorPresentation.additionalTextEdits.map((value) => TextEdit.from(value))
                : undefined,
        };
    }
    ColorPresentation.from = from;
})(ColorPresentation || (exports.ColorPresentation = ColorPresentation = {}));
var Color;
(function (Color) {
    function to(c) {
        return new types.Color(c[0], c[1], c[2], c[3]);
    }
    Color.to = to;
    function from(color) {
        return [color.red, color.green, color.blue, color.alpha];
    }
    Color.from = from;
})(Color || (exports.Color = Color = {}));
/**
 * @deprecated
 */
function fromColor(color) {
    return [color.red, color.green, color.blue, color.alpha];
}
function toColor(color) {
    return new types.Color(color[0], color[1], color[2], color[3]);
}
/**
 * @description
 * @param colorPresentation
 */
function fromColorPresentation(colorPresentation) {
    return {
        label: colorPresentation.label,
        textEdit: colorPresentation.textEdit ? fromTextEdit(colorPresentation.textEdit) : undefined,
        additionalTextEdits: colorPresentation.additionalTextEdits
            ? colorPresentation.additionalTextEdits.map((value) => fromTextEdit(value))
            : undefined,
    };
}
var DocumentHighlight;
(function (DocumentHighlight) {
    function from(documentHighlight) {
        return {
            range: fromRange(documentHighlight.range),
            kind: documentHighlight.kind,
        };
    }
    DocumentHighlight.from = from;
    function to(occurrence) {
        return new types.DocumentHighlight(toRange(occurrence.range), occurrence.kind);
    }
    DocumentHighlight.to = to;
})(DocumentHighlight || (exports.DocumentHighlight = DocumentHighlight = {}));
function fromDocumentHighlightKind(kind) {
    switch (kind) {
        case types.DocumentHighlightKind.Text:
            return model.DocumentHighlightKind.Text;
        case types.DocumentHighlightKind.Read:
            return model.DocumentHighlightKind.Read;
        case types.DocumentHighlightKind.Write:
            return model.DocumentHighlightKind.Write;
    }
    return model.DocumentHighlightKind.Text;
}
var Diagnostic;
(function (Diagnostic) {
    function convertCode(code) {
        if (typeof code === 'number') {
            return String(code);
        }
        else if (typeof code === 'object') {
            return String(code.value);
        }
        else {
            return code;
        }
    }
    Diagnostic.convertCode = convertCode;
    function toMarker(diagnostic) {
        return {
            code: convertCode(diagnostic.code),
            codeHref: typeof diagnostic.code === 'object' ? ide_core_common_1.Uri.from(diagnostic.code.target) : undefined,
            severity: convertSeverity(diagnostic.severity),
            message: diagnostic.message,
            source: diagnostic.source,
            startLineNumber: diagnostic.range.start.line + 1,
            startColumn: diagnostic.range.start.character + 1,
            endLineNumber: diagnostic.range.end.line + 1,
            endColumn: diagnostic.range.end.character + 1,
            relatedInformation: convertRelatedInformation(diagnostic.relatedInformation),
            tags: convertTags(diagnostic.tags),
        };
    }
    Diagnostic.toMarker = toMarker;
    function convertSeverity(severity) {
        switch (severity) {
            case types.DiagnosticSeverity.Error:
                return ide_core_common_1.MarkerSeverity.Error;
            case types.DiagnosticSeverity.Warning:
                return ide_core_common_1.MarkerSeverity.Warning;
            case types.DiagnosticSeverity.Information:
                return ide_core_common_1.MarkerSeverity.Info;
            case types.DiagnosticSeverity.Hint:
                return ide_core_common_1.MarkerSeverity.Hint;
        }
    }
    Diagnostic.convertSeverity = convertSeverity;
    function convertRelatedInformation(diagnosticsRelatedInformation) {
        if (!diagnosticsRelatedInformation) {
            return undefined;
        }
        const relatedInformation = [];
        for (const item of diagnosticsRelatedInformation) {
            relatedInformation.push({
                resource: item.location.uri.toString(),
                message: item.message,
                startLineNumber: item.location.range.start.line + 1,
                startColumn: item.location.range.start.character + 1,
                endLineNumber: item.location.range.end.line + 1,
                endColumn: item.location.range.end.character + 1,
            });
        }
        return relatedInformation;
    }
    Diagnostic.convertRelatedInformation = convertRelatedInformation;
    function convertTags(tags) {
        if (!tags) {
            return undefined;
        }
        const markerTags = [];
        for (const tag of tags) {
            switch (tag) {
                case types.DiagnosticTag.Unnecessary:
                    markerTags.push(1 /* MarkerTag.Unnecessary */);
                    break;
                case types.DiagnosticTag.Deprecated:
                    markerTags.push(2 /* MarkerTag.Deprecated */);
                    break;
            }
        }
        return markerTags;
    }
})(Diagnostic || (exports.Diagnostic = Diagnostic = {}));
function toSelection(selection) {
    const { selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn } = selection;
    const start = new types.Position(selectionStartLineNumber - 1, selectionStartColumn - 1);
    const end = new types.Position(positionLineNumber - 1, positionColumn - 1);
    return new types.Selection(start, end);
}
function fromSelection(selection) {
    const { active, anchor } = selection;
    return {
        selectionStartLineNumber: anchor.line + 1,
        selectionStartColumn: anchor.character + 1,
        positionLineNumber: active.line + 1,
        positionColumn: active.character + 1,
    };
}
var DocumentLink;
(function (DocumentLink) {
    function from(link) {
        return {
            range: Range.from(link.range),
            url: link.target,
            tooltip: link.tooltip,
        };
    }
    DocumentLink.from = from;
    function to(link) {
        let target;
        if (link.url) {
            try {
                target = typeof link.url === 'string' ? ide_core_common_1.Uri.parse(link.url) : ide_core_common_1.Uri.revive(link.url);
            }
            catch (err) {
                // ignore
            }
        }
        return new types.DocumentLink(Range.to(link.range), target);
    }
    DocumentLink.to = to;
})(DocumentLink || (exports.DocumentLink = DocumentLink = {}));
/**
 * @deprecated
 */
function fromDocumentLink(link) {
    return {
        range: fromRange(link.range),
        url: link.target,
        tooltip: link.tooltip,
    };
}
var Selection;
(function (Selection) {
    function to(selection) {
        const { selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn } = selection;
        const start = new types.Position(selectionStartLineNumber - 1, selectionStartColumn - 1);
        const end = new types.Position(positionLineNumber - 1, positionColumn - 1);
        return new types.Selection(start, end);
    }
    Selection.to = to;
    function from(selection) {
        const { anchor, active } = selection;
        return {
            selectionStartLineNumber: anchor.line + 1,
            selectionStartColumn: anchor.character + 1,
            positionLineNumber: active.line + 1,
            positionColumn: active.character + 1,
        };
    }
    Selection.from = from;
})(Selection || (exports.Selection = Selection = {}));
var TextEditorLineNumbersStyle;
(function (TextEditorLineNumbersStyle) {
    function from(style) {
        switch (style) {
            case types.TextEditorLineNumbersStyle.Off:
                return 0 /* RenderLineNumbersType.Off */;
            case types.TextEditorLineNumbersStyle.Relative:
                return 2 /* RenderLineNumbersType.Relative */;
            case types.TextEditorLineNumbersStyle.Interval:
                return 3 /* RenderLineNumbersType.Interval */;
            case types.TextEditorLineNumbersStyle.On:
            default:
                return 1 /* RenderLineNumbersType.On */;
        }
    }
    TextEditorLineNumbersStyle.from = from;
    function to(style) {
        switch (style) {
            case 0 /* RenderLineNumbersType.Off */:
                return types.TextEditorLineNumbersStyle.Off;
            case 2 /* RenderLineNumbersType.Relative */:
                return types.TextEditorLineNumbersStyle.Relative;
            case 3 /* RenderLineNumbersType.Interval */:
                return types.TextEditorLineNumbersStyle.Interval;
            case 1 /* RenderLineNumbersType.On */:
            default:
                return types.TextEditorLineNumbersStyle.On;
        }
    }
    TextEditorLineNumbersStyle.to = to;
})(TextEditorLineNumbersStyle || (exports.TextEditorLineNumbersStyle = TextEditorLineNumbersStyle = {}));
var DecorationRenderOptions;
(function (DecorationRenderOptions) {
    function from(options) {
        return {
            isWholeLine: options.isWholeLine,
            rangeBehavior: options.rangeBehavior ? DecorationRangeBehavior.from(options.rangeBehavior) : undefined,
            overviewRulerLane: options.overviewRulerLane,
            light: options.light ? ThemableDecorationRenderOptions.from(options.light) : undefined,
            dark: options.dark ? ThemableDecorationRenderOptions.from(options.dark) : undefined,
            backgroundColor: options.backgroundColor,
            outline: options.outline,
            outlineColor: options.outlineColor,
            outlineStyle: options.outlineStyle,
            outlineWidth: options.outlineWidth,
            border: options.border,
            borderColor: options.borderColor,
            borderRadius: options.borderRadius,
            borderSpacing: options.borderSpacing,
            borderStyle: options.borderStyle,
            borderWidth: options.borderWidth,
            fontStyle: options.fontStyle,
            fontWeight: options.fontWeight,
            textDecoration: options.textDecoration,
            textUnderlinePosition: options.textUnderlinePosition,
            cursor: options.cursor,
            color: options.color,
            opacity: options.opacity,
            letterSpacing: options.letterSpacing,
            gutterIconPath: options.gutterIconPath ? pathOrURIToURI(options.gutterIconPath) : undefined,
            gutterIconSize: options.gutterIconSize,
            overviewRulerColor: options.overviewRulerColor,
            before: options.before ? ThemableDecorationAttachmentRenderOptions.from(options.before) : undefined,
            after: options.after ? ThemableDecorationAttachmentRenderOptions.from(options.after) : undefined,
        };
    }
    DecorationRenderOptions.from = from;
})(DecorationRenderOptions || (exports.DecorationRenderOptions = DecorationRenderOptions = {}));
var ThemableDecorationRenderOptions;
(function (ThemableDecorationRenderOptions) {
    function from(options) {
        if (typeof options === 'undefined') {
            return options;
        }
        return {
            backgroundColor: options.backgroundColor,
            outline: options.outline,
            outlineColor: options.outlineColor,
            outlineStyle: options.outlineStyle,
            outlineWidth: options.outlineWidth,
            border: options.border,
            borderColor: options.borderColor,
            borderRadius: options.borderRadius,
            borderSpacing: options.borderSpacing,
            borderStyle: options.borderStyle,
            borderWidth: options.borderWidth,
            fontStyle: options.fontStyle,
            fontWeight: options.fontWeight,
            textDecoration: options.textDecoration,
            textUnderlinePosition: options.textUnderlinePosition,
            cursor: options.cursor,
            color: options.color,
            opacity: options.opacity,
            letterSpacing: options.letterSpacing,
            gutterIconPath: options.gutterIconPath ? pathOrURIToURI(options.gutterIconPath) : undefined,
            gutterIconSize: options.gutterIconSize,
            overviewRulerColor: options.overviewRulerColor,
            before: options.before ? ThemableDecorationAttachmentRenderOptions.from(options.before) : undefined,
            after: options.after ? ThemableDecorationAttachmentRenderOptions.from(options.after) : undefined,
        };
    }
    ThemableDecorationRenderOptions.from = from;
})(ThemableDecorationRenderOptions || (exports.ThemableDecorationRenderOptions = ThemableDecorationRenderOptions = {}));
var ThemableDecorationAttachmentRenderOptions;
(function (ThemableDecorationAttachmentRenderOptions) {
    function from(options) {
        if (typeof options === 'undefined') {
            return options;
        }
        return {
            contentText: options.contentText,
            contentIconPath: options.contentIconPath ? pathOrURIToURI(options.contentIconPath) : undefined,
            border: options.border,
            borderColor: options.borderColor,
            fontStyle: options.fontStyle,
            fontWeight: options.fontWeight,
            textDecoration: options.textDecoration,
            color: options.color,
            backgroundColor: options.backgroundColor,
            margin: options.margin,
            width: options.width,
            height: options.height,
        };
    }
    ThemableDecorationAttachmentRenderOptions.from = from;
})(ThemableDecorationAttachmentRenderOptions || (exports.ThemableDecorationAttachmentRenderOptions = ThemableDecorationAttachmentRenderOptions = {}));
var WorkspaceEdit;
(function (WorkspaceEdit) {
    function from(value, documents) {
        const result = {
            edits: [],
        };
        for (const entry of value.allEntries()) {
            if (entry._type === types.WorkspaceEditType.File) {
                // file operation
                result.edits.push({
                    _type: types.WorkspaceEditType.File,
                    oldResource: entry.from,
                    newResource: entry.to,
                    options: entry.options,
                    metadata: entry.metadata,
                });
            }
            else if (entry._type === types.WorkspaceEditType.Text) {
                // text edits
                const doc = documents === null || documents === void 0 ? void 0 : documents.getDocument(entry.uri);
                result.edits.push({
                    _type: types.WorkspaceEditType.Text,
                    resource: entry.uri,
                    textEdit: TextEdit.from(entry.edit),
                    versionId: doc === null || doc === void 0 ? void 0 : doc.version,
                    metadata: entry.metadata,
                });
            }
            else if (entry._type === types.WorkspaceEditType.Snippet) {
                // snippet edits
                const doc = documents === null || documents === void 0 ? void 0 : documents.getDocument(entry.uri);
                result.edits.push({
                    _type: types.WorkspaceEditType.Text,
                    resource: entry.uri,
                    textEdit: SnippetTextEdit.from(entry.edit),
                    versionId: doc === null || doc === void 0 ? void 0 : doc.version,
                    metadata: entry.metadata,
                });
            }
        }
        return result;
    }
    WorkspaceEdit.from = from;
    function to(value) {
        const result = new types.WorkspaceEdit();
        for (const edit of value.edits) {
            if (edit.textEdit) {
                result.replace(ide_core_common_1.URI.revive(edit.resource), Range.to(edit.textEdit.range), edit.textEdit.text);
            }
            else {
                result.renameFile(ide_core_common_1.URI.revive(edit.oldResource), ide_core_common_1.URI.revive(edit.newResource), edit.options);
            }
        }
        return result;
    }
    WorkspaceEdit.to = to;
})(WorkspaceEdit || (exports.WorkspaceEdit = WorkspaceEdit = {}));
var DecorationRangeBehavior;
(function (DecorationRangeBehavior) {
    function from(value) {
        if (typeof value === 'undefined') {
            return value;
        }
        switch (value) {
            case types.DecorationRangeBehavior.OpenOpen:
                return 0 /* TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges */;
            case types.DecorationRangeBehavior.ClosedClosed:
                return 1 /* TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges */;
            case types.DecorationRangeBehavior.OpenClosed:
                return 2 /* TrackedRangeStickiness.GrowsOnlyWhenTypingBefore */;
            case types.DecorationRangeBehavior.ClosedOpen:
                return 3 /* TrackedRangeStickiness.GrowsOnlyWhenTypingAfter */;
        }
    }
    DecorationRangeBehavior.from = from;
})(DecorationRangeBehavior || (exports.DecorationRangeBehavior = DecorationRangeBehavior = {}));
var GlobPattern;
(function (GlobPattern) {
    function from(pattern) {
        if (pattern instanceof types.RelativePattern) {
            return pattern;
        }
        if (typeof pattern === 'string') {
            return pattern;
        }
        if (isRelativePattern(pattern)) {
            return new types.RelativePattern(pattern.base, pattern.pattern);
        }
        return pattern; // preserve `undefined` and `null`
    }
    GlobPattern.from = from;
    function isRelativePattern(obj) {
        const rp = obj;
        return rp && typeof rp.base === 'string' && typeof rp.pattern === 'string';
    }
})(GlobPattern || (exports.GlobPattern = GlobPattern = {}));
function pathOrURIToURI(value) {
    if (typeof value === 'undefined') {
        return value;
    }
    if (typeof value === 'string') {
        return types.Uri.file(value);
    }
    else {
        return value;
    }
}
var SymbolKind;
(function (SymbolKind) {
    const fromMapping = Object.create(null);
    fromMapping[types.SymbolKind.File] = types.SymbolKind.File;
    fromMapping[types.SymbolKind.Module] = types.SymbolKind.Module;
    fromMapping[types.SymbolKind.Namespace] = types.SymbolKind.Namespace;
    fromMapping[types.SymbolKind.Package] = types.SymbolKind.Package;
    fromMapping[types.SymbolKind.Class] = types.SymbolKind.Class;
    fromMapping[types.SymbolKind.Method] = types.SymbolKind.Method;
    fromMapping[types.SymbolKind.Property] = types.SymbolKind.Property;
    fromMapping[types.SymbolKind.Field] = types.SymbolKind.Field;
    fromMapping[types.SymbolKind.Constructor] = types.SymbolKind.Constructor;
    fromMapping[types.SymbolKind.Enum] = types.SymbolKind.Enum;
    fromMapping[types.SymbolKind.Interface] = types.SymbolKind.Interface;
    fromMapping[types.SymbolKind.Function] = types.SymbolKind.Function;
    fromMapping[types.SymbolKind.Variable] = types.SymbolKind.Variable;
    fromMapping[types.SymbolKind.Constant] = types.SymbolKind.Constant;
    fromMapping[types.SymbolKind.String] = types.SymbolKind.String;
    fromMapping[types.SymbolKind.Number] = types.SymbolKind.Number;
    fromMapping[types.SymbolKind.Boolean] = types.SymbolKind.Boolean;
    fromMapping[types.SymbolKind.Array] = types.SymbolKind.Array;
    fromMapping[types.SymbolKind.Object] = types.SymbolKind.Object;
    fromMapping[types.SymbolKind.Key] = types.SymbolKind.Key;
    fromMapping[types.SymbolKind.Null] = types.SymbolKind.Null;
    fromMapping[types.SymbolKind.EnumMember] = types.SymbolKind.EnumMember;
    fromMapping[types.SymbolKind.Struct] = types.SymbolKind.Struct;
    fromMapping[types.SymbolKind.Event] = types.SymbolKind.Event;
    fromMapping[types.SymbolKind.Operator] = types.SymbolKind.Operator;
    fromMapping[types.SymbolKind.TypeParameter] = types.SymbolKind.TypeParameter;
    function from(kind) {
        return fromMapping[kind] || types.SymbolKind.Property;
    }
    SymbolKind.from = from;
    function to(kind) {
        for (const k in fromMapping) {
            if (fromMapping[k] === kind) {
                return Number(k);
            }
        }
        return types.SymbolKind.Property;
    }
    SymbolKind.to = to;
    /**
     * @deprecated
     */
    function fromSymbolKind(kind) {
        return fromMapping[kind] || types.SymbolKind.Property;
    }
    SymbolKind.fromSymbolKind = fromSymbolKind;
    /**
     * @deprecated
     */
    function toSymbolKind(kind) {
        for (const k in fromMapping) {
            if (fromMapping[k] === kind) {
                return Number(k);
            }
        }
        return types.SymbolKind.Property;
    }
    SymbolKind.toSymbolKind = toSymbolKind;
})(SymbolKind || (exports.SymbolKind = SymbolKind = {}));
function fromDocumentSymbol(info) {
    var _a, _b;
    const result = {
        name: info.name,
        detail: info.detail,
        range: fromRange(info.range),
        selectionRange: fromRange(info.selectionRange),
        kind: SymbolKind.fromSymbolKind(info.kind),
        tags: (_b = (_a = info.tags) === null || _a === void 0 ? void 0 : _a.map(SymbolTag.from)) !== null && _b !== void 0 ? _b : [],
    };
    if (info.children) {
        result.children = info.children.map(fromDocumentSymbol);
    }
    return result;
}
function fromSymbolInformation(symbolInformation) {
    if (!symbolInformation) {
        return undefined;
    }
    if (symbolInformation.location && symbolInformation.location.range) {
        const p1 = vscode_languageserver_types_1.Position.create(symbolInformation.location.range.start.line, symbolInformation.location.range.start.character);
        const p2 = vscode_languageserver_types_1.Position.create(symbolInformation.location.range.end.line, symbolInformation.location.range.end.character);
        return vscode_languageserver_types_1.SymbolInformation.create(symbolInformation.name, symbolInformation.kind++, vscode_languageserver_types_1.Range.create(p1, p2), symbolInformation.location.uri.toString(), symbolInformation.containerName);
    }
    return {
        name: symbolInformation.name,
        containerName: symbolInformation.containerName,
        kind: symbolInformation.kind++,
        location: {
            uri: symbolInformation.location.uri.toString(),
        },
    };
}
function toSymbolInformation(symbolInformation) {
    if (!symbolInformation) {
        return undefined;
    }
    return {
        name: symbolInformation.name,
        containerName: symbolInformation.containerName,
        kind: symbolInformation.kind,
        location: {
            uri: ide_core_common_1.URI.revive(symbolInformation.location.uri),
            range: symbolInformation.location.range,
        },
    };
}
var SymbolTag;
(function (SymbolTag) {
    function from(kind) {
        switch (kind) {
            case types.SymbolTag.Deprecated:
                return model.SymbolTag.Deprecated;
        }
    }
    SymbolTag.from = from;
    function to(kind) {
        switch (kind) {
            case model.SymbolTag.Deprecated:
                return types.SymbolTag.Deprecated;
        }
    }
    SymbolTag.to = to;
})(SymbolTag || (exports.SymbolTag = SymbolTag = {}));
var CompletionItemKind;
(function (CompletionItemKind) {
    const _from = new Map([
        [types.CompletionItemKind.Method, model.CompletionItemKind.Method],
        [types.CompletionItemKind.Function, model.CompletionItemKind.Function],
        [types.CompletionItemKind.Constructor, model.CompletionItemKind.Constructor],
        [types.CompletionItemKind.Field, model.CompletionItemKind.Field],
        [types.CompletionItemKind.Variable, model.CompletionItemKind.Variable],
        [types.CompletionItemKind.Class, model.CompletionItemKind.Class],
        [types.CompletionItemKind.Interface, model.CompletionItemKind.Interface],
        [types.CompletionItemKind.Struct, model.CompletionItemKind.Struct],
        [types.CompletionItemKind.Module, model.CompletionItemKind.Module],
        [types.CompletionItemKind.Property, model.CompletionItemKind.Property],
        [types.CompletionItemKind.Unit, model.CompletionItemKind.Unit],
        [types.CompletionItemKind.Value, model.CompletionItemKind.Value],
        [types.CompletionItemKind.Constant, model.CompletionItemKind.Constant],
        [types.CompletionItemKind.Enum, model.CompletionItemKind.Enum],
        [types.CompletionItemKind.EnumMember, model.CompletionItemKind.EnumMember],
        [types.CompletionItemKind.Keyword, model.CompletionItemKind.Keyword],
        [types.CompletionItemKind.Snippet, model.CompletionItemKind.Snippet],
        [types.CompletionItemKind.Text, model.CompletionItemKind.Text],
        [types.CompletionItemKind.Color, model.CompletionItemKind.Color],
        [types.CompletionItemKind.File, model.CompletionItemKind.File],
        [types.CompletionItemKind.Reference, model.CompletionItemKind.Reference],
        [types.CompletionItemKind.Folder, model.CompletionItemKind.Folder],
        [types.CompletionItemKind.Event, model.CompletionItemKind.Event],
        [types.CompletionItemKind.Operator, model.CompletionItemKind.Operator],
        [types.CompletionItemKind.TypeParameter, model.CompletionItemKind.TypeParameter],
        [types.CompletionItemKind.Issue, model.CompletionItemKind.Issue],
        [types.CompletionItemKind.User, model.CompletionItemKind.User],
    ]);
    function from(kind) {
        var _a;
        return (_a = _from.get(kind)) !== null && _a !== void 0 ? _a : model.CompletionItemKind.Property;
    }
    CompletionItemKind.from = from;
    const _to = new Map([
        [model.CompletionItemKind.Method, types.CompletionItemKind.Method],
        [model.CompletionItemKind.Function, types.CompletionItemKind.Function],
        [model.CompletionItemKind.Constructor, types.CompletionItemKind.Constructor],
        [model.CompletionItemKind.Field, types.CompletionItemKind.Field],
        [model.CompletionItemKind.Variable, types.CompletionItemKind.Variable],
        [model.CompletionItemKind.Class, types.CompletionItemKind.Class],
        [model.CompletionItemKind.Interface, types.CompletionItemKind.Interface],
        [model.CompletionItemKind.Struct, types.CompletionItemKind.Struct],
        [model.CompletionItemKind.Module, types.CompletionItemKind.Module],
        [model.CompletionItemKind.Property, types.CompletionItemKind.Property],
        [model.CompletionItemKind.Unit, types.CompletionItemKind.Unit],
        [model.CompletionItemKind.Value, types.CompletionItemKind.Value],
        [model.CompletionItemKind.Constant, types.CompletionItemKind.Constant],
        [model.CompletionItemKind.Enum, types.CompletionItemKind.Enum],
        [model.CompletionItemKind.EnumMember, types.CompletionItemKind.EnumMember],
        [model.CompletionItemKind.Keyword, types.CompletionItemKind.Keyword],
        [model.CompletionItemKind.Snippet, types.CompletionItemKind.Snippet],
        [model.CompletionItemKind.Text, types.CompletionItemKind.Text],
        [model.CompletionItemKind.Color, types.CompletionItemKind.Color],
        [model.CompletionItemKind.File, types.CompletionItemKind.File],
        [model.CompletionItemKind.Reference, types.CompletionItemKind.Reference],
        [model.CompletionItemKind.Folder, types.CompletionItemKind.Folder],
        [model.CompletionItemKind.Event, types.CompletionItemKind.Event],
        [model.CompletionItemKind.Operator, types.CompletionItemKind.Operator],
        [model.CompletionItemKind.TypeParameter, types.CompletionItemKind.TypeParameter],
        // [model.CompletionItemKind.User, types.CompletionItemKind.User],
        // [model.CompletionItemKind.Issue, types.CompletionItemKind.Issue],
    ]);
    function to(kind) {
        var _a;
        return (_a = _to.get(kind)) !== null && _a !== void 0 ? _a : types.CompletionItemKind.Property;
    }
    CompletionItemKind.to = to;
})(CompletionItemKind || (exports.CompletionItemKind = CompletionItemKind = {}));
var CompletionItem;
(function (CompletionItem) {
    function to(suggestion, converter) {
        var _a;
        const result = new types.CompletionItem(suggestion.label);
        if (typeof suggestion.label !== 'string') {
            result.label2 = suggestion.label;
        }
        result.insertText = suggestion.insertText;
        result.kind = CompletionItemKind.to(suggestion.kind);
        result.tags = (_a = suggestion.tags) === null || _a === void 0 ? void 0 : _a.map(CompletionItemTag.to);
        result.detail = suggestion.detail;
        result.documentation = (0, models_1.isMarkdownString)(suggestion.documentation)
            ? MarkdownString.to(suggestion.documentation)
            : suggestion.documentation;
        result.sortText = suggestion.sortText;
        result.filterText = suggestion.filterText;
        result.preselect = suggestion.preselect;
        result.commitCharacters = suggestion.commitCharacters;
        // range
        if (model.isIRange(suggestion.range)) {
            result.range = Range.to(suggestion.range);
        }
        else if (typeof suggestion.range === 'object') {
            result.range = {
                inserting: Range.to(suggestion.range.insert),
                replacing: Range.to(suggestion.range.replace),
            };
        }
        result.keepWhitespace =
            typeof suggestion.insertTextRules === 'undefined'
                ? false
                : Boolean(suggestion.insertTextRules & model.CompletionItemInsertTextRule.KeepWhitespace);
        // 'insertText'-logic
        if (typeof suggestion.insertTextRules !== 'undefined' &&
            suggestion.insertTextRules & model.CompletionItemInsertTextRule.InsertAsSnippet) {
            result.insertText = new types.SnippetString(suggestion.insertText);
        }
        else {
            result.insertText = suggestion.insertText;
            result.textEdit =
                result.range instanceof types.Range ? new types.TextEdit(result.range, result.insertText) : undefined;
        }
        if (suggestion.additionalTextEdits && suggestion.additionalTextEdits.length > 0) {
            result.additionalTextEdits = suggestion.additionalTextEdits.map((e) => TextEdit.to(e));
        }
        result.command = converter && suggestion.command ? converter.fromInternal(suggestion.command) : undefined;
        return result;
    }
    CompletionItem.to = to;
})(CompletionItem || (exports.CompletionItem = CompletionItem = {}));
var CompletionItemTag;
(function (CompletionItemTag) {
    function from(kind) {
        switch (kind) {
            case types.CompletionItemTag.Deprecated:
                return model.CompletionItemTag.Deprecated;
        }
    }
    CompletionItemTag.from = from;
    function to(kind) {
        switch (kind) {
            case model.CompletionItemTag.Deprecated:
                return types.CompletionItemTag.Deprecated;
        }
    }
    CompletionItemTag.to = to;
})(CompletionItemTag || (exports.CompletionItemTag = CompletionItemTag = {}));
function viewColumnToResourceOpenOptions(viewColumn) {
    const result = {};
    if (viewColumn) {
        if (viewColumn === enums_1.ViewColumn.Beside) {
            result.relativeGroupIndex = 1;
        }
        else if (viewColumn === enums_1.ViewColumn.Active) {
            result.relativeGroupIndex = 0;
        }
        else {
            result.groupIndex = viewColumn - 1;
        }
    }
    return result;
}
var WorkspaceSymbol;
(function (WorkspaceSymbol) {
    function from(info) {
        return {
            name: info.name,
            kind: SymbolKind.from(info.kind),
            tags: info.tags && info.tags.map(SymbolTag.from),
            containerName: info.containerName,
            location: location.from(info.location),
        };
    }
    WorkspaceSymbol.from = from;
    function to(info) {
        const result = new types.SymbolInformation(info.name, SymbolKind.to(info.kind), info.containerName, location.to(info.location));
        result.tags = info.tags && info.tags.map(SymbolTag.to);
        return result;
    }
    WorkspaceSymbol.to = to;
})(WorkspaceSymbol || (exports.WorkspaceSymbol = WorkspaceSymbol = {}));
var Position;
(function (Position) {
    function to(position) {
        return new types.Position(position.lineNumber - 1, position.column - 1);
    }
    Position.to = to;
    function from(position) {
        return { lineNumber: position.line + 1, column: position.character + 1 };
    }
    Position.from = from;
})(Position || (exports.Position = Position = {}));
var ProgressLocation;
(function (ProgressLocation) {
    function from(loc) {
        if (typeof loc === 'object') {
            return loc.viewId;
        }
        switch (loc) {
            case types.ProgressLocation.SourceControl:
                return ide_core_common_1.ProgressLocation.Scm;
            case types.ProgressLocation.Window:
                return ide_core_common_1.ProgressLocation.Window;
            case types.ProgressLocation.Notification:
                return ide_core_common_1.ProgressLocation.Notification;
        }
        throw new Error("Unknown 'ProgressLocation'");
    }
    ProgressLocation.from = from;
})(ProgressLocation || (exports.ProgressLocation = ProgressLocation = {}));
function fromFileStat(stat, uri) {
    const isSymbolicLink = stat.type.valueOf() === ide_file_service_1.FileType.SymbolicLink.valueOf();
    const isDirectory = stat.type.valueOf() === ide_file_service_1.FileType.Directory.valueOf();
    const result = {
        uri: uri.toString(),
        lastModification: stat.mtime,
        createTime: stat.ctime,
        isSymbolicLink,
        isDirectory,
        size: stat.size,
    };
    return result;
}
function toFileStat(stat) {
    return {
        ctime: (stat === null || stat === void 0 ? void 0 : stat.createTime) || 0,
        mtime: stat === null || stat === void 0 ? void 0 : stat.lastModification,
        size: (stat === null || stat === void 0 ? void 0 : stat.size) || 0,
        type: (stat === null || stat === void 0 ? void 0 : stat.type) || ide_file_service_1.FileType.Unknown,
    };
}
function isLikelyVscodeRange(thing) {
    if (!thing) {
        return false;
    }
    return thing.start !== undefined && thing.end !== undefined;
}
var CallHierarchyItem;
(function (CallHierarchyItem) {
    function to(item) {
        const result = new types.CallHierarchyItem(SymbolKind.toSymbolKind(item.kind), item.name, item.detail || '', ide_core_common_1.URI.revive(item.uri), toRange(item.range), toRange(item.selectionRange));
        result._sessionId = item._sessionId;
        result._itemId = item._itemId;
        return result;
    }
    CallHierarchyItem.to = to;
})(CallHierarchyItem || (exports.CallHierarchyItem = CallHierarchyItem = {}));
var TypeHierarchyItem;
(function (TypeHierarchyItem) {
    function to(item) {
        const result = new types.TypeHierarchyItem(SymbolKind.to(item.kind), item.name, item.detail || '', ide_core_common_1.URI.revive(item.uri), Range.to(item.range), Range.to(item.selectionRange));
        result._sessionId = item._sessionId;
        result._itemId = item._itemId;
        return result;
    }
    TypeHierarchyItem.to = to;
    function from(item, sessionId, itemId) {
        var _a, _b;
        sessionId = sessionId !== null && sessionId !== void 0 ? sessionId : item._sessionId;
        itemId = itemId !== null && itemId !== void 0 ? itemId : item._itemId;
        if (sessionId === undefined || itemId === undefined) {
            throw new Error('invalid item');
        }
        return {
            _sessionId: sessionId,
            _itemId: itemId,
            kind: SymbolKind.from(item.kind),
            name: item.name,
            detail: (_a = item.detail) !== null && _a !== void 0 ? _a : '',
            uri: item.uri,
            range: Range.from(item.range),
            selectionRange: Range.from(item.selectionRange),
            tags: (_b = item.tags) === null || _b === void 0 ? void 0 : _b.map(SymbolTag.from),
        };
    }
    TypeHierarchyItem.from = from;
})(TypeHierarchyItem || (exports.TypeHierarchyItem = TypeHierarchyItem = {}));
var CallHierarchyIncomingCall;
(function (CallHierarchyIncomingCall) {
    function to(item) {
        return new types.CallHierarchyIncomingCall(CallHierarchyItem.to(item.from), item.fromRanges.map((r) => toRange(r)));
    }
    CallHierarchyIncomingCall.to = to;
})(CallHierarchyIncomingCall || (exports.CallHierarchyIncomingCall = CallHierarchyIncomingCall = {}));
var CallHierarchyOutgoingCall;
(function (CallHierarchyOutgoingCall) {
    function to(item) {
        return new types.CallHierarchyOutgoingCall(CallHierarchyItem.to(item.to), item.fromRanges.map((r) => toRange(r)));
    }
    CallHierarchyOutgoingCall.to = to;
})(CallHierarchyOutgoingCall || (exports.CallHierarchyOutgoingCall = CallHierarchyOutgoingCall = {}));
var ParameterInformation;
(function (ParameterInformation) {
    function from(info) {
        return {
            label: info.label,
            documentation: info.documentation ? MarkdownString.fromStrict(info.documentation) : undefined,
        };
    }
    ParameterInformation.from = from;
    function to(info) {
        return {
            label: info.label,
            documentation: (0, models_1.isMarkdownString)(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation,
        };
    }
    ParameterInformation.to = to;
})(ParameterInformation || (exports.ParameterInformation = ParameterInformation = {}));
var SignatureInformation;
(function (SignatureInformation) {
    function from(info) {
        return {
            label: info.label,
            documentation: info.documentation ? MarkdownString.fromStrict(info.documentation) : undefined,
            parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.from) : [],
            activeParameter: info.activeParameter,
        };
    }
    SignatureInformation.from = from;
    function to(info) {
        return {
            label: info.label,
            documentation: (0, models_1.isMarkdownString)(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation,
            parameters: Array.isArray(info.parameters) ? info.parameters.map(ParameterInformation.to) : [],
            activeParameter: info.activeParameter,
        };
    }
    SignatureInformation.to = to;
})(SignatureInformation || (exports.SignatureInformation = SignatureInformation = {}));
var SignatureHelp;
(function (SignatureHelp) {
    function from(help) {
        return {
            activeSignature: help.activeSignature,
            activeParameter: help.activeParameter,
            signatures: Array.isArray(help.signatures) ? help.signatures.map(SignatureInformation.from) : [],
        };
    }
    SignatureHelp.from = from;
    function to(help) {
        return {
            activeSignature: help.activeSignature,
            activeParameter: help.activeParameter,
            signatures: Array.isArray(help.signatures) ? help.signatures.map(SignatureInformation.to) : [],
        };
    }
    SignatureHelp.to = to;
})(SignatureHelp || (exports.SignatureHelp = SignatureHelp = {}));
exports.ACTIVE_GROUP = -1;
exports.SIDE_GROUP = -2;
var ViewColumn;
(function (ViewColumn) {
    function from(column) {
        if (typeof column === 'number' && column >= types.ViewColumn.One) {
            return column - 1; // adjust zero index (ViewColumn.ONE => 0)
        }
        if (column === types.ViewColumn.Beside) {
            return exports.SIDE_GROUP;
        }
        return exports.ACTIVE_GROUP; // default is always the active group
    }
    ViewColumn.from = from;
    function to(position) {
        if (typeof position === 'number' && position >= 0) {
            return position + 1; // adjust to index (ViewColumn.ONE => 1)
        }
        throw new Error("invalid 'EditorGroupColumn'");
    }
    ViewColumn.to = to;
})(ViewColumn || (exports.ViewColumn = ViewColumn = {}));
var DefinitionLink;
(function (DefinitionLink) {
    function from(value) {
        const definitionLink = value;
        const location = value;
        return {
            originSelectionRange: definitionLink.originSelectionRange
                ? Range.from(definitionLink.originSelectionRange)
                : undefined,
            uri: definitionLink.targetUri ? definitionLink.targetUri : location.uri,
            range: Range.from(definitionLink.targetRange ? definitionLink.targetRange : location.range),
            targetSelectionRange: definitionLink.targetSelectionRange
                ? Range.from(definitionLink.targetSelectionRange)
                : undefined,
        };
    }
    DefinitionLink.from = from;
    function to(value) {
        return {
            targetUri: value.uri,
            targetRange: Range.to(value.range),
            targetSelectionRange: value.targetSelectionRange ? Range.to(value.targetSelectionRange) : undefined,
            originSelectionRange: value.originSelectionRange ? Range.to(value.originSelectionRange) : undefined,
        };
    }
    DefinitionLink.to = to;
})(DefinitionLink || (exports.DefinitionLink = DefinitionLink = {}));
var EvaluatableExpression;
(function (EvaluatableExpression) {
    function from(expression) {
        return {
            range: fromRange(expression.range),
            expression: expression.expression,
        };
    }
    EvaluatableExpression.from = from;
    function to(info) {
        return new types.EvaluatableExpression(toRange(info.range), info.expression);
    }
    EvaluatableExpression.to = to;
})(EvaluatableExpression || (exports.EvaluatableExpression = EvaluatableExpression = {}));
var InlineValue;
(function (InlineValue) {
    function from(inlineValue) {
        if (inlineValue instanceof types.InlineValueText) {
            return {
                type: 'text',
                range: Range.from(inlineValue.range),
                text: inlineValue.text,
            };
        }
        else if (inlineValue instanceof types.InlineValueVariableLookup) {
            return {
                type: 'variable',
                range: Range.from(inlineValue.range),
                variableName: inlineValue.variableName,
                caseSensitiveLookup: inlineValue.caseSensitiveLookup,
            };
        }
        else if (inlineValue instanceof types.InlineValueEvaluatableExpression) {
            return {
                type: 'expression',
                range: Range.from(inlineValue.range),
                expression: inlineValue.expression,
            };
        }
        else {
            throw new Error("Unknown 'InlineValue' type");
        }
    }
    InlineValue.from = from;
    function to(inlineValue) {
        switch (inlineValue.type) {
            case 'text':
                return {
                    range: Range.to(inlineValue.range),
                    text: inlineValue.text,
                };
            case 'variable':
                return {
                    range: Range.to(inlineValue.range),
                    variableName: inlineValue.variableName,
                    caseSensitiveLookup: inlineValue.caseSensitiveLookup,
                };
            case 'expression':
                return {
                    range: Range.to(inlineValue.range),
                    expression: inlineValue.expression,
                };
        }
    }
    InlineValue.to = to;
})(InlineValue || (exports.InlineValue = InlineValue = {}));
var InlineValueContext;
(function (InlineValueContext) {
    function from(inlineValueContext) {
        return {
            frameId: inlineValueContext.frameId,
            stoppedLocation: Range.from(inlineValueContext.stoppedLocation),
        };
    }
    InlineValueContext.from = from;
    function to(inlineValueContext) {
        return new types.InlineValueContext(inlineValueContext.frameId, Range.to(inlineValueContext.stoppedLocation));
    }
    InlineValueContext.to = to;
})(InlineValueContext || (exports.InlineValueContext = InlineValueContext = {}));
var InlayHint;
(function (InlayHint) {
    function from(hint) {
        return {
            label: hint.label,
            position: Position.from(hint.position),
            kind: hint.kind && InlayHintKind.from(hint.kind),
            paddingLeft: hint.paddingLeft,
            paddingRight: hint.paddingRight,
        };
    }
    InlayHint.from = from;
    function to(converter, hint) {
        const res = new types.InlayHint(Position.to(hint.position), typeof hint.label === 'string' ? hint.label : hint.label.map(InlayHintLabelPart.to.bind(undefined, converter)), hint.kind && InlayHintKind.to(hint.kind));
        res.paddingLeft = hint.paddingLeft;
        res.paddingRight = hint.paddingRight;
        return res;
    }
    InlayHint.to = to;
})(InlayHint || (exports.InlayHint = InlayHint = {}));
var InlayHintLabelPart;
(function (InlayHintLabelPart) {
    function to(converter, part) {
        const result = new types.InlayHintLabelPart(part.label);
        result.tooltip = (0, models_1.isMarkdownString)(part.tooltip) ? MarkdownString.to(part.tooltip) : part.tooltip;
        if (models_1.Command.is(part.command)) {
            result.command = converter.fromInternal(part.command);
        }
        if (part.location) {
            result.location = location.to(part.location);
        }
        return result;
    }
    InlayHintLabelPart.to = to;
})(InlayHintLabelPart || (exports.InlayHintLabelPart = InlayHintLabelPart = {}));
var InlayHintKind;
(function (InlayHintKind) {
    function from(kind) {
        return kind;
    }
    InlayHintKind.from = from;
    function to(kind) {
        return kind;
    }
    InlayHintKind.to = to;
})(InlayHintKind || (exports.InlayHintKind = InlayHintKind = {}));
var CodeActionTriggerKind;
(function (CodeActionTriggerKind) {
    function to(value) {
        switch (value) {
            case 1 /* CodeActionTriggerType.Invoke */:
                return types.CodeActionTriggerKind.Invoke;
            case 2 /* CodeActionTriggerType.Auto */:
                return types.CodeActionTriggerKind.Automatic;
        }
    }
    CodeActionTriggerKind.to = to;
})(CodeActionTriggerKind || (exports.CodeActionTriggerKind = CodeActionTriggerKind = {}));
// #region Test Adapter
var TestMessage;
(function (TestMessage) {
    function from(message) {
        return {
            message: MarkdownString.fromStrict(message.message) || '',
            type: 0 /* TestMessageType.Error */,
            expected: message.expectedOutput,
            actual: message.actualOutput,
            contextValue: message.contextValue,
            location: message.location ? location.from(message.location) : undefined,
            stackTrace: message.stackTrace && message.stackTrace.map((frame) => TestMessageStackFrame.from(frame)),
        };
    }
    TestMessage.from = from;
    function to(item) {
        const message = new types.TestMessage(typeof item.message === 'string' ? item.message : MarkdownString.to(item.message));
        message.actualOutput = item.actual;
        message.expectedOutput = item.expected;
        message.contextValue = item.contextValue;
        message.location = item.location ? location.to(item.location) : undefined;
        return message;
    }
    TestMessage.to = to;
})(TestMessage || (exports.TestMessage = TestMessage = {}));
var TestMessageStackFrame;
(function (TestMessageStackFrame) {
    function from(stackTrace) {
        return {
            label: stackTrace.label,
            position: stackTrace.position,
            uri: stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.uri,
        };
    }
    TestMessageStackFrame.from = from;
})(TestMessageStackFrame || (exports.TestMessageStackFrame = TestMessageStackFrame = {}));
var TestTag;
(function (TestTag) {
    TestTag.namespace = (ctrlId, tagId) => ctrlId + "\0" /* Constants.Delimiter */ + tagId;
    TestTag.denamespace = (namespaced) => {
        const index = namespaced.indexOf("\0" /* Constants.Delimiter */);
        return { ctrlId: namespaced.slice(0, index), tagId: namespaced.slice(index + 1) };
    };
})(TestTag || (exports.TestTag = TestTag = {}));
var TestItem;
(function (TestItem) {
    function from(item) {
        const ctrlId = (0, testApi_1.getPrivateApiFor)(item).controllerId;
        return {
            extId: common_1.TestId.fromExtHostTestItem(item, ctrlId).toString(),
            label: item.label,
            uri: item.uri,
            tags: item.tags.map((t) => TestTag.namespace(ctrlId, t.id)),
            range: Range.from(item.range) || null,
            description: item.description || null,
            sortText: item.sortText || null,
            error: item.error ? MarkdownString.fromStrict(item.error) || null : null,
        };
    }
    TestItem.from = from;
    function toPlain(item) {
        return {
            parent: undefined,
            error: undefined,
            id: common_1.TestId.fromString(item.extId).localId,
            label: item.label,
            uri: ide_core_common_1.URI.revive(item.uri),
            tags: (item.tags || []).map((t) => {
                const { tagId } = TestTag.denamespace(t);
                return new types.TestTag(tagId);
            }),
            range: Range.to(item.range || undefined),
            invalidateResults: () => undefined,
            canResolveChildren: false,
            busy: false,
            description: item.description || undefined,
            sortText: item.sortText || undefined,
        };
    }
    TestItem.toPlain = toPlain;
    function to(item) {
        const testId = common_1.TestId.fromString(item.extId);
        const testItem = new testApi_1.TestItemImpl(testId.controllerId, testId.localId, item.label, ide_core_common_1.URI.revive(item.uri));
        testItem.range = Range.to(item.range || undefined);
        testItem.description = item.description || undefined;
        return testItem;
    }
    function toItemFromContext(context) {
        let node;
        for (const test of context.tests) {
            const next = to(test.item);
            (0, testApi_1.getPrivateApiFor)(next).parent = node;
            node = next;
        }
        return node;
    }
    TestItem.toItemFromContext = toItemFromContext;
})(TestItem || (exports.TestItem = TestItem = {}));
(function (TestTag) {
    function from(tag) {
        return { id: tag.id };
    }
    TestTag.from = from;
    function to(tag) {
        return new types.TestTag(tag.id);
    }
    TestTag.to = to;
})(TestTag || (exports.TestTag = TestTag = {}));
var TestResults;
(function (TestResults) {
    const convertTestResultItem = (item, byInternalId) => {
        const snapshot = {
            ...TestItem.toPlain(item.item),
            parent: undefined,
            taskStates: item.tasks.map((t) => ({
                state: t.state,
                duration: t.duration,
                messages: t.messages
                    .filter((m) => m.type === 0 /* TestMessageType.Error */)
                    .map(TestMessage.to),
            })),
            children: item.children
                .map((c) => byInternalId.get(c))
                .filter(ide_core_common_1.isDefined)
                .map((c) => convertTestResultItem(c, byInternalId)),
        };
        for (const child of snapshot.children) {
            child.parent = snapshot;
        }
        return snapshot;
    };
    function to(serialized) {
        const roots = [];
        const byInternalId = new Map();
        for (const item of serialized.items) {
            byInternalId.set(item.item.extId, item);
            if (serialized.request.targets.some((t) => t.controllerId === item.controllerId && t.testIds.includes(item.item.extId))) {
                roots.push(item);
            }
        }
        return {
            completedAt: serialized.completedAt,
            results: roots.map((r) => convertTestResultItem(r, byInternalId)),
        };
    }
    TestResults.to = to;
})(TestResults || (exports.TestResults = TestResults = {}));
var DocumentSelector;
(function (DocumentSelector) {
    function from(value, uriTransformer) {
        return coalesce(asArray(value).map((sel) => _doTransformDocumentSelector(sel, uriTransformer)));
    }
    DocumentSelector.from = from;
    function _doTransformDocumentSelector(selector, uriTransformer) {
        if (typeof selector === 'string') {
            return {
                $serialized: true,
                language: selector,
            };
        }
        if (selector) {
            return {
                $serialized: true,
                language: selector.language,
                scheme: _transformScheme(selector.scheme, uriTransformer),
                pattern: typeof selector.pattern === 'undefined' ? undefined : GlobPattern.from(selector.pattern),
                exclusive: selector.exclusive,
            };
        }
        return undefined;
    }
    function _transformScheme(scheme, uriTransformer) {
        if (uriTransformer && typeof scheme === 'string') {
            return uriTransformer.transformOutgoingScheme(scheme);
        }
        return scheme;
    }
})(DocumentSelector || (exports.DocumentSelector = DocumentSelector = {}));
var DataTransferItem;
(function (DataTransferItem) {
    function toDataTransferItem(item, resolveFileData) {
        const file = item.fileData;
        if (file) {
            return new (class extends types.DataTransferItem {
                asFile() {
                    return {
                        name: file.name,
                        uri: ide_core_common_1.URI.revive(file.uri),
                        data: (0, ide_core_common_1.once)(() => resolveFileData()),
                    };
                }
            })('', item.id);
        }
        else {
            return new types.DataTransferItem(item.asString);
        }
    }
    DataTransferItem.toDataTransferItem = toDataTransferItem;
})(DataTransferItem || (exports.DataTransferItem = DataTransferItem = {}));
var DataTransfer;
(function (DataTransfer) {
    function toDataTransfer(value, resolveFileData) {
        const init = value.items.map(([type, item]) => [type, DataTransferItem.toDataTransferItem(item, () => resolveFileData(item.id))]);
        return new types.DataTransfer(init);
    }
    DataTransfer.toDataTransfer = toDataTransfer;
    async function toDataTransferDTO(value) {
        const newDTO = { items: [] };
        const promises = [];
        value.forEach((value, key) => {
            promises.push((async () => {
                const stringValue = await value.asString();
                const fileValue = value.asFile();
                newDTO.items.push([
                    key,
                    {
                        id: value.id,
                        asString: stringValue,
                        fileData: fileValue ? { name: fileValue.name, uri: fileValue.uri } : undefined,
                    },
                ]);
            })());
        });
        await Promise.all(promises);
        return newDTO;
    }
    DataTransfer.toDataTransferDTO = toDataTransferDTO;
})(DataTransfer || (exports.DataTransfer = DataTransfer = {}));
var ChatReplyFollowup;
(function (ChatReplyFollowup) {
    function from(followup) {
        return {
            kind: 'reply',
            message: followup.message,
            title: followup.title,
            tooltip: followup.tooltip,
        };
    }
    ChatReplyFollowup.from = from;
})(ChatReplyFollowup || (exports.ChatReplyFollowup = ChatReplyFollowup = {}));
var ChatFollowup;
(function (ChatFollowup) {
    function from(followup) {
        var _a, _b, _c;
        if (typeof followup === 'string') {
            return { title: followup, message: followup, kind: 'reply' };
        }
        else if ('commandId' in followup) {
            return {
                kind: 'command',
                title: (_a = followup.title) !== null && _a !== void 0 ? _a : '',
                commandId: (_b = followup.commandId) !== null && _b !== void 0 ? _b : '',
                when: (_c = followup.when) !== null && _c !== void 0 ? _c : '',
                args: followup.args,
            };
        }
        else {
            return ChatReplyFollowup.from(followup);
        }
    }
    ChatFollowup.from = from;
})(ChatFollowup || (exports.ChatFollowup = ChatFollowup = {}));
var ChatMessage;
(function (ChatMessage) {
    function to(message) {
        const res = new types.ChatMessage(ChatMessageRole.to(message.role), message.content);
        res.name = message.name;
        return res;
    }
    ChatMessage.to = to;
    function from(message) {
        return {
            role: ChatMessageRole.from(message.role),
            content: message.content,
            name: message.name,
        };
    }
    ChatMessage.from = from;
})(ChatMessage || (exports.ChatMessage = ChatMessage = {}));
var ChatMessageRole;
(function (ChatMessageRole) {
    function to(role) {
        switch (role) {
            case 0 /* ChatMessageRoleEnum.System */:
                return types.ChatMessageRole.System;
            case 1 /* ChatMessageRoleEnum.User */:
                return types.ChatMessageRole.User;
            case 2 /* ChatMessageRoleEnum.Assistant */:
                return types.ChatMessageRole.Assistant;
            case 3 /* ChatMessageRoleEnum.Function */:
                return types.ChatMessageRole.Function;
        }
    }
    ChatMessageRole.to = to;
    function from(role) {
        switch (role) {
            case types.ChatMessageRole.System:
                return 0 /* ChatMessageRoleEnum.System */;
            case types.ChatMessageRole.Assistant:
                return 2 /* ChatMessageRoleEnum.Assistant */;
            case types.ChatMessageRole.Function:
                return 3 /* ChatMessageRoleEnum.Function */;
            case types.ChatMessageRole.User:
            default:
                return 1 /* ChatMessageRoleEnum.User */;
        }
    }
    ChatMessageRole.from = from;
})(ChatMessageRole || (exports.ChatMessageRole = ChatMessageRole = {}));
var NotebookRange;
(function (NotebookRange) {
    function from(range) {
        return { start: range.start, end: range.end };
    }
    NotebookRange.from = from;
    function to(range) {
        return new types.NotebookRange(range.start, range.end);
    }
    NotebookRange.to = to;
})(NotebookRange || (exports.NotebookRange = NotebookRange = {}));
var NotebookCellExecutionSummary;
(function (NotebookCellExecutionSummary) {
    function to(data) {
        return {
            timing: (0, ide_core_common_1.isNumber)(data.runStartTime) && (0, ide_core_common_1.isNumber)(data.runEndTime)
                ? { startTime: data.runStartTime, endTime: data.runEndTime }
                : undefined,
            executionOrder: data.executionOrder,
            success: data.lastRunSuccess,
        };
    }
    NotebookCellExecutionSummary.to = to;
    function from(data) {
        var _a, _b;
        return {
            lastRunSuccess: data.success,
            runStartTime: (_a = data.timing) === null || _a === void 0 ? void 0 : _a.startTime,
            runEndTime: (_b = data.timing) === null || _b === void 0 ? void 0 : _b.endTime,
            executionOrder: data.executionOrder,
        };
    }
    NotebookCellExecutionSummary.from = from;
})(NotebookCellExecutionSummary || (exports.NotebookCellExecutionSummary = NotebookCellExecutionSummary = {}));
var NotebookCellKind;
(function (NotebookCellKind) {
    function from(data) {
        switch (data) {
            case types.NotebookCellKind.Markup:
                return notebook_1.CellKind.Markup;
            case types.NotebookCellKind.Code:
            default:
                return notebook_1.CellKind.Code;
        }
    }
    NotebookCellKind.from = from;
    function to(data) {
        switch (data) {
            case notebook_1.CellKind.Markup:
                return types.NotebookCellKind.Markup;
            case notebook_1.CellKind.Code:
            default:
                return types.NotebookCellKind.Code;
        }
    }
    NotebookCellKind.to = to;
})(NotebookCellKind || (exports.NotebookCellKind = NotebookCellKind = {}));
//# sourceMappingURL=converter.js.map